jscript: Always use jsval-based to_object implementation.

This commit is contained in:
Jacek Caban 2012-09-17 15:19:19 +02:00 committed by Alexandre Julliard
parent acfd2b98c3
commit 228aab23be
5 changed files with 34 additions and 47 deletions

View File

@ -148,7 +148,7 @@ static HRESULT stack_pop_object(exec_ctx_t *ctx, IDispatch **r)
return S_OK; return S_OK;
} }
hres = to_object_jsval(ctx->script, v, r); hres = to_object(ctx->script, v, r);
jsval_release(v); jsval_release(v);
return hres; return hres;
} }
@ -627,7 +627,7 @@ static HRESULT interp_push_scope(exec_ctx_t *ctx)
TRACE("\n"); TRACE("\n");
v = stack_pop(ctx); v = stack_pop(ctx);
hres = to_object_jsval(ctx->script, v, &disp); hres = to_object(ctx->script, v, &disp);
jsval_release(v); jsval_release(v);
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
@ -878,7 +878,7 @@ static HRESULT interp_memberid(exec_ctx_t *ctx)
namev = stack_pop(ctx); namev = stack_pop(ctx);
objv = 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); jsval_release(objv);
if(SUCCEEDED(hres)) { if(SUCCEEDED(hres)) {
hres = to_string(ctx->script, namev, ctx->ei, &name); 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); namev = stack_pop(ctx);
objv = 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); jsval_release(objv);
if(FAILED(hres)) { if(FAILED(hres)) {
jsval_release(namev); jsval_release(namev);

View File

@ -389,7 +389,7 @@ static HRESULT Function_apply(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, un
if(argc) { if(argc) {
if(!is_undefined(argv[0]) && !is_null(argv[0])) { 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)) if(FAILED(hres))
return hres; return hres;
} }
@ -442,7 +442,7 @@ static HRESULT Function_call(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, uns
if(argc) { if(argc) {
if(!is_undefined(argv[0]) && !is_null(argv[0])) { 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)) if(FAILED(hres))
return hres; return hres;
} }

View File

@ -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_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_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_string(script_ctx_t*,jsval_t,jsexcept_t*,BSTR*) DECLSPEC_HIDDEN;
HRESULT to_object(script_ctx_t*,VARIANT*,IDispatch**) DECLSPEC_HIDDEN; HRESULT to_object(script_ctx_t*,jsval_t,IDispatch**) DECLSPEC_HIDDEN;
HRESULT to_object_jsval(script_ctx_t*,jsval_t,IDispatch**) DECLSPEC_HIDDEN;
HRESULT variant_change_type(script_ctx_t*,VARIANT*,VARIANT*,VARTYPE) DECLSPEC_HIDDEN; HRESULT variant_change_type(script_ctx_t*,VARIANT*,VARIANT*,VARTYPE) DECLSPEC_HIDDEN;

View File

@ -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 */ /* 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; jsdisp_t *dispex;
HRESULT hres; HRESULT hres;
switch(V_VT(v)) { switch(val.type) {
case VT_BSTR: case JSV_STRING:
hres = create_string(ctx, V_BSTR(v), SysStringLen(V_BSTR(v)), &dispex); hres = create_string(ctx, get_string(val), SysStringLen(get_string(val)), &dispex);
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
*disp = to_disp(dispex); *disp = to_disp(dispex);
break; break;
case VT_I4: case JSV_NUMBER:
case VT_R8: hres = create_number(ctx, get_number(val), &dispex);
hres = create_number(ctx, num_val(v), &dispex);
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
*disp = to_disp(dispex); *disp = to_disp(dispex);
break; break;
case VT_DISPATCH: case JSV_OBJECT:
if(V_DISPATCH(v)) { if(get_object(val)) {
IDispatch_AddRef(V_DISPATCH(v)); *disp = get_object(val);
*disp = V_DISPATCH(v); IDispatch_AddRef(*disp);
}else { }else {
jsdisp_t *obj; jsdisp_t *obj;
@ -795,47 +794,36 @@ HRESULT to_object(script_ctx_t *ctx, VARIANT *v, IDispatch **disp)
*disp = to_disp(obj); *disp = to_disp(obj);
} }
break; break;
case VT_BOOL: case JSV_BOOL:
hres = create_bool(ctx, V_BOOL(v), &dispex); hres = create_bool(ctx, get_bool(val), &dispex);
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
*disp = to_disp(dispex); *disp = to_disp(dispex);
break; break;
case VT_ARRAY|VT_VARIANT: case JSV_VARIANT:
hres = create_vbarray(ctx, V_ARRAY(v), &dispex); switch(V_VT(get_variant(val))) {
if(FAILED(hres)) case VT_ARRAY|VT_VARIANT:
return hres; 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; break;
default: default:
FIXME("unsupported vt %d\n", V_VT(v)); FIXME("unsupported %s\n", debugstr_jsval(val));
return E_NOTIMPL; return E_NOTIMPL;
} }
return S_OK; 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) HRESULT variant_change_type(script_ctx_t *ctx, VARIANT *dst, VARIANT *src, VARTYPE vt)
{ {
jsexcept_t ei; jsexcept_t ei;

View File

@ -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]))) { if(!is_undefined(argv[0]) && !is_null(argv[0]) && (!is_object_instance(argv[0]) || get_object(argv[0]))) {
IDispatch *disp; IDispatch *disp;
hres = to_object_jsval(ctx, argv[0], &disp); hres = to_object(ctx, argv[0], &disp);
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;