Bug 151365 - Problem with ES6 class definition inside of function definition
Summary: Problem with ES6 class definition inside of function definition
Status: RESOLVED DUPLICATE of bug 142567
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: Safari 9
Hardware: Macintosh OS X 10.10
: P2 Normal
Assignee: Nobody
Depends on:
Blocks: 140491
  Show dependency treegraph
Reported: 2015-11-17 15:25 PST by Dan Bornstein
Modified: 2016-05-05 22:28 PDT (History)
3 users (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Dan Bornstein 2015-11-17 15:25:31 PST
When using the ES6 class definition syntax in the scope of a function, it looks like static definitions might not quite work. I am not 100% sure what the exact trigger is, but I do have a case right now that consistently fails.

Steps to Reproduce:
1. Open Safari.
2. Visit <http://milk.com/mimu/awkward-js-music/>.

Expected Results:
Embedded canvases should be rendered, and "play / pause" button should work.

Actual Results:
Message to console: "ReferenceError: Can't find variable: StyleUtil -- cloneComputedStyle -- StyleUtil.js:39"

Notably, the line that is being complained about is within the definition of the class StyleUtil. Given that cloneComputedStyle does exist in that class, the lookup should not ever fail.

I'm continuing development of the code. Here's a snapshot of the source as of this report: <https://github.com/danfuzz/mimu/tree/6042dc4014211eed2ba75354e5ed5361b998f07a>

Three items of note:

* This bug showed up after I wrapped the definition of the class in a function definition (as part of a conversion to RequireJS).
* The code as currently written works in Chrome. It doesn't work in FireFox in that FireFox doesn't do the ES6 class syntax at all yet (at least not in the release build).
* If you clone the source locally and view the index.html file in Safari, then *sometimes* the bug will show up, and sometimes the page will operate properly.
Comment 1 Dan Bornstein 2015-11-17 15:28:58 PST
Here's the version of StyleUtil.js in question: <https://github.com/danfuzz/mimu/blob/6042dc4014211eed2ba75354e5ed5361b998f07a/lib/StyleUtil.js>
Comment 2 Joseph Pecoraro 2016-05-05 22:28:23 PDT
Looks like this works now in trunk (and Safari Technology Preview / WebKit Nightly if you want to verify).

I believe this was the Class Name Scope change, since it looks like that is what was on line 39 (accessing the Class's Name from inside the class's block). Though I think that was, maybe you had tested in Safari and not a WebKit Nightly at the time.

    ES6 class syntax should use block scoping

*** This bug has been marked as a duplicate of bug 142567 ***