RESOLVED FIXED 157246
ES6 Function.name inferred from property names of literal objects can break some websites
https://bugs.webkit.org/show_bug.cgi?id=157246
Summary ES6 Function.name inferred from property names of literal objects can break s...
Mark Lam
Reported 2016-05-01 08:42:04 PDT
Specifically, the library mathjs (see http://mathjs.org and https://github.com/josdejong/mathjs) uses an idiom where it created literal objects with property names that look like this: 'number | BigNumber | Unit'. Later, this name is used in a string to create function source code that gets eval'ed. Since 'number | BigNumber | Unit' is not a valid function name, we get a syntax error. The nitty gritty details: 1. mathjs uses object literals with the funky property names for its function members. For example, // helper function to type check the middle value of the array var middle = typed({ 'number | BigNumber | Unit': function (value) { return value; } }); 2. mathjs' getName() uses Function.name to get the name of functions (hence, picks up the ES6 behavior): /** * Retrieve the function name from a set of functions, and check * whether the name of all functions match (if given) ... */ function getName (fns) { var name = ''; for (var i = 0; i < fns.length; i++) { var fn = fns[i]; ... name = fn.name; ... return name; } 3. mathjs uses that name to assembler new function source code that gets eval'ed: /** * Compose a function from sub-functions each handling a single type signature. ... */ function _typed(name, signatures) { ... // generate code for the typed function var code = []; var _name = name || ''; ... code.push('function ' + _name + '(' + _args.join(', ') + ') {'); code.push(' "use strict";'); code.push(' var name = \'' + _name + '\';'); code.push(node.toCode(refs, ' ')); code.push('}'); // generate body for the factory function var body = [ refs.toCode(), 'return ' + code.join('\n') ].join('\n'); // evaluate the JavaScript code and attach function references var factory = (new Function(refs.name, 'createError', body)); // <========= Syntax Error right here! var fn = factory(refs, createError); ... return fn; } Until mathjs (and any other frameworks that does similar things) and sites that uses mathjs has been updated to work with ES6, we'll need a compatibility hack to work around it.
Attachments
proposed patch. (17.60 KB, patch)
2016-05-03 10:16 PDT, Mark Lam
buildbot: commit-queue-
Archive of layout-test-results from ews122 for ios-simulator-wk2 (658.18 KB, application/zip)
2016-05-03 11:32 PDT, Build Bot
no flags
proposed patch: fixed iOS sim EWS sadness (16.41 KB, patch)
2016-05-03 16:21 PDT, Mark Lam
ggaren: review+
Mark Lam
Comment 1 2016-05-01 08:42:36 PDT
Mark Lam
Comment 2 2016-05-03 10:16:08 PDT
Created attachment 278008 [details] proposed patch. Still need to run tests.
Mark Lam
Comment 3 2016-05-03 10:55:50 PDT
The mac and mac-wk2 EWS' fast/workers/worker-replace-self.html failure is not due to this patch (pre-existing). The ios-sim EWS' js/dom/regress-157246.html failure is interesting. I'll investigate.
Build Bot
Comment 4 2016-05-03 11:32:42 PDT
Comment on attachment 278008 [details] proposed patch. Attachment 278008 [details] did not pass ios-sim-ews (ios-simulator-wk2): Output: http://webkit-queues.webkit.org/results/1261770 New failing tests: js/dom/regress-157246.html
Build Bot
Comment 5 2016-05-03 11:32:47 PDT
Created attachment 278010 [details] Archive of layout-test-results from ews122 for ios-simulator-wk2 The attached test failures were seen while running run-webkit-tests on the ios-sim-ews. Bot: ews122 Port: ios-simulator-wk2 Platform: Mac OS X 10.11.4
Mark Lam
Comment 6 2016-05-03 16:21:06 PDT
Created attachment 278043 [details] proposed patch: fixed iOS sim EWS sadness
WebKit Commit Bot
Comment 7 2016-05-03 17:44:33 PDT
Attachment 278043 [details] did not pass style-queue: WARNING: Not running on native Windows. ERROR: Source/JavaScriptCore/ChangeLog:30: Need whitespace between colon and description [changelog/filechangedescriptionwhitespace] [5] ERROR: Source/JavaScriptCore/ChangeLog:31: Need whitespace between colon and description [changelog/filechangedescriptionwhitespace] [5] ERROR: Source/JavaScriptCore/ChangeLog:48: Need whitespace between colon and description [changelog/filechangedescriptionwhitespace] [5] Total errors found: 3 in 16 files If any of these errors are false positives, please file a bug against check-webkit-style.
Geoffrey Garen
Comment 8 2016-05-04 12:14:55 PDT
Comment on attachment 278043 [details] proposed patch: fixed iOS sim EWS sadness r=me
Mark Lam
Comment 9 2016-05-04 12:23:48 PDT
Thanks for the review. Landed in r200423: <http://trac.webkit.org/r200423>.
Note You need to log in before you can comment on or make changes to this bug.