- Revision
- 200423
- Author
- [email protected]
- Date
- 2016-05-04 12:23:41 -0700 (Wed, 04 May 2016)
Log Message
ES6 Function.name inferred from property names of literal objects can break some websites.
https://bugs.webkit.org/show_bug.cgi?id=157246
Reviewed by Geoffrey Garen.
Source/_javascript_Core:
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.
Here are the 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 property name as inferred value of Function.name as specified by ES6):
/**
* 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 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.
Here's what we'll do:
1. Introduce a needsSiteSpecificQuirks flag in JSGlobalObject.
2. Have WebCore's JSDOMWindowBase set that flag if the browser's
needsSiteSpecificQuirks is enabled in its settings.
3. If needsSiteSpecificQuirks is enabled, have JSFunction::reifyName() check for
' ' or '|' in the name string it will use to reify the Function.name property.
If those characters exists in the name, we'll replace the name string with a
null string.
* runtime/JSFunction.cpp:
(JSC::JSFunction::reifyName):
* runtime/JSGlobalObject.h:
(JSC::JSGlobalObject::needsSiteSpecificQuirks):
(JSC::JSGlobalObject::GlobalPropertyInfo::GlobalPropertyInfo):
(JSC::JSGlobalObject::setNeedsSiteSpecificQuirks):
Source/WebCore:
Test: js/dom/regress-157246.html
* bindings/js/JSDOMWindowBase.cpp:
(WebCore::JSDOMWindowBase::finishCreation):
- Set the needsSiteSpecificQuirks flag in the JSGlobalObject if needed.
Tools:
* WebKitTestRunner/TestController.cpp:
(WTR::TestController::resetPreferencesToConsistentValues):
(WTR::updateTestOptionsFromTestHeader):
* WebKitTestRunner/TestOptions.h:
* WebKitTestRunner/ios/PlatformWebViewIOS.mm:
(WTR::PlatformWebView::viewSupportsOptions):
* WebKitTestRunner/mac/PlatformWebViewMac.mm:
(WTR::PlatformWebView::viewSupportsOptions):
- Add needsSiteSpecificQuirks to WKTR options that can be set.
LayoutTests:
* js/dom/regress-157246-expected.txt: Added.
* js/dom/regress-157246.html: Added.
* js/dom/script-tests/regress-157246.js: Added.
* platform/ios-simulator-wk1/TestExpectations:
* platform/mac-wk1/TestExpectations:
- Skip js/dom/regress-157246.html for wk1 because it relies on a WKTR feature to
enable the needsSiteSpecificQuirks settings before running the test.
Modified Paths
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (200422 => 200423)
--- trunk/LayoutTests/ChangeLog 2016-05-04 17:59:10 UTC (rev 200422)
+++ trunk/LayoutTests/ChangeLog 2016-05-04 19:23:41 UTC (rev 200423)
@@ -1,3 +1,19 @@
+2016-05-04 Mark Lam <[email protected]>
+
+ ES6 Function.name inferred from property names of literal objects can break some websites.
+ https://bugs.webkit.org/show_bug.cgi?id=157246
+
+ Reviewed by Geoffrey Garen.
+
+ * js/dom/regress-157246-expected.txt: Added.
+ * js/dom/regress-157246.html: Added.
+ * js/dom/script-tests/regress-157246.js: Added.
+
+ * platform/ios-simulator-wk1/TestExpectations:
+ * platform/mac-wk1/TestExpectations:
+ - Skip js/dom/regress-157246.html for wk1 because it relies on a WKTR feature to
+ enable the needsSiteSpecificQuirks settings before running the test.
+
2016-05-04 Keith Miller <[email protected]>
Speedup array iterators
Added: trunk/LayoutTests/js/dom/regress-157246-expected.txt (0 => 200423)
--- trunk/LayoutTests/js/dom/regress-157246-expected.txt (rev 0)
+++ trunk/LayoutTests/js/dom/regress-157246-expected.txt 2016-05-04 19:23:41 UTC (rev 200423)
@@ -0,0 +1,10 @@
+JSRegress/regress-157246
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS no exception thrown
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/js/dom/regress-157246.html (0 => 200423)
--- trunk/LayoutTests/js/dom/regress-157246.html (rev 0)
+++ trunk/LayoutTests/js/dom/regress-157246.html 2016-05-04 19:23:41 UTC (rev 200423)
@@ -0,0 +1,14 @@
+<!-- webkit-test-runner [ needsSiteSpecificQuirks=true ] -->
+<!-- This test relies on a settings option that we can only set when run with WKRT. -->
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<script src=""
+<script src=""
+<script src=""
+<script src=""
+</body>
+</html>
Added: trunk/LayoutTests/js/dom/script-tests/regress-157246.js (0 => 200423)
--- trunk/LayoutTests/js/dom/script-tests/regress-157246.js (rev 0)
+++ trunk/LayoutTests/js/dom/script-tests/regress-157246.js 2016-05-04 19:23:41 UTC (rev 200423)
@@ -0,0 +1,25 @@
+// Regression test for https://bugs.webkit.org/show_bug.cgi?id=157246.
+// Needs the browser needsSiteSpecificQuirks settings flag to be set in order to pass.
+
+function assert(result) {
+ if (!result)
+ throw new Error("Unexpected result");
+}
+
+function makeObj(propName) {
+ var o = {
+ [propName]: function () { }, // accessed via get_by_val
+ 'c | d': function() { } // accessed via get_by_id
+ }
+ return o;
+}
+
+function test(obj) {
+ for (let prop in obj) {
+ let bodyStr = "return function " + obj[prop].name + "() { return 5; }";
+ let func = new Function(bodyStr);
+ assert(func()() === 5);
+ }
+}
+
+test(makeObj('a | b'));
Modified: trunk/LayoutTests/platform/ios-simulator-wk1/TestExpectations (200422 => 200423)
--- trunk/LayoutTests/platform/ios-simulator-wk1/TestExpectations 2016-05-04 17:59:10 UTC (rev 200422)
+++ trunk/LayoutTests/platform/ios-simulator-wk1/TestExpectations 2016-05-04 19:23:41 UTC (rev 200423)
@@ -1359,3 +1359,6 @@
webkit.org/b/156069 http/tests/security/anchor-download-block-crossorigin.html [ Skip ]
webkit.org/b/137572 scrollbars/scrollbar-iframe-click-does-not-blur-content.html [ Failure ]
+
+# This test relies on a settings option that we can only set with WKRT.
+js/dom/regress-157246.html
Modified: trunk/LayoutTests/platform/mac-wk1/TestExpectations (200422 => 200423)
--- trunk/LayoutTests/platform/mac-wk1/TestExpectations 2016-05-04 17:59:10 UTC (rev 200422)
+++ trunk/LayoutTests/platform/mac-wk1/TestExpectations 2016-05-04 19:23:41 UTC (rev 200423)
@@ -213,3 +213,6 @@
webkit.org/b/156629 imported/w3c/web-platform-tests/html/semantics/embedded-content/the-img-element/sizes/parse-a-sizes-attribute.html [ Pass Failure ]
webkit.org/b/157007 fast/layers/no-clipping-overflow-hidden-added-after-transform.html [ Pass ImageOnlyFailure ]
+
+# This test relies on a settings option that we can only set with WKRT.
+js/dom/regress-157246.html
Modified: trunk/Source/_javascript_Core/ChangeLog (200422 => 200423)
--- trunk/Source/_javascript_Core/ChangeLog 2016-05-04 17:59:10 UTC (rev 200422)
+++ trunk/Source/_javascript_Core/ChangeLog 2016-05-04 19:23:41 UTC (rev 200423)
@@ -1,3 +1,98 @@
+2016-05-04 Mark Lam <[email protected]>
+
+ ES6 Function.name inferred from property names of literal objects can break some websites.
+ https://bugs.webkit.org/show_bug.cgi?id=157246
+
+ Reviewed by Geoffrey Garen.
+
+ 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.
+
+ Here are the 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 property name as inferred value of Function.name as specified by ES6):
+
+ /**
+ * 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 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.
+
+ Here's what we'll do:
+ 1. Introduce a needsSiteSpecificQuirks flag in JSGlobalObject.
+ 2. Have WebCore's JSDOMWindowBase set that flag if the browser's
+ needsSiteSpecificQuirks is enabled in its settings.
+ 3. If needsSiteSpecificQuirks is enabled, have JSFunction::reifyName() check for
+ ' ' or '|' in the name string it will use to reify the Function.name property.
+ If those characters exists in the name, we'll replace the name string with a
+ null string.
+
+ * runtime/JSFunction.cpp:
+ (JSC::JSFunction::reifyName):
+ * runtime/JSGlobalObject.h:
+ (JSC::JSGlobalObject::needsSiteSpecificQuirks):
+ (JSC::JSGlobalObject::GlobalPropertyInfo::GlobalPropertyInfo):
+ (JSC::JSGlobalObject::setNeedsSiteSpecificQuirks):
+
2016-05-04 Keith Miller <[email protected]>
Speedup array iterators
Modified: trunk/Source/_javascript_Core/runtime/JSFunction.cpp (200422 => 200423)
--- trunk/Source/_javascript_Core/runtime/JSFunction.cpp 2016-05-04 17:59:10 UTC (rev 200422)
+++ trunk/Source/_javascript_Core/runtime/JSFunction.cpp 2016-05-04 19:23:41 UTC (rev 200423)
@@ -631,6 +631,14 @@
unsigned initialAttributes = DontEnum | ReadOnly;
const Identifier& propID = exec->propertyNames().name;
+ if (exec->lexicalGlobalObject()->needsSiteSpecificQuirks()) {
+ auto illegalCharMatcher = [] (UChar ch) -> bool {
+ return ch == ' ' || ch == '|';
+ };
+ if (name.find(illegalCharMatcher) != notFound)
+ name = String();
+ }
+
if (jsExecutable()->isGetter())
name = makeString("get ", name);
else if (jsExecutable()->isSetter())
Modified: trunk/Source/_javascript_Core/runtime/JSGlobalObject.h (200422 => 200423)
--- trunk/Source/_javascript_Core/runtime/JSGlobalObject.h 2016-05-04 17:59:10 UTC (rev 200422)
+++ trunk/Source/_javascript_Core/runtime/JSGlobalObject.h 2016-05-04 19:23:41 UTC (rev 200423)
@@ -717,6 +717,8 @@
UnlinkedEvalCodeBlock* createEvalCodeBlock(CallFrame*, EvalExecutable*, ThisTDZMode, const VariableEnvironment*);
UnlinkedModuleProgramCodeBlock* createModuleProgramCodeBlock(CallFrame*, ModuleProgramExecutable*);
+ bool needsSiteSpecificQuirks() const { return m_needsSiteSpecificQuirks; }
+
protected:
struct GlobalPropertyInfo {
GlobalPropertyInfo(const Identifier& i, JSValue v, unsigned a)
@@ -734,6 +736,8 @@
JS_EXPORT_PRIVATE static JSC::JSValue toThis(JSC::JSCell*, JSC::ExecState*, ECMAMode);
+ void setNeedsSiteSpecificQuirks(bool needQuirks) { m_needsSiteSpecificQuirks = needQuirks; }
+
private:
friend class LLIntOffsetsExtractor;
@@ -745,6 +749,8 @@
void createThrowTypeErrorArgumentsAndCaller(VM&);
JS_EXPORT_PRIVATE static void clearRareData(JSCell*);
+
+ bool m_needsSiteSpecificQuirks { false };
};
JSGlobalObject* asGlobalObject(JSValue);
Modified: trunk/Source/WebCore/ChangeLog (200422 => 200423)
--- trunk/Source/WebCore/ChangeLog 2016-05-04 17:59:10 UTC (rev 200422)
+++ trunk/Source/WebCore/ChangeLog 2016-05-04 19:23:41 UTC (rev 200423)
@@ -1,3 +1,16 @@
+2016-05-04 Mark Lam <[email protected]>
+
+ ES6 Function.name inferred from property names of literal objects can break some websites.
+ https://bugs.webkit.org/show_bug.cgi?id=157246
+
+ Reviewed by Geoffrey Garen.
+
+ Test: js/dom/regress-157246.html
+
+ * bindings/js/JSDOMWindowBase.cpp:
+ (WebCore::JSDOMWindowBase::finishCreation):
+ - Set the needsSiteSpecificQuirks flag in the JSGlobalObject if needed.
+
2016-05-04 Konstantin Tokarev <[email protected]>
Deduplicated initializer lists of BitmapImage constructors.
Modified: trunk/Source/WebCore/bindings/js/JSDOMWindowBase.cpp (200422 => 200423)
--- trunk/Source/WebCore/bindings/js/JSDOMWindowBase.cpp 2016-05-04 17:59:10 UTC (rev 200422)
+++ trunk/Source/WebCore/bindings/js/JSDOMWindowBase.cpp 2016-05-04 19:23:41 UTC (rev 200423)
@@ -85,6 +85,9 @@
};
addStaticGlobals(staticGlobals, WTF_ARRAY_LENGTH(staticGlobals));
+
+ if (m_wrapped && m_wrapped->frame() && m_wrapped->frame()->settings().needsSiteSpecificQuirks())
+ setNeedsSiteSpecificQuirks(true);
}
void JSDOMWindowBase::visitChildren(JSCell* cell, SlotVisitor& visitor)
Modified: trunk/Tools/ChangeLog (200422 => 200423)
--- trunk/Tools/ChangeLog 2016-05-04 17:59:10 UTC (rev 200422)
+++ trunk/Tools/ChangeLog 2016-05-04 19:23:41 UTC (rev 200423)
@@ -1,3 +1,21 @@
+2016-05-04 Mark Lam <[email protected]>
+
+ ES6 Function.name inferred from property names of literal objects can break some websites.
+ https://bugs.webkit.org/show_bug.cgi?id=157246
+
+ Reviewed by Geoffrey Garen.
+
+ * WebKitTestRunner/TestController.cpp:
+ (WTR::TestController::resetPreferencesToConsistentValues):
+ (WTR::updateTestOptionsFromTestHeader):
+ * WebKitTestRunner/TestOptions.h:
+
+ * WebKitTestRunner/ios/PlatformWebViewIOS.mm:
+ (WTR::PlatformWebView::viewSupportsOptions):
+ * WebKitTestRunner/mac/PlatformWebViewMac.mm:
+ (WTR::PlatformWebView::viewSupportsOptions):
+ - Add needsSiteSpecificQuirks to WKTR options that can be set.
+
2016-05-04 Joanmarie Diggs <[email protected]>
AX: ARIA 'region' role is now a landmark; HTML 'section' element should be a landmark only if named
Modified: trunk/Tools/WebKitTestRunner/TestController.cpp (200422 => 200423)
--- trunk/Tools/WebKitTestRunner/TestController.cpp 2016-05-04 17:59:10 UTC (rev 200422)
+++ trunk/Tools/WebKitTestRunner/TestController.cpp 2016-05-04 19:23:41 UTC (rev 200423)
@@ -666,6 +666,7 @@
WKPreferencesSetTabToLinksEnabled(preferences, false);
WKPreferencesSetInteractiveFormValidationEnabled(preferences, true);
WKPreferencesSetMockScrollbarsEnabled(preferences, options.useMockScrollbars);
+ WKPreferencesSetNeedsSiteSpecificQuirks(preferences, options.needsSiteSpecificQuirks);
static WKStringRef defaultTextEncoding = WKStringCreateWithUTF8CString("ISO-8859-1");
WKPreferencesSetDefaultTextEncodingName(preferences, defaultTextEncoding);
@@ -955,6 +956,8 @@
testOptions.useDataDetection = parseBooleanTestHeaderValue(value);
if (key == "useMockScrollbars")
testOptions.useMockScrollbars = parseBooleanTestHeaderValue(value);
+ if (key == "needsSiteSpecificQuirks")
+ testOptions.needsSiteSpecificQuirks = parseBooleanTestHeaderValue(value);
pairStart = pairEnd + 1;
}
}
Modified: trunk/Tools/WebKitTestRunner/TestOptions.h (200422 => 200423)
--- trunk/Tools/WebKitTestRunner/TestOptions.h 2016-05-04 17:59:10 UTC (rev 200422)
+++ trunk/Tools/WebKitTestRunner/TestOptions.h 2016-05-04 19:23:41 UTC (rev 200423)
@@ -41,6 +41,7 @@
bool isHiDPITest { false };
bool useDataDetection { false };
bool useMockScrollbars { true };
+ bool needsSiteSpecificQuirks { false };
Vector<String> overrideLanguages;
Modified: trunk/Tools/WebKitTestRunner/ios/PlatformWebViewIOS.mm (200422 => 200423)
--- trunk/Tools/WebKitTestRunner/ios/PlatformWebViewIOS.mm 2016-05-04 17:59:10 UTC (rev 200422)
+++ trunk/Tools/WebKitTestRunner/ios/PlatformWebViewIOS.mm 2016-05-04 19:23:41 UTC (rev 200423)
@@ -212,7 +212,7 @@
bool PlatformWebView::viewSupportsOptions(const TestOptions& options) const
{
- if (m_options.overrideLanguages != options.overrideLanguages)
+ if (m_options.overrideLanguages != options.overrideLanguages || m_options.needsSiteSpecificQuirks != options.needsSiteSpecificQuirks)
return false;
return true;
Modified: trunk/Tools/WebKitTestRunner/mac/PlatformWebViewMac.mm (200422 => 200423)
--- trunk/Tools/WebKitTestRunner/mac/PlatformWebViewMac.mm 2016-05-04 17:59:10 UTC (rev 200422)
+++ trunk/Tools/WebKitTestRunner/mac/PlatformWebViewMac.mm 2016-05-04 19:23:41 UTC (rev 200423)
@@ -233,7 +233,7 @@
bool PlatformWebView::viewSupportsOptions(const TestOptions& options) const
{
- if (m_options.useThreadedScrolling != options.useThreadedScrolling || m_options.overrideLanguages != options.overrideLanguages || m_options.useMockScrollbars != options.useMockScrollbars)
+ if (m_options.useThreadedScrolling != options.useThreadedScrolling || m_options.overrideLanguages != options.overrideLanguages || m_options.useMockScrollbars != options.useMockScrollbars || m_options.needsSiteSpecificQuirks != options.needsSiteSpecificQuirks)
return false;
return true;