[Webkit-unassigned] [Bug 125501] New: `Function.prototype.apply` & `Function.prototype.call` with `undefined` or `null` as `thisArg`

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Tue Dec 10 05:18:43 PST 2013


https://bugs.webkit.org/show_bug.cgi?id=125501

           Summary: `Function.prototype.apply` & `Function.prototype.call`
                    with `undefined` or `null` as `thisArg`
           Product: WebKit
           Version: 528+ (Nightly build)
          Platform: Unspecified
               URL: data:text/html,<script>function foo() {
                    console.log(this); return this; };
                    document.write(foo.call(undefined) === undefined %3F
                    'PASS' %3A 'FAIL');</script>
        OS/Version: Unspecified
            Status: NEW
          Severity: Normal
          Priority: P2
         Component: JavaScriptCore
        AssignedTo: webkit-unassigned at lists.webkit.org
        ReportedBy: mathias at qiwi.be


>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 :)

-- 
Configure bugmail: https://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.


More information about the webkit-unassigned mailing list