[Webkit-unassigned] [Bug 141184] New: Function declaration inside a function and using the same name as an argument to the containing function no longer takes precedence over the argument

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Mon Feb 2 19:05:33 PST 2015


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

            Bug ID: 141184
           Summary: Function declaration inside a function and using the
                    same name as an argument to the containing function no
                    longer takes precedence over the argument
    Classification: Unclassified
           Product: WebKit
           Version: 528+ (Nightly build)
          Hardware: Unspecified
                OS: Mac OS X 10.10
            Status: NEW
          Severity: Normal
          Priority: P2
         Component: JavaScriptCore
          Assignee: webkit-unassigned at lists.webkit.org
          Reporter: rob at robbrackett.com

Using the latest WebKit Nightly (r179474), I ran into a problem using code like the following:

```
(function(Thing) {
    Thing.whatever = "This breaks.";
    function Thing() {
        return this;
    }
})()
```

An exception is thrown on line 2 above, when trying to assign to `Thing.whatever`. The exception is “TypeError: undefined is not an object (evaluating 'Thing.whatever = "This breaks."')“ It seems that, on line 2, `Thing` evaluates to the first argument of the containing function (which is undefined) instead of the function defined in line 3. This differs from the currently shipping version of Safari, where `Thing` on line 2 evaluates to the function declaration instead of to `undefined`.

A quick perusal of section “10.5 Declaration Binding Instantiation” in the ECMA-262 spec _seems_ like the new behavior is correct, though I’m honestly not sure I’m reading it right. However, this behavior differs from previous builds of JSC and from many other JS engines (V8, Spidermonkey). It also breaks code existing in the wild — I encountered this while browsing a site built using Instapaper’s web app (http://instapaper.com), which I believe is using Browserify, which creates code like the above example.

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20150203/28b3a6b5/attachment-0002.html>


More information about the webkit-unassigned mailing list