Bug 125501 - `Function.prototype.apply` & `Function.prototype.call` with `undefined` or `null` as `thisArg`
Summary: `Function.prototype.apply` & `Function.prototype.call` with `undefined` or `n...
Status: RESOLVED INVALID
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL: data:text/html,<script>function foo()...
Keywords:
Depends on:
Blocks:
 
Reported: 2013-12-10 05:16 PST by Mathias Bynens
Modified: 2013-12-10 05:30 PST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mathias Bynens 2013-12-10 05:16:57 PST
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 :)
Comment 1 Mathias Bynens 2013-12-10 05:30:02 PST
This is a bug in the spec: https://bugs.ecmascript.org/show_bug.cgi?id=2370