jscript: Support null this in Function.prototype.bind.
Signed-off-by: Jacek Caban <jacek@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
3af3375b97
commit
edd4316492
|
@ -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,
|
static HRESULT Function_bind(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
||||||
jsval_t *r)
|
jsval_t *r)
|
||||||
{
|
{
|
||||||
|
IDispatch *bound_this = NULL;
|
||||||
FunctionInstance *function;
|
FunctionInstance *function;
|
||||||
jsdisp_t *new_function;
|
jsdisp_t *new_function;
|
||||||
HRESULT hres;
|
HRESULT hres;
|
||||||
|
@ -453,12 +454,14 @@ static HRESULT Function_bind(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, uns
|
||||||
return E_NOTIMPL;
|
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]));
|
FIXME("%s is not an object instance\n", debugstr_jsval(argv[0]));
|
||||||
return E_NOTIMPL;
|
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))
|
if(FAILED(hres))
|
||||||
return hres;
|
return hres;
|
||||||
|
|
||||||
|
@ -875,6 +878,7 @@ static void BindFunction_destructor(FunctionInstance *func)
|
||||||
for(i = 0; i < function->argc; i++)
|
for(i = 0; i < function->argc; i++)
|
||||||
jsval_release(function->args[i]);
|
jsval_release(function->args[i]);
|
||||||
jsdisp_release(&function->target->dispex);
|
jsdisp_release(&function->target->dispex);
|
||||||
|
if(function->this)
|
||||||
IDispatch_Release(function->this);
|
IDispatch_Release(function->this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -899,6 +903,7 @@ static HRESULT create_bind_function(script_ctx_t *ctx, FunctionInstance *target,
|
||||||
jsdisp_addref(&target->dispex);
|
jsdisp_addref(&target->dispex);
|
||||||
function->target = target;
|
function->target = target;
|
||||||
|
|
||||||
|
if(bound_this)
|
||||||
IDispatch_AddRef(function->this = bound_this);
|
IDispatch_AddRef(function->this = bound_this);
|
||||||
|
|
||||||
for(function->argc = 0; function->argc < argc; function->argc++) {
|
for(function->argc = 0; function->argc < argc; function->argc++) {
|
||||||
|
|
|
@ -862,6 +862,9 @@ function test_bind() {
|
||||||
f = (function() { return this; }).bind(a);
|
f = (function() { return this; }).bind(a);
|
||||||
ok(f() === a, "f() != a");
|
ok(f() === a, "f() != a");
|
||||||
|
|
||||||
|
f = (function() { return this; }).bind(null);
|
||||||
|
ok(f() === window, "f() = " + f());
|
||||||
|
|
||||||
var t;
|
var t;
|
||||||
f = (function() { return t = this; }).bind(a);
|
f = (function() { return t = this; }).bind(a);
|
||||||
ok(new f() === t, "new f() != a");
|
ok(new f() === t, "new f() != a");
|
||||||
|
|
Loading…
Reference in New Issue