From 228aab23be7bd3b23cb362dd186eebce87171532 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Mon, 17 Sep 2012 15:19:19 +0200 Subject: [PATCH] jscript: Always use jsval-based to_object implementation. --- dlls/jscript/engine.c | 8 +++--- dlls/jscript/function.c | 4 +-- dlls/jscript/jscript.h | 3 +- dlls/jscript/jsutils.c | 64 +++++++++++++++++------------------------ dlls/jscript/object.c | 2 +- 5 files changed, 34 insertions(+), 47 deletions(-) diff --git a/dlls/jscript/engine.c b/dlls/jscript/engine.c index 9cdc2fb4719..1a06b19c6e8 100644 --- a/dlls/jscript/engine.c +++ b/dlls/jscript/engine.c @@ -148,7 +148,7 @@ static HRESULT stack_pop_object(exec_ctx_t *ctx, IDispatch **r) return S_OK; } - hres = to_object_jsval(ctx->script, v, r); + hres = to_object(ctx->script, v, r); jsval_release(v); return hres; } @@ -627,7 +627,7 @@ static HRESULT interp_push_scope(exec_ctx_t *ctx) TRACE("\n"); v = stack_pop(ctx); - hres = to_object_jsval(ctx->script, v, &disp); + hres = to_object(ctx->script, v, &disp); jsval_release(v); if(FAILED(hres)) return hres; @@ -878,7 +878,7 @@ static HRESULT interp_memberid(exec_ctx_t *ctx) namev = stack_pop(ctx); objv = stack_pop(ctx); - hres = to_object_jsval(ctx->script, objv, &obj); + hres = to_object(ctx->script, objv, &obj); jsval_release(objv); if(SUCCEEDED(hres)) { hres = to_string(ctx->script, namev, ctx->ei, &name); @@ -1578,7 +1578,7 @@ static HRESULT interp_delete(exec_ctx_t *ctx) namev = stack_pop(ctx); objv = stack_pop(ctx); - hres = to_object_jsval(ctx->script, objv, &obj); + hres = to_object(ctx->script, objv, &obj); jsval_release(objv); if(FAILED(hres)) { jsval_release(namev); diff --git a/dlls/jscript/function.c b/dlls/jscript/function.c index 401aae25fd2..041f1049857 100644 --- a/dlls/jscript/function.c +++ b/dlls/jscript/function.c @@ -389,7 +389,7 @@ static HRESULT Function_apply(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, un if(argc) { if(!is_undefined(argv[0]) && !is_null(argv[0])) { - hres = to_object_jsval(ctx, argv[0], &this_obj); + hres = to_object(ctx, argv[0], &this_obj); if(FAILED(hres)) return hres; } @@ -442,7 +442,7 @@ static HRESULT Function_call(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, uns if(argc) { if(!is_undefined(argv[0]) && !is_null(argv[0])) { - hres = to_object_jsval(ctx, argv[0], &this_obj); + hres = to_object(ctx, argv[0], &this_obj); if(FAILED(hres)) return hres; } diff --git a/dlls/jscript/jscript.h b/dlls/jscript/jscript.h index 4a40bc618fd..bbac902e2c5 100644 --- a/dlls/jscript/jscript.h +++ b/dlls/jscript/jscript.h @@ -261,8 +261,7 @@ HRESULT to_integer(script_ctx_t*,jsval_t,jsexcept_t*,double*) DECLSPEC_HIDDEN; HRESULT to_int32(script_ctx_t*,jsval_t,jsexcept_t*,INT*) DECLSPEC_HIDDEN; HRESULT to_uint32(script_ctx_t*,jsval_t,jsexcept_t*,DWORD*) DECLSPEC_HIDDEN; HRESULT to_string(script_ctx_t*,jsval_t,jsexcept_t*,BSTR*) DECLSPEC_HIDDEN; -HRESULT to_object(script_ctx_t*,VARIANT*,IDispatch**) DECLSPEC_HIDDEN; -HRESULT to_object_jsval(script_ctx_t*,jsval_t,IDispatch**) DECLSPEC_HIDDEN; +HRESULT to_object(script_ctx_t*,jsval_t,IDispatch**) DECLSPEC_HIDDEN; HRESULT variant_change_type(script_ctx_t*,VARIANT*,VARIANT*,VARTYPE) DECLSPEC_HIDDEN; diff --git a/dlls/jscript/jsutils.c b/dlls/jscript/jsutils.c index e89b8ae04d6..1801f861a24 100644 --- a/dlls/jscript/jsutils.c +++ b/dlls/jscript/jsutils.c @@ -760,31 +760,30 @@ HRESULT to_string(script_ctx_t *ctx, jsval_t val, jsexcept_t *ei, BSTR *str) } /* ECMA-262 3rd Edition 9.9 */ -HRESULT to_object(script_ctx_t *ctx, VARIANT *v, IDispatch **disp) +HRESULT to_object(script_ctx_t *ctx, jsval_t val, IDispatch **disp) { jsdisp_t *dispex; HRESULT hres; - switch(V_VT(v)) { - case VT_BSTR: - hres = create_string(ctx, V_BSTR(v), SysStringLen(V_BSTR(v)), &dispex); + switch(val.type) { + case JSV_STRING: + hres = create_string(ctx, get_string(val), SysStringLen(get_string(val)), &dispex); if(FAILED(hres)) return hres; *disp = to_disp(dispex); break; - case VT_I4: - case VT_R8: - hres = create_number(ctx, num_val(v), &dispex); + case JSV_NUMBER: + hres = create_number(ctx, get_number(val), &dispex); if(FAILED(hres)) return hres; *disp = to_disp(dispex); break; - case VT_DISPATCH: - if(V_DISPATCH(v)) { - IDispatch_AddRef(V_DISPATCH(v)); - *disp = V_DISPATCH(v); + case JSV_OBJECT: + if(get_object(val)) { + *disp = get_object(val); + IDispatch_AddRef(*disp); }else { jsdisp_t *obj; @@ -795,47 +794,36 @@ HRESULT to_object(script_ctx_t *ctx, VARIANT *v, IDispatch **disp) *disp = to_disp(obj); } break; - case VT_BOOL: - hres = create_bool(ctx, V_BOOL(v), &dispex); + case JSV_BOOL: + hres = create_bool(ctx, get_bool(val), &dispex); if(FAILED(hres)) return hres; *disp = to_disp(dispex); break; - case VT_ARRAY|VT_VARIANT: - hres = create_vbarray(ctx, V_ARRAY(v), &dispex); - if(FAILED(hres)) - return hres; + case JSV_VARIANT: + switch(V_VT(get_variant(val))) { + case VT_ARRAY|VT_VARIANT: + hres = create_vbarray(ctx, V_ARRAY(get_variant(val)), &dispex); + if(FAILED(hres)) + return hres; - *disp = to_disp(dispex); + *disp = to_disp(dispex); + break; + + default: + FIXME("Unsupported %s\n", debugstr_variant(get_variant(val))); + return E_NOTIMPL; + } break; default: - FIXME("unsupported vt %d\n", V_VT(v)); + FIXME("unsupported %s\n", debugstr_jsval(val)); return E_NOTIMPL; } return S_OK; } -/* ECMA-262 3rd Edition 9.9 */ -HRESULT to_object_jsval(script_ctx_t *ctx, jsval_t v, IDispatch **disp) -{ - VARIANT var; - HRESULT hres; - - if(is_object_instance(v)) { - *disp = get_object(v); - IDispatch_AddRef(*disp); - return S_OK; - } - - hres = jsval_to_variant(v, &var); - if(FAILED(hres)) - return hres; - - return to_object(ctx, &var, disp); -} - HRESULT variant_change_type(script_ctx_t *ctx, VARIANT *dst, VARIANT *src, VARTYPE vt) { jsexcept_t ei; diff --git a/dlls/jscript/object.c b/dlls/jscript/object.c index b88cf840da1..99daf461b1b 100644 --- a/dlls/jscript/object.c +++ b/dlls/jscript/object.c @@ -228,7 +228,7 @@ static HRESULT ObjectConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags if(!is_undefined(argv[0]) && !is_null(argv[0]) && (!is_object_instance(argv[0]) || get_object(argv[0]))) { IDispatch *disp; - hres = to_object_jsval(ctx, argv[0], &disp); + hres = to_object(ctx, argv[0], &disp); if(FAILED(hres)) return hres;