Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com --- dlls/jscript/function.c | 57 ++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 26 deletions(-)
diff --git a/dlls/jscript/function.c b/dlls/jscript/function.c index 43f2441..80b8d9c 100644 --- a/dlls/jscript/function.c +++ b/dlls/jscript/function.c @@ -35,7 +35,7 @@ typedef struct { } FunctionInstance;
struct _function_vtbl_t { - HRESULT (*call)(script_ctx_t*,FunctionInstance*,IDispatch*,unsigned,unsigned,jsval_t*,jsval_t*); + HRESULT (*call)(script_ctx_t*,FunctionInstance*,jsval_t,unsigned,unsigned,jsval_t*,jsval_t*); HRESULT (*toString)(FunctionInstance*,jsstr_t**); function_code_t* (*get_code)(FunctionInstance*); void (*destructor)(FunctionInstance*); @@ -256,7 +256,7 @@ HRESULT Function_invoke(jsdisp_t *func_this, IDispatch *jsthis, WORD flags, unsi assert(is_class(func_this, JSCLASS_FUNCTION)); function = function_from_jsdisp(func_this);
- return function->vtbl->call(function->dispex.ctx, function, jsthis, flags, argc, argv, r); + return function->vtbl->call(function->dispex.ctx, function, jsval_disp(jsthis), flags, argc, argv, r); }
static HRESULT Function_get_length(script_ctx_t *ctx, jsdisp_t *jsthis, jsval_t *r) @@ -331,8 +331,8 @@ static HRESULT Function_apply(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsi FunctionInstance *function; jsval_t *args = NULL; unsigned i, cnt = 0; - IDispatch *this_obj = NULL; HRESULT hres = S_OK; + jsval_t this_val;
TRACE("\n");
@@ -341,11 +341,15 @@ static HRESULT Function_apply(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsi
if(argc) { if(!is_undefined(argv[0]) && !is_null(argv[0])) { + IDispatch *this_obj; hres = to_object(ctx, argv[0], &this_obj); if(FAILED(hres)) return hres; - } - } + this_val = jsval_disp(this_obj); + }else + this_val = argv[0]; + }else + this_val = jsval_undefined();
if(argc >= 2) { jsdisp_t *arg_array = NULL; @@ -370,10 +374,11 @@ static HRESULT Function_apply(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsi
if(SUCCEEDED(hres)) { if(function) { - hres = function->vtbl->call(ctx, function, this_obj, flags, cnt, args, r); + hres = function->vtbl->call(ctx, function, this_val, flags, cnt, args, r); }else { jsval_t res; - hres = disp_call_value(ctx, get_object(vthis), this_obj, DISPATCH_METHOD, cnt, args, &res); + hres = disp_call_value(ctx, get_object(vthis), is_object_instance(this_val) ? get_object(this_val) : NULL, + DISPATCH_METHOD, cnt, args, &res); if(SUCCEEDED(hres)) { if(r) *r = res; @@ -383,8 +388,7 @@ static HRESULT Function_apply(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsi } }
- if(this_obj) - IDispatch_Release(this_obj); + jsval_release(this_val); for(i=0; i < cnt; i++) jsval_release(args[i]); heap_free(args); @@ -395,8 +399,8 @@ static HRESULT Function_call(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsig jsval_t *r) { FunctionInstance *function; - IDispatch *this_obj = NULL; unsigned cnt = 0; + jsval_t this_val; HRESULT hres;
TRACE("\n"); @@ -406,18 +410,21 @@ static HRESULT Function_call(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsig
if(argc) { if(!is_undefined(argv[0]) && !is_null(argv[0])) { + IDispatch *this_obj; hres = to_object(ctx, argv[0], &this_obj); if(FAILED(hres)) return hres; - } + this_val = jsval_disp(this_obj); + }else + this_val = argv[0];
cnt = argc-1; - } + }else + this_val = jsval_undefined();
- hres = function->vtbl->call(ctx, function, this_obj, flags, cnt, argv + 1, r); + hres = function->vtbl->call(ctx, function, this_val, flags, cnt, argv + 1, r);
- if(this_obj) - IDispatch_Release(this_obj); + jsval_release(this_val); return hres; }
@@ -469,7 +476,7 @@ HRESULT Function_value(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned ar return E_FAIL; }
- return function->vtbl->call(ctx, function, NULL, flags, argc, argv, r); + return function->vtbl->call(ctx, function, vthis, flags, argc, argv, r); }
HRESULT Function_get_value(script_ctx_t *ctx, jsdisp_t *jsthis, jsval_t *r) @@ -590,16 +597,10 @@ static HRESULT create_function(script_ctx_t *ctx, const builtin_info_t *builtin_ return S_OK; }
-static HRESULT NativeFunction_call(script_ctx_t *ctx, FunctionInstance *func, IDispatch *this_disp, unsigned flags, +static HRESULT NativeFunction_call(script_ctx_t *ctx, FunctionInstance *func, jsval_t vthis, unsigned flags, unsigned argc, jsval_t *argv, jsval_t *r) { NativeFunction *function = (NativeFunction*)func; - jsval_t vthis; - - if(this_disp) - vthis = jsval_disp(this_disp); - else - vthis = jsval_null();
return function->proc(ctx, vthis, flags & ~DISPATCH_JSCRIPT_INTERNAL_MASK, argc, argv, r); } @@ -698,10 +699,11 @@ HRESULT create_builtin_constructor(script_ctx_t *ctx, builtin_invoke_t value_pro return S_OK; }
-static HRESULT InterpretedFunction_call(script_ctx_t *ctx, FunctionInstance *func, IDispatch *this_obj, unsigned flags, +static HRESULT InterpretedFunction_call(script_ctx_t *ctx, FunctionInstance *func, jsval_t vthis, unsigned flags, unsigned argc, jsval_t *argv, jsval_t *r) { InterpretedFunction *function = (InterpretedFunction*)func; + IDispatch *this_obj = NULL; jsdisp_t *new_obj = NULL; DWORD exec_flags = 0; HRESULT hres; @@ -718,6 +720,8 @@ static HRESULT InterpretedFunction_call(script_ctx_t *ctx, FunctionInstance *fun if(FAILED(hres)) return hres; this_obj = to_disp(new_obj); + }else if(is_object_instance(vthis)) { + this_obj = get_object(vthis); }
if(flags & DISPATCH_JSCRIPT_CALLEREXECSSOURCE) @@ -801,7 +805,7 @@ HRESULT create_source_function(script_ctx_t *ctx, bytecode_t *code, function_cod return S_OK; }
-static HRESULT BindFunction_call(script_ctx_t *ctx, FunctionInstance *func, IDispatch *this_obj, unsigned flags, +static HRESULT BindFunction_call(script_ctx_t *ctx, FunctionInstance *func, jsval_t vthis, unsigned flags, unsigned argc, jsval_t *argv, jsval_t *r) { BindFunction *function = (BindFunction*)func; @@ -823,7 +827,8 @@ static HRESULT BindFunction_call(script_ctx_t *ctx, FunctionInstance *func, IDis memcpy(call_args + function->argc, argv, argc * sizeof(*call_args)); }
- hres = function->target->vtbl->call(ctx, function->target, function->this, flags, call_argc, call_args, r); + hres = function->target->vtbl->call(ctx, function->target, jsval_disp(function->this), + flags, call_argc, call_args, r);
heap_free(call_args); return hres;