Bug 125501
Summary: | `Function.prototype.apply` & `Function.prototype.call` with `undefined` or `null` as `thisArg` | ||
---|---|---|---|
Product: | WebKit | Reporter: | Mathias Bynens <mathias> |
Component: | JavaScriptCore | Assignee: | Nobody <webkit-unassigned> |
Status: | RESOLVED INVALID | ||
Severity: | Normal | CC: | mathias |
Priority: | P2 | ||
Version: | 528+ (Nightly build) | ||
Hardware: | Unspecified | ||
OS: | Unspecified | ||
URL: | data:text/html,<script>function foo() { console.log(this); return this; }; document.write(foo.call(undefined) === undefined %3F 'PASS' %3A 'FAIL');</script> |
Mathias Bynens
From <http://ecma-international.org/ecma-262/5.1/#sec-15.3.4.3> and <http://ecma-international.org/ecma-262/5.1/#sec-15.3.4.4>:
The `thisArg` value is passed without modification as the `this` value. This is a change from Edition 3, where a `undefined` or `null` `thisArg` is replaced with the global object and `ToObject` is applied to all other values and that result is passed as the `this` value.
It seems like modern engines still have the ES3 behavior:
function foo() {
console.log(this);
return this;
};
foo.call(undefined) === undefined; // `false`, expected `true`
I’ve tested this in Spidermonkey/Firefox, Carakan/PrestOpera, JSC/Safari, and v8/Chrome. They all show FAIL in this test case:
data:text/html,<script>function foo() { console.log(this); return this; }; document.write(foo.call(undefined) === undefined %3F 'PASS' %3A 'FAIL');</script>
Is this…
1. a wilful violation of the ES5 spec for back-compat reasons, or…
2. is it just an oversight that this never got implemented, or…
3. am I misreading the spec?
If 2 is the case, please fix this :)
Attachments | ||
---|---|---|
Add attachment proposed patch, testcase, etc. |
Mathias Bynens
This is a bug in the spec: https://bugs.ecmascript.org/show_bug.cgi?id=2370