Commit 7774a0a4 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

jscript: Pass HRESULTs instead of IDSs to throw_* functions.

parent aab8a1ba
...@@ -172,7 +172,7 @@ static HRESULT ActiveXObject_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flag ...@@ -172,7 +172,7 @@ static HRESULT ActiveXObject_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flag
obj = create_activex_object(ctx, progid); obj = create_activex_object(ctx, progid);
SysFreeString(progid); SysFreeString(progid);
if(!obj) if(!obj)
return throw_generic_error(ctx, ei, IDS_CREATE_OBJ_ERROR, NULL); return throw_generic_error(ctx, ei, JS_E_CANNOT_CREATE_OBJ, NULL);
hres = IUnknown_QueryInterface(obj, &IID_IDispatch, (void**)&disp); hres = IUnknown_QueryInterface(obj, &IID_IDispatch, (void**)&disp);
IUnknown_Release(obj); IUnknown_Release(obj);
......
...@@ -70,7 +70,7 @@ static HRESULT get_length(script_ctx_t *ctx, vdisp_t *vdisp, jsexcept_t *ei, jsd ...@@ -70,7 +70,7 @@ static HRESULT get_length(script_ctx_t *ctx, vdisp_t *vdisp, jsexcept_t *ei, jsd
} }
if(!is_jsdisp(vdisp)) if(!is_jsdisp(vdisp))
return throw_type_error(ctx, ei, IDS_JSCRIPT_EXPECTED, NULL); return throw_type_error(ctx, ei, JS_E_JSCRIPT_EXPECTED, NULL);
hres = jsdisp_propget_name(vdisp->u.jsdisp, lengthW, &var, ei, NULL/*FIXME*/); hres = jsdisp_propget_name(vdisp->u.jsdisp, lengthW, &var, ei, NULL/*FIXME*/);
if(FAILED(hres)) if(FAILED(hres))
...@@ -139,7 +139,7 @@ static HRESULT Array_length(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISP ...@@ -139,7 +139,7 @@ static HRESULT Array_length(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISP
len = floor(V_R8(&num)); len = floor(V_R8(&num));
if(len!=(DWORD)len) if(len!=(DWORD)len)
return throw_range_error(ctx, ei, IDS_INVALID_LENGTH, NULL); return throw_range_error(ctx, ei, JS_E_INVALID_LENGTH, NULL);
for(i=len; i<This->length; i++) { for(i=len; i<This->length; i++) {
hres = jsdisp_delete_idx(&This->dispex, i); hres = jsdisp_delete_idx(&This->dispex, i);
...@@ -975,7 +975,7 @@ static HRESULT Array_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DI ...@@ -975,7 +975,7 @@ static HRESULT Array_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DI
array = array_this(jsthis); array = array_this(jsthis);
if(!array) if(!array)
return throw_type_error(ctx, ei, IDS_ARRAY_EXPECTED, NULL); return throw_type_error(ctx, ei, JS_E_ARRAY_EXPECTED, NULL);
return array_join(ctx, &array->dispex, array->length, default_separatorW, retv, ei, sp); return array_join(ctx, &array->dispex, array->length, default_separatorW, retv, ei, sp);
} }
...@@ -1061,7 +1061,7 @@ static HRESULT Array_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPP ...@@ -1061,7 +1061,7 @@ static HRESULT Array_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPP
switch(flags) { switch(flags) {
case INVOKE_FUNC: case INVOKE_FUNC:
return throw_type_error(ctx, ei, IDS_NOT_FUNC, NULL); return throw_type_error(ctx, ei, JS_E_FUNCTION_EXPECTED, NULL);
case INVOKE_PROPERTYGET: case INVOKE_PROPERTYGET:
return array_join(ctx, jsthis->u.jsdisp, array_from_vdisp(jsthis)->length, default_separatorW, retv, ei, sp); return array_join(ctx, jsthis->u.jsdisp, array_from_vdisp(jsthis)->length, default_separatorW, retv, ei, sp);
default: default:
...@@ -1138,7 +1138,7 @@ static HRESULT ArrayConstr_value(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, ...@@ -1138,7 +1138,7 @@ static HRESULT ArrayConstr_value(script_ctx_t *ctx, vdisp_t *vthis, WORD flags,
case DISPATCH_CONSTRUCT: { case DISPATCH_CONSTRUCT: {
if(arg_cnt(dp) == 1 && V_VT((arg_var = get_arg(dp, 0))) == VT_I4) { if(arg_cnt(dp) == 1 && V_VT((arg_var = get_arg(dp, 0))) == VT_I4) {
if(V_I4(arg_var) < 0) if(V_I4(arg_var) < 0)
return throw_range_error(ctx, ei, IDS_INVALID_LENGTH, NULL); return throw_range_error(ctx, ei, JS_E_INVALID_LENGTH, NULL);
hres = create_array(ctx, V_I4(arg_var), &obj); hres = create_array(ctx, V_I4(arg_var), &obj);
if(FAILED(hres)) if(FAILED(hres))
......
...@@ -49,7 +49,7 @@ static HRESULT Bool_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DIS ...@@ -49,7 +49,7 @@ static HRESULT Bool_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DIS
TRACE("\n"); TRACE("\n");
if(!(bool = bool_this(jsthis))) if(!(bool = bool_this(jsthis)))
return throw_type_error(ctx, ei, IDS_NOT_BOOL, NULL); return throw_type_error(ctx, ei, JS_E_BOOLEAN_EXPECTED, NULL);
if(retv) { if(retv) {
BSTR val; BSTR val;
...@@ -76,7 +76,7 @@ static HRESULT Bool_valueOf(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISP ...@@ -76,7 +76,7 @@ static HRESULT Bool_valueOf(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISP
TRACE("\n"); TRACE("\n");
if(!(bool = bool_this(jsthis))) if(!(bool = bool_this(jsthis)))
return throw_type_error(ctx, ei, IDS_NOT_BOOL, NULL); return throw_type_error(ctx, ei, JS_E_BOOLEAN_EXPECTED, NULL);
if(retv) { if(retv) {
V_VT(retv) = VT_BOOL; V_VT(retv) = VT_BOOL;
...@@ -93,7 +93,7 @@ static HRESULT Bool_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPA ...@@ -93,7 +93,7 @@ static HRESULT Bool_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPA
switch(flags) { switch(flags) {
case INVOKE_FUNC: case INVOKE_FUNC:
return throw_type_error(ctx, ei, IDS_NOT_FUNC, NULL); return throw_type_error(ctx, ei, JS_E_FUNCTION_EXPECTED, NULL);
default: default:
FIXME("unimplemented flags %x\n", flags); FIXME("unimplemented flags %x\n", flags);
return E_NOTIMPL; return E_NOTIMPL;
......
...@@ -81,7 +81,7 @@ static HRESULT exprval_value(script_ctx_t *ctx, exprval_t *val, jsexcept_t *ei, ...@@ -81,7 +81,7 @@ static HRESULT exprval_value(script_ctx_t *ctx, exprval_t *val, jsexcept_t *ei,
case EXPRVAL_NAMEREF: case EXPRVAL_NAMEREF:
break; break;
case EXPRVAL_INVALID: case EXPRVAL_INVALID:
return throw_type_error(ctx, ei, IDS_UNDEFINED, val->u.identifier); return throw_type_error(ctx, ei, JS_E_UNDEFINED_VARIABLE, val->u.identifier);
} }
ERR("type %d\n", val->type); ERR("type %d\n", val->type);
...@@ -247,7 +247,7 @@ static HRESULT disp_get_id(script_ctx_t *ctx, IDispatch *disp, BSTR name, DWORD ...@@ -247,7 +247,7 @@ static HRESULT disp_get_id(script_ctx_t *ctx, IDispatch *disp, BSTR name, DWORD
static HRESULT put_value(script_ctx_t *ctx, exprval_t *ref, VARIANT *v, jsexcept_t *ei) static HRESULT put_value(script_ctx_t *ctx, exprval_t *ref, VARIANT *v, jsexcept_t *ei)
{ {
if(ref->type != EXPRVAL_IDREF) if(ref->type != EXPRVAL_IDREF)
return throw_reference_error(ctx, ei, IDS_ILLEGAL_ASSIGN, NULL); return throw_reference_error(ctx, ei, JS_E_ILLEGAL_ASSIGN, NULL);
return disp_propput(ctx, ref->u.idref.disp, ref->u.idref.id, v, ei, NULL/*FIXME*/); return disp_propput(ctx, ref->u.idref.disp, ref->u.idref.id, v, ei, NULL/*FIXME*/);
} }
...@@ -1560,13 +1560,13 @@ HRESULT new_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, ...@@ -1560,13 +1560,13 @@ HRESULT new_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags,
if(V_VT(&constr) == VT_NULL) { if(V_VT(&constr) == VT_NULL) {
VariantClear(&constr); VariantClear(&constr);
return throw_type_error(ctx, ei, IDS_OBJECT_EXPECTED, NULL); return throw_type_error(ctx, ei, JS_E_OBJECT_EXPECTED, NULL);
} else if(V_VT(&constr) != VT_DISPATCH) { } else if(V_VT(&constr) != VT_DISPATCH) {
VariantClear(&constr); VariantClear(&constr);
return throw_type_error(ctx, ei, IDS_UNSUPPORTED_ACTION, NULL); return throw_type_error(ctx, ei, JS_E_INVALID_ACTION, NULL);
} else if(!V_DISPATCH(&constr)) { } else if(!V_DISPATCH(&constr)) {
VariantClear(&constr); VariantClear(&constr);
return throw_type_error(ctx, ei, IDS_NO_PROPERTY, NULL); return throw_type_error(ctx, ei, JS_E_INVALID_PROPERTY, NULL);
} }
hres = disp_call(ctx, V_DISPATCH(&constr), DISPID_VALUE, hres = disp_call(ctx, V_DISPATCH(&constr), DISPID_VALUE,
...@@ -1604,14 +1604,14 @@ HRESULT call_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags ...@@ -1604,14 +1604,14 @@ HRESULT call_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags
hres = disp_call(ctx, V_DISPATCH(&exprval.u.var), DISPID_VALUE, hres = disp_call(ctx, V_DISPATCH(&exprval.u.var), DISPID_VALUE,
DISPATCH_METHOD, &dp, flags & EXPR_NOVAL ? NULL : &var, ei, NULL/*FIXME*/); DISPATCH_METHOD, &dp, flags & EXPR_NOVAL ? NULL : &var, ei, NULL/*FIXME*/);
else else
hres = throw_type_error(ctx, ei, IDS_NO_PROPERTY, NULL); hres = throw_type_error(ctx, ei, JS_E_INVALID_PROPERTY, NULL);
break; break;
case EXPRVAL_IDREF: case EXPRVAL_IDREF:
hres = disp_call(ctx, exprval.u.idref.disp, exprval.u.idref.id, hres = disp_call(ctx, exprval.u.idref.disp, exprval.u.idref.id,
DISPATCH_METHOD, &dp, flags & EXPR_NOVAL ? NULL : &var, ei, NULL/*FIXME*/); DISPATCH_METHOD, &dp, flags & EXPR_NOVAL ? NULL : &var, ei, NULL/*FIXME*/);
break; break;
case EXPRVAL_INVALID: case EXPRVAL_INVALID:
hres = throw_type_error(ctx, ei, IDS_OBJECT_EXPECTED, NULL); hres = throw_type_error(ctx, ei, JS_E_OBJECT_EXPECTED, NULL);
break; break;
default: default:
FIXME("unimplemented type %d\n", exprval.type); FIXME("unimplemented type %d\n", exprval.type);
...@@ -1996,7 +1996,7 @@ static HRESULT instanceof_eval(script_ctx_t *ctx, VARIANT *inst, VARIANT *objv, ...@@ -1996,7 +1996,7 @@ static HRESULT instanceof_eval(script_ctx_t *ctx, VARIANT *inst, VARIANT *objv,
static const WCHAR prototypeW[] = {'p','r','o','t','o','t', 'y', 'p','e',0}; static const WCHAR prototypeW[] = {'p','r','o','t','o','t', 'y', 'p','e',0};
if(V_VT(objv) != VT_DISPATCH || !V_DISPATCH(objv)) if(V_VT(objv) != VT_DISPATCH || !V_DISPATCH(objv))
return throw_type_error(ctx, ei, IDS_NOT_FUNC, NULL); return throw_type_error(ctx, ei, JS_E_FUNCTION_EXPECTED, NULL);
obj = iface_to_jsdisp((IUnknown*)V_DISPATCH(objv)); obj = iface_to_jsdisp((IUnknown*)V_DISPATCH(objv));
if(!obj) { if(!obj) {
...@@ -2062,7 +2062,7 @@ static HRESULT in_eval(script_ctx_t *ctx, VARIANT *lval, VARIANT *obj, jsexcept_ ...@@ -2062,7 +2062,7 @@ static HRESULT in_eval(script_ctx_t *ctx, VARIANT *lval, VARIANT *obj, jsexcept_
HRESULT hres; HRESULT hres;
if(V_VT(obj) != VT_DISPATCH || !V_DISPATCH(obj)) if(V_VT(obj) != VT_DISPATCH || !V_DISPATCH(obj))
return throw_type_error(ctx, ei, IDS_OBJECT_EXPECTED, NULL); return throw_type_error(ctx, ei, JS_E_OBJECT_EXPECTED, NULL);
hres = to_string(ctx, lval, ei, &str); hres = to_string(ctx, lval, ei, &str);
if(FAILED(hres)) if(FAILED(hres))
......
...@@ -132,7 +132,7 @@ static HRESULT Error_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, ...@@ -132,7 +132,7 @@ static HRESULT Error_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
switch(flags) { switch(flags) {
case INVOKE_FUNC: case INVOKE_FUNC:
return throw_type_error(ctx, ei, IDS_NOT_FUNC, NULL); return throw_type_error(ctx, ei, JS_E_FUNCTION_EXPECTED, NULL);
default: default:
FIXME("unimplemented flags %x\n", flags); FIXME("unimplemented flags %x\n", flags);
return E_NOTIMPL; return E_NOTIMPL;
...@@ -384,14 +384,17 @@ HRESULT init_error_constr(script_ctx_t *ctx, jsdisp_t *object_prototype) ...@@ -384,14 +384,17 @@ HRESULT init_error_constr(script_ctx_t *ctx, jsdisp_t *object_prototype)
return S_OK; return S_OK;
} }
static HRESULT throw_error(script_ctx_t *ctx, jsexcept_t *ei, UINT id, const WCHAR *str, jsdisp_t *constr) static HRESULT throw_error(script_ctx_t *ctx, jsexcept_t *ei, HRESULT error, const WCHAR *str, jsdisp_t *constr)
{ {
WCHAR buf[1024], *pos = NULL; WCHAR buf[1024], *pos = NULL;
jsdisp_t *err; jsdisp_t *err;
HRESULT hres; HRESULT hres;
if(!is_jscript_error(error))
return error;
buf[0] = '\0'; buf[0] = '\0';
LoadStringW(jscript_hinstance, id&0xFFFF, buf, sizeof(buf)/sizeof(WCHAR)); LoadStringW(jscript_hinstance, HRESULT_CODE(error), buf, sizeof(buf)/sizeof(WCHAR));
if(str) pos = strchrW(buf, '|'); if(str) pos = strchrW(buf, '|');
if(pos) { if(pos) {
...@@ -402,47 +405,46 @@ static HRESULT throw_error(script_ctx_t *ctx, jsexcept_t *ei, UINT id, const WCH ...@@ -402,47 +405,46 @@ static HRESULT throw_error(script_ctx_t *ctx, jsexcept_t *ei, UINT id, const WCH
WARN("%s\n", debugstr_w(buf)); WARN("%s\n", debugstr_w(buf));
id |= JSCRIPT_ERROR; hres = create_error(ctx, constr, error, buf, &err);
hres = create_error(ctx, constr, id, buf, &err);
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
if(ei) if(ei)
var_set_jsdisp(&ei->var, err); var_set_jsdisp(&ei->var, err);
return id; return error;
} }
HRESULT throw_generic_error(script_ctx_t *ctx, jsexcept_t *ei, UINT id, const WCHAR *str) HRESULT throw_generic_error(script_ctx_t *ctx, jsexcept_t *ei, HRESULT error, const WCHAR *str)
{ {
return throw_error(ctx, ei, id, str, ctx->error_constr); return throw_error(ctx, ei, error, str, ctx->error_constr);
} }
HRESULT throw_range_error(script_ctx_t *ctx, jsexcept_t *ei, UINT id, const WCHAR *str) HRESULT throw_range_error(script_ctx_t *ctx, jsexcept_t *ei, HRESULT error, const WCHAR *str)
{ {
return throw_error(ctx, ei, id, str, ctx->range_error_constr); return throw_error(ctx, ei, error, str, ctx->range_error_constr);
} }
HRESULT throw_reference_error(script_ctx_t *ctx, jsexcept_t *ei, UINT id, const WCHAR *str) HRESULT throw_reference_error(script_ctx_t *ctx, jsexcept_t *ei, HRESULT error, const WCHAR *str)
{ {
return throw_error(ctx, ei, id, str, ctx->reference_error_constr); return throw_error(ctx, ei, error, str, ctx->reference_error_constr);
} }
HRESULT throw_regexp_error(script_ctx_t *ctx, jsexcept_t *ei, UINT id, const WCHAR *str) HRESULT throw_regexp_error(script_ctx_t *ctx, jsexcept_t *ei, HRESULT error, const WCHAR *str)
{ {
return throw_error(ctx, ei, id, str, ctx->regexp_error_constr); return throw_error(ctx, ei, error, str, ctx->regexp_error_constr);
} }
HRESULT throw_syntax_error(script_ctx_t *ctx, jsexcept_t *ei, UINT id, const WCHAR *str) HRESULT throw_syntax_error(script_ctx_t *ctx, jsexcept_t *ei, HRESULT error, const WCHAR *str)
{ {
return throw_error(ctx, ei, id, str, ctx->syntax_error_constr); return throw_error(ctx, ei, error, str, ctx->syntax_error_constr);
} }
HRESULT throw_type_error(script_ctx_t *ctx, jsexcept_t *ei, UINT id, const WCHAR *str) HRESULT throw_type_error(script_ctx_t *ctx, jsexcept_t *ei, HRESULT error, const WCHAR *str)
{ {
return throw_error(ctx, ei, id, str, ctx->type_error_constr); return throw_error(ctx, ei, error, str, ctx->type_error_constr);
} }
HRESULT throw_uri_error(script_ctx_t *ctx, jsexcept_t *ei, UINT id, const WCHAR *str) HRESULT throw_uri_error(script_ctx_t *ctx, jsexcept_t *ei, HRESULT error, const WCHAR *str)
{ {
return throw_error(ctx, ei, id, str, ctx->uri_error_constr); return throw_error(ctx, ei, error, str, ctx->uri_error_constr);
} }
...@@ -343,7 +343,7 @@ static HRESULT Function_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, ...@@ -343,7 +343,7 @@ static HRESULT Function_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
TRACE("\n"); TRACE("\n");
if(!(function = function_this(jsthis))) if(!(function = function_this(jsthis)))
return throw_type_error(ctx, ei, IDS_NOT_FUNC, NULL); return throw_type_error(ctx, ei, JS_E_FUNCTION_EXPECTED, NULL);
hres = function_to_string(function, &str); hres = function_to_string(function, &str);
if(FAILED(hres)) if(FAILED(hres))
...@@ -407,7 +407,7 @@ static HRESULT Function_apply(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DI ...@@ -407,7 +407,7 @@ static HRESULT Function_apply(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DI
TRACE("\n"); TRACE("\n");
if(!(function = function_this(jsthis))) if(!(function = function_this(jsthis)))
return throw_type_error(ctx, ei, IDS_NOT_FUNC, NULL); return throw_type_error(ctx, ei, JS_E_FUNCTION_EXPECTED, NULL);
argc = arg_cnt(dp); argc = arg_cnt(dp);
if(argc) { if(argc) {
...@@ -463,7 +463,7 @@ static HRESULT Function_call(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DIS ...@@ -463,7 +463,7 @@ static HRESULT Function_call(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DIS
TRACE("\n"); TRACE("\n");
if(!(function = function_this(jsthis))) if(!(function = function_this(jsthis)))
return throw_type_error(ctx, ei, IDS_NOT_FUNC, NULL); return throw_type_error(ctx, ei, JS_E_FUNCTION_EXPECTED, NULL);
argc = arg_cnt(dp); argc = arg_cnt(dp);
if(argc) { if(argc) {
......
...@@ -803,7 +803,7 @@ static HRESULT JSGlobal_encodeURI(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags ...@@ -803,7 +803,7 @@ static HRESULT JSGlobal_encodeURI(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
i = WideCharToMultiByte(CP_UTF8, 0, ptr, 1, NULL, 0, NULL, NULL)*3; i = WideCharToMultiByte(CP_UTF8, 0, ptr, 1, NULL, 0, NULL, NULL)*3;
if(!i) { if(!i) {
SysFreeString(str); SysFreeString(str);
return throw_uri_error(ctx, ei, IDS_URI_INVALID_CHAR, NULL); return throw_uri_error(ctx, ei, JS_E_INVALID_URI_CHAR, NULL);
} }
len += i; len += i;
......
...@@ -33,8 +33,6 @@ ...@@ -33,8 +33,6 @@
#include "wine/unicode.h" #include "wine/unicode.h"
#include "wine/list.h" #include "wine/list.h"
#define JSCRIPT_ERROR 0x800A0000
typedef struct _script_ctx_t script_ctx_t; typedef struct _script_ctx_t script_ctx_t;
typedef struct _exec_ctx_t exec_ctx_t; typedef struct _exec_ctx_t exec_ctx_t;
typedef struct _dispex_prop_t dispex_prop_t; typedef struct _dispex_prop_t dispex_prop_t;
...@@ -226,14 +224,14 @@ HRESULT create_builtin_function(script_ctx_t*,builtin_invoke_t,const WCHAR*,cons ...@@ -226,14 +224,14 @@ HRESULT create_builtin_function(script_ctx_t*,builtin_invoke_t,const WCHAR*,cons
jsdisp_t*,jsdisp_t**); jsdisp_t*,jsdisp_t**);
HRESULT Function_value(script_ctx_t*,vdisp_t*,WORD,DISPPARAMS*,VARIANT*,jsexcept_t*,IServiceProvider*); HRESULT Function_value(script_ctx_t*,vdisp_t*,WORD,DISPPARAMS*,VARIANT*,jsexcept_t*,IServiceProvider*);
HRESULT throw_eval_error(script_ctx_t*,jsexcept_t*,UINT,const WCHAR*); HRESULT throw_eval_error(script_ctx_t*,jsexcept_t*,HRESULT,const WCHAR*);
HRESULT throw_generic_error(script_ctx_t*,jsexcept_t*,UINT,const WCHAR*); HRESULT throw_generic_error(script_ctx_t*,jsexcept_t*,HRESULT,const WCHAR*);
HRESULT throw_range_error(script_ctx_t*,jsexcept_t*,UINT,const WCHAR*); HRESULT throw_range_error(script_ctx_t*,jsexcept_t*,HRESULT,const WCHAR*);
HRESULT throw_reference_error(script_ctx_t*,jsexcept_t*,UINT,const WCHAR*); HRESULT throw_reference_error(script_ctx_t*,jsexcept_t*,HRESULT,const WCHAR*);
HRESULT throw_regexp_error(script_ctx_t*,jsexcept_t*,UINT,const WCHAR*); HRESULT throw_regexp_error(script_ctx_t*,jsexcept_t*,HRESULT,const WCHAR*);
HRESULT throw_syntax_error(script_ctx_t*,jsexcept_t*,UINT,const WCHAR*); HRESULT throw_syntax_error(script_ctx_t*,jsexcept_t*,HRESULT,const WCHAR*);
HRESULT throw_type_error(script_ctx_t*,jsexcept_t*,UINT,const WCHAR*); HRESULT throw_type_error(script_ctx_t*,jsexcept_t*,HRESULT,const WCHAR*);
HRESULT throw_uri_error(script_ctx_t*,jsexcept_t*,UINT,const WCHAR*); HRESULT throw_uri_error(script_ctx_t*,jsexcept_t*,HRESULT,const WCHAR*);
HRESULT create_object(script_ctx_t*,jsdisp_t*,jsdisp_t**); HRESULT create_object(script_ctx_t*,jsdisp_t*,jsdisp_t**);
HRESULT create_math(script_ctx_t*,jsdisp_t**); HRESULT create_math(script_ctx_t*,jsdisp_t**);
...@@ -434,6 +432,41 @@ static inline DWORD make_grfdex(script_ctx_t *ctx, DWORD flags) ...@@ -434,6 +432,41 @@ static inline DWORD make_grfdex(script_ctx_t *ctx, DWORD flags)
return (ctx->version << 28) | flags; return (ctx->version << 28) | flags;
} }
#define FACILITY_JSCRIPT 10
#define MAKE_JSERROR(code) MAKE_HRESULT(SEVERITY_ERROR, FACILITY_JSCRIPT, code)
#define JS_E_TO_PRIMITIVE MAKE_JSERROR(IDS_TO_PRIMITIVE)
#define JS_E_INVALIDARG MAKE_JSERROR(IDS_INVALID_CALL_ARG)
#define JS_E_SUBSCRIPT_OUT_OF_RANGE MAKE_JSERROR(IDS_SUBSCRIPT_OUT_OF_RANGE)
#define JS_E_CANNOT_CREATE_OBJ MAKE_JSERROR(IDS_CREATE_OBJ_ERROR)
#define JS_E_INVALID_PROPERTY MAKE_JSERROR(IDS_NO_PROPERTY)
#define JS_E_INVALID_ACTION MAKE_JSERROR(IDS_UNSUPPORTED_ACTION)
#define JS_E_MISSING_ARG MAKE_JSERROR(IDS_ARG_NOT_OPT)
#define JS_E_SYNTAX MAKE_JSERROR(IDS_SYNTAX_ERROR)
#define JS_E_MISSING_SEMICOLON MAKE_JSERROR(IDS_SEMICOLON)
#define JS_E_MISSING_LBRACKET MAKE_JSERROR(IDS_LBRACKET)
#define JS_E_MISSING_RBRACKET MAKE_JSERROR(IDS_RBRACKET)
#define JS_E_UNTERMINATED_STRING MAKE_JSERROR(IDS_UNTERMINATED_STR)
#define JS_E_FUNCTION_EXPECTED MAKE_JSERROR(IDS_NOT_FUNC)
#define JS_E_DATE_EXPECTED MAKE_JSERROR(IDS_NOT_DATE)
#define JS_E_NUMBER_EXPECTED MAKE_JSERROR(IDS_NOT_NUM)
#define JS_E_OBJECT_EXPECTED MAKE_JSERROR(IDS_OBJECT_EXPECTED)
#define JS_E_ILLEGAL_ASSIGN MAKE_JSERROR(IDS_ILLEGAL_ASSIGN)
#define JS_E_UNDEFINED_VARIABLE MAKE_JSERROR(IDS_UNDEFINED)
#define JS_E_BOOLEAN_EXPECTED MAKE_JSERROR(IDS_NOT_BOOL)
#define JS_E_VBARRAY_EXPECTED MAKE_JSERROR(IDS_NOT_VBARRAY)
#define JS_E_JSCRIPT_EXPECTED MAKE_JSERROR(IDS_JSCRIPT_EXPECTED)
#define JS_E_REGEXP_SYNTAX MAKE_JSERROR(IDS_REGEXP_SYNTAX_ERROR)
#define JS_E_INVALID_URI_CHAR MAKE_JSERROR(IDS_URI_INVALID_CHAR)
#define JS_E_INVALID_LENGTH MAKE_JSERROR(IDS_INVALID_LENGTH)
#define JS_E_ARRAY_EXPECTED MAKE_JSERROR(IDS_ARRAY_EXPECTED)
static inline BOOL is_jscript_error(HRESULT hres)
{
return HRESULT_FACILITY(hres) == FACILITY_JSCRIPT;
}
const char *debugstr_variant(const VARIANT*); const char *debugstr_variant(const VARIANT*);
HRESULT WINAPI JScriptFactory_CreateInstance(IClassFactory*,IUnknown*,REFIID,void**); HRESULT WINAPI JScriptFactory_CreateInstance(IClassFactory*,IUnknown*,REFIID,void**);
......
...@@ -252,7 +252,7 @@ HRESULT to_primitive(script_ctx_t *ctx, VARIANT *v, jsexcept_t *ei, VARIANT *ret ...@@ -252,7 +252,7 @@ HRESULT to_primitive(script_ctx_t *ctx, VARIANT *v, jsexcept_t *ei, VARIANT *ret
jsdisp_release(jsdisp); jsdisp_release(jsdisp);
WARN("failed\n"); WARN("failed\n");
return throw_type_error(ctx, ei, IDS_TO_PRIMITIVE, NULL); return throw_type_error(ctx, ei, JS_E_TO_PRIMITIVE, NULL);
} }
default: default:
FIXME("Unimplemented for vt %d\n", V_VT(v)); FIXME("Unimplemented for vt %d\n", V_VT(v));
......
...@@ -99,7 +99,7 @@ static const struct { ...@@ -99,7 +99,7 @@ static const struct {
static int lex_error(parser_ctx_t *ctx, HRESULT hres) static int lex_error(parser_ctx_t *ctx, HRESULT hres)
{ {
ctx->hres = JSCRIPT_ERROR|hres; ctx->hres = MAKE_JSERROR(hres);
ctx->lexer_error = TRUE; ctx->lexer_error = TRUE;
return -1; return -1;
} }
......
...@@ -65,7 +65,7 @@ static HRESULT Number_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, D ...@@ -65,7 +65,7 @@ static HRESULT Number_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, D
TRACE("\n"); TRACE("\n");
if(!(number = number_this(jsthis))) if(!(number = number_this(jsthis)))
return throw_type_error(ctx, ei, IDS_NOT_NUM, NULL); return throw_type_error(ctx, ei, JS_E_NUMBER_EXPECTED, NULL);
if(arg_cnt(dp)) { if(arg_cnt(dp)) {
hres = to_int32(ctx, get_arg(dp, 0), ei, &radix); hres = to_int32(ctx, get_arg(dp, 0), ei, &radix);
...@@ -73,7 +73,7 @@ static HRESULT Number_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, D ...@@ -73,7 +73,7 @@ static HRESULT Number_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, D
return hres; return hres;
if(radix<2 || radix>36) if(radix<2 || radix>36)
return throw_type_error(ctx, ei, IDS_INVALID_CALL_ARG, NULL); return throw_type_error(ctx, ei, JS_E_INVALIDARG, NULL);
} }
if(V_VT(&number->num) == VT_I4) if(V_VT(&number->num) == VT_I4)
...@@ -215,7 +215,7 @@ static HRESULT Number_valueOf(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DI ...@@ -215,7 +215,7 @@ static HRESULT Number_valueOf(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DI
TRACE("\n"); TRACE("\n");
if(!(number = number_this(jsthis))) if(!(number = number_this(jsthis)))
return throw_type_error(ctx, ei, IDS_NOT_NUM, NULL); return throw_type_error(ctx, ei, JS_E_NUMBER_EXPECTED, NULL);
if(retv) if(retv)
*retv = number->num; *retv = number->num;
...@@ -229,7 +229,7 @@ static HRESULT Number_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISP ...@@ -229,7 +229,7 @@ static HRESULT Number_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISP
switch(flags) { switch(flags) {
case INVOKE_FUNC: case INVOKE_FUNC:
return throw_type_error(ctx, ei, IDS_NOT_FUNC, NULL); return throw_type_error(ctx, ei, JS_E_FUNCTION_EXPECTED, NULL);
case DISPATCH_PROPERTYGET: case DISPATCH_PROPERTYGET:
*retv = number->num; *retv = number->num;
break; break;
......
...@@ -136,7 +136,7 @@ static HRESULT Object_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISP ...@@ -136,7 +136,7 @@ static HRESULT Object_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISP
switch(flags) { switch(flags) {
case INVOKE_FUNC: case INVOKE_FUNC:
return throw_type_error(ctx, ei, IDS_NOT_FUNC, NULL); return throw_type_error(ctx, ei, JS_E_FUNCTION_EXPECTED, NULL);
case DISPATCH_PROPERTYGET: case DISPATCH_PROPERTYGET:
V_VT(retv) = VT_BSTR; V_VT(retv) = VT_BSTR;
V_BSTR(retv) = SysAllocString(default_valueW); V_BSTR(retv) = SysAllocString(default_valueW);
......
...@@ -1459,7 +1459,7 @@ static int parser_error(const char *str) ...@@ -1459,7 +1459,7 @@ static int parser_error(const char *str)
static void set_error(parser_ctx_t *ctx, UINT error) static void set_error(parser_ctx_t *ctx, UINT error)
{ {
ctx->hres = JSCRIPT_ERROR|error; ctx->hres = MAKE_JSERROR(error);
} }
static BOOL explicit_error(parser_ctx_t *ctx, void *obj, WCHAR next) static BOOL explicit_error(parser_ctx_t *ctx, void *obj, WCHAR next)
...@@ -1603,7 +1603,7 @@ HRESULT script_parse(script_ctx_t *ctx, const WCHAR *code, const WCHAR *delimite ...@@ -1603,7 +1603,7 @@ HRESULT script_parse(script_ctx_t *ctx, const WCHAR *code, const WCHAR *delimite
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
parser_ctx->ref = 1; parser_ctx->ref = 1;
parser_ctx->hres = JSCRIPT_ERROR|IDS_SYNTAX_ERROR; parser_ctx->hres = JS_E_SYNTAX;
parser_ctx->is_html = delimiter && !strcmpiW(delimiter, html_tagW); parser_ctx->is_html = delimiter && !strcmpiW(delimiter, html_tagW);
parser_ctx->begin = heap_strdupW(code); parser_ctx->begin = heap_strdupW(code);
......
...@@ -3778,7 +3778,7 @@ static HRESULT RegExp_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISP ...@@ -3778,7 +3778,7 @@ static HRESULT RegExp_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISP
switch(flags) { switch(flags) {
case INVOKE_FUNC: case INVOKE_FUNC:
return throw_type_error(ctx, ei, IDS_NOT_FUNC, NULL); return throw_type_error(ctx, ei, JS_E_FUNCTION_EXPECTED, NULL);
default: default:
FIXME("unimplemented flags %x\n", flags); FIXME("unimplemented flags %x\n", flags);
return E_NOTIMPL; return E_NOTIMPL;
...@@ -4089,7 +4089,7 @@ static HRESULT RegExpConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags ...@@ -4089,7 +4089,7 @@ static HRESULT RegExpConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
if(is_class(jsdisp, JSCLASS_REGEXP)) { if(is_class(jsdisp, JSCLASS_REGEXP)) {
if(arg_cnt(dp) > 1 && V_VT(get_arg(dp,1)) != VT_EMPTY) { if(arg_cnt(dp) > 1 && V_VT(get_arg(dp,1)) != VT_EMPTY) {
jsdisp_release(jsdisp); jsdisp_release(jsdisp);
return throw_regexp_error(ctx, ei, IDS_REGEXP_SYNTAX_ERROR, NULL); return throw_regexp_error(ctx, ei, JS_E_REGEXP_SYNTAX, NULL);
} }
if(retv) if(retv)
......
...@@ -1526,7 +1526,7 @@ static HRESULT String_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISP ...@@ -1526,7 +1526,7 @@ static HRESULT String_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISP
switch(flags) { switch(flags) {
case INVOKE_FUNC: case INVOKE_FUNC:
return throw_type_error(ctx, ei, IDS_NOT_FUNC, NULL); return throw_type_error(ctx, ei, JS_E_FUNCTION_EXPECTED, NULL);
case DISPATCH_PROPERTYGET: { case DISPATCH_PROPERTYGET: {
BSTR str = SysAllocString(This->str); BSTR str = SysAllocString(This->str);
if(!str) if(!str)
......
...@@ -53,7 +53,7 @@ static HRESULT VBArray_dimensions(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, ...@@ -53,7 +53,7 @@ static HRESULT VBArray_dimensions(script_ctx_t *ctx, vdisp_t *vthis, WORD flags,
vbarray = vbarray_this(vthis); vbarray = vbarray_this(vthis);
if(!vbarray) if(!vbarray)
return throw_type_error(ctx, ei, IDS_NOT_VBARRAY, NULL); return throw_type_error(ctx, ei, JS_E_VBARRAY_EXPECTED, NULL);
if(retv) if(retv)
num_set_int(retv, SafeArrayGetDim(vbarray->safearray)); num_set_int(retv, SafeArrayGetDim(vbarray->safearray));
...@@ -72,11 +72,11 @@ static HRESULT VBArray_getItem(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, DI ...@@ -72,11 +72,11 @@ static HRESULT VBArray_getItem(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, DI
vbarray = vbarray_this(vthis); vbarray = vbarray_this(vthis);
if(!vbarray) if(!vbarray)
return throw_type_error(ctx, ei, IDS_NOT_VBARRAY, NULL); return throw_type_error(ctx, ei, JS_E_VBARRAY_EXPECTED, NULL);
size = arg_cnt(dp); size = arg_cnt(dp);
if(size < SafeArrayGetDim(vbarray->safearray)) if(size < SafeArrayGetDim(vbarray->safearray))
return throw_range_error(ctx, ei, IDS_SUBSCRIPT_OUT_OF_RANGE, NULL); return throw_range_error(ctx, ei, JS_E_SUBSCRIPT_OUT_OF_RANGE, NULL);
indexes = heap_alloc(sizeof(int)*size); indexes = heap_alloc(sizeof(int)*size);
if(!indexes) if(!indexes)
...@@ -93,7 +93,7 @@ static HRESULT VBArray_getItem(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, DI ...@@ -93,7 +93,7 @@ static HRESULT VBArray_getItem(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, DI
hres = SafeArrayGetElement(vbarray->safearray, indexes, (void*)&out); hres = SafeArrayGetElement(vbarray->safearray, indexes, (void*)&out);
heap_free(indexes); heap_free(indexes);
if(hres == DISP_E_BADINDEX) if(hres == DISP_E_BADINDEX)
return throw_range_error(ctx, ei, IDS_SUBSCRIPT_OUT_OF_RANGE, NULL); return throw_range_error(ctx, ei, JS_E_SUBSCRIPT_OUT_OF_RANGE, NULL);
else if(FAILED(hres)) else if(FAILED(hres))
return hres; return hres;
...@@ -114,7 +114,7 @@ static HRESULT VBArray_lbound(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, DIS ...@@ -114,7 +114,7 @@ static HRESULT VBArray_lbound(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, DIS
vbarray = vbarray_this(vthis); vbarray = vbarray_this(vthis);
if(!vbarray) if(!vbarray)
return throw_type_error(ctx, ei, IDS_NOT_VBARRAY, NULL); return throw_type_error(ctx, ei, JS_E_VBARRAY_EXPECTED, NULL);
if(arg_cnt(dp)) { if(arg_cnt(dp)) {
hres = to_int32(ctx, get_arg(dp, 0), ei, &dim); hres = to_int32(ctx, get_arg(dp, 0), ei, &dim);
...@@ -125,7 +125,7 @@ static HRESULT VBArray_lbound(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, DIS ...@@ -125,7 +125,7 @@ static HRESULT VBArray_lbound(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, DIS
hres = SafeArrayGetLBound(vbarray->safearray, dim, &dim); hres = SafeArrayGetLBound(vbarray->safearray, dim, &dim);
if(hres == DISP_E_BADINDEX) if(hres == DISP_E_BADINDEX)
return throw_range_error(ctx, ei, IDS_SUBSCRIPT_OUT_OF_RANGE, NULL); return throw_range_error(ctx, ei, JS_E_SUBSCRIPT_OUT_OF_RANGE, NULL);
else if(FAILED(hres)) else if(FAILED(hres))
return hres; return hres;
...@@ -147,7 +147,7 @@ static HRESULT VBArray_toArray(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, DI ...@@ -147,7 +147,7 @@ static HRESULT VBArray_toArray(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, DI
vbarray = vbarray_this(vthis); vbarray = vbarray_this(vthis);
if(!vbarray) if(!vbarray)
return throw_type_error(ctx, ei, IDS_NOT_VBARRAY, NULL); return throw_type_error(ctx, ei, JS_E_VBARRAY_EXPECTED, NULL);
for(i=1; i<=SafeArrayGetDim(vbarray->safearray); i++) { for(i=1; i<=SafeArrayGetDim(vbarray->safearray); i++) {
SafeArrayGetLBound(vbarray->safearray, i, &lbound); SafeArrayGetLBound(vbarray->safearray, i, &lbound);
...@@ -193,7 +193,7 @@ static HRESULT VBArray_ubound(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, DIS ...@@ -193,7 +193,7 @@ static HRESULT VBArray_ubound(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, DIS
vbarray = vbarray_this(vthis); vbarray = vbarray_this(vthis);
if(!vbarray) if(!vbarray)
return throw_type_error(ctx, ei, IDS_NOT_VBARRAY, NULL); return throw_type_error(ctx, ei, JS_E_VBARRAY_EXPECTED, NULL);
if(arg_cnt(dp)) { if(arg_cnt(dp)) {
hres = to_int32(ctx, get_arg(dp, 0), ei, &dim); hres = to_int32(ctx, get_arg(dp, 0), ei, &dim);
...@@ -204,7 +204,7 @@ static HRESULT VBArray_ubound(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, DIS ...@@ -204,7 +204,7 @@ static HRESULT VBArray_ubound(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, DIS
hres = SafeArrayGetUBound(vbarray->safearray, dim, &dim); hres = SafeArrayGetUBound(vbarray->safearray, dim, &dim);
if(hres == DISP_E_BADINDEX) if(hres == DISP_E_BADINDEX)
return throw_range_error(ctx, ei, IDS_SUBSCRIPT_OUT_OF_RANGE, NULL); return throw_range_error(ctx, ei, JS_E_SUBSCRIPT_OUT_OF_RANGE, NULL);
else if(FAILED(hres)) else if(FAILED(hres))
return hres; return hres;
...@@ -287,14 +287,14 @@ static HRESULT VBArrayConstr_value(script_ctx_t *ctx, vdisp_t *vthis, WORD flags ...@@ -287,14 +287,14 @@ static HRESULT VBArrayConstr_value(script_ctx_t *ctx, vdisp_t *vthis, WORD flags
switch(flags) { switch(flags) {
case DISPATCH_METHOD: case DISPATCH_METHOD:
if(arg_cnt(dp)<1 || V_VT((arg = get_arg(dp, 0)))!=(VT_ARRAY|VT_VARIANT)) if(arg_cnt(dp)<1 || V_VT((arg = get_arg(dp, 0)))!=(VT_ARRAY|VT_VARIANT))
return throw_type_error(ctx, ei, IDS_NOT_VBARRAY, NULL); return throw_type_error(ctx, ei, JS_E_VBARRAY_EXPECTED, NULL);
hres = VariantCopy(retv, arg); hres = VariantCopy(retv, arg);
return hres; return hres;
case DISPATCH_CONSTRUCT: case DISPATCH_CONSTRUCT:
if(arg_cnt(dp)<1 || V_VT((arg = get_arg(dp, 0)))!=(VT_ARRAY|VT_VARIANT)) if(arg_cnt(dp)<1 || V_VT((arg = get_arg(dp, 0)))!=(VT_ARRAY|VT_VARIANT))
return throw_type_error(ctx, ei, IDS_NOT_VBARRAY, NULL); return throw_type_error(ctx, ei, JS_E_VBARRAY_EXPECTED, NULL);
hres = alloc_vbarray(ctx, NULL, &vbarray); hres = alloc_vbarray(ctx, NULL, &vbarray);
if(FAILED(hres)) if(FAILED(hres))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment