Module: wine Branch: master Commit: edd4316492f05e42b72473a3a2a4948d62e40e3d URL: https://source.winehq.org/git/wine.git/?a=commit;h=edd4316492f05e42b72473a3a...
Author: Jacek Caban jacek@codeweavers.com Date: Tue Apr 21 17:43:46 2020 +0200
jscript: Support null this in Function.prototype.bind.
Signed-off-by: Jacek Caban jacek@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
dlls/jscript/function.c | 13 +++++++++---- dlls/mshtml/tests/es5.js | 3 +++ 2 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/dlls/jscript/function.c b/dlls/jscript/function.c index caca274a49..e43d19464b 100644 --- a/dlls/jscript/function.c +++ b/dlls/jscript/function.c @@ -439,6 +439,7 @@ static HRESULT Function_call(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, uns static HRESULT Function_bind(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r) { + IDispatch *bound_this = NULL; FunctionInstance *function; jsdisp_t *new_function; HRESULT hres; @@ -453,12 +454,14 @@ static HRESULT Function_bind(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, uns return E_NOTIMPL; }
- if(!is_object_instance(argv[0]) || !get_object(argv[0])) { + if(is_object_instance(argv[0])) { + bound_this = get_object(argv[0]); + }else if(!is_null(argv[0])) { FIXME("%s is not an object instance\n", debugstr_jsval(argv[0])); return E_NOTIMPL; }
- hres = create_bind_function(ctx, function, get_object(argv[0]), argc - 1, argv + 1, &new_function); + hres = create_bind_function(ctx, function, bound_this, argc - 1, argv + 1, &new_function); if(FAILED(hres)) return hres;
@@ -875,7 +878,8 @@ static void BindFunction_destructor(FunctionInstance *func) for(i = 0; i < function->argc; i++) jsval_release(function->args[i]); jsdisp_release(&function->target->dispex); - IDispatch_Release(function->this); + if(function->this) + IDispatch_Release(function->this); }
static const function_vtbl_t BindFunctionVtbl = { @@ -899,7 +903,8 @@ static HRESULT create_bind_function(script_ctx_t *ctx, FunctionInstance *target, jsdisp_addref(&target->dispex); function->target = target;
- IDispatch_AddRef(function->this = bound_this); + if(bound_this) + IDispatch_AddRef(function->this = bound_this);
for(function->argc = 0; function->argc < argc; function->argc++) { hres = jsval_copy(argv[function->argc], function->args + function->argc); diff --git a/dlls/mshtml/tests/es5.js b/dlls/mshtml/tests/es5.js index 6b5d04a959..a24f61fcd5 100644 --- a/dlls/mshtml/tests/es5.js +++ b/dlls/mshtml/tests/es5.js @@ -862,6 +862,9 @@ function test_bind() { f = (function() { return this; }).bind(a); ok(f() === a, "f() != a");
+ f = (function() { return this; }).bind(null); + ok(f() === window, "f() = " + f()); + var t; f = (function() { return t = this; }).bind(a); ok(new f() === t, "new f() != a");