Skip to content

Commit

Permalink
jscript: Implement Function.prototype.bind's thisArg properly.
Browse files Browse the repository at this point in the history
Signed-off-by: Gabriel Ivăncescu <[email protected]>
  • Loading branch information
g-insn committed Aug 29, 2022
1 parent 994844d commit 77752f3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
16 changes: 7 additions & 9 deletions dlls/jscript/function.c
Original file line number Diff line number Diff line change
Expand Up @@ -605,18 +605,16 @@ static HRESULT Function_bind(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsig
return JS_E_FUNCTION_EXPECTED;

if(argc < 1) {
FIXME("no this argument\n");
return E_NOTIMPL;
}

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;
argc = 1;
}else if(!is_undefined(argv[0]) && !is_null(argv[0])) {
hres = to_object(ctx, argv[0], &bound_this);
if(FAILED(hres))
return hres;
}

hres = create_bind_function(ctx, function, bound_this, argc - 1, argv + 1, &new_function);
if(bound_this)
IDispatch_Release(bound_this);
if(FAILED(hres))
return hres;

Expand Down
8 changes: 8 additions & 0 deletions dlls/mshtml/tests/es5.js
Original file line number Diff line number Diff line change
Expand Up @@ -1209,6 +1209,14 @@ sync_test("bind", function() {
ok(t != a, "t == a");

ok(Function.prototype.bind.length === 1, "Function.prototype.bind.length = " + Function.prototype.bind.length);

((function() { ok(this === window, "bind() this = " + this); }).bind())();
((function() { ok(this === window, "bind(undefined) = " + this); }).bind(undefined))();
((function() { ok(this === window, "bind(nullDisp) = " + this); }).bind(external.nullDisp))();
((function() {
ok(typeof(this) === "object", "bind(42) typeof(this) = " + typeof(this));
ok(this.valueOf() === 42, "bind(42) this = " + this);
}).bind(42))();
});

sync_test("keys", function() {
Expand Down

0 comments on commit 77752f3

Please sign in to comment.