- Revision
- 189341
- Author
- [email protected]
- Date
- 2015-09-03 23:58:40 -0700 (Thu, 03 Sep 2015)
Log Message
[ES6] Implement ES6 arrow function syntax. Prototype of arrow function should be undefined
https://bugs.webkit.org/show_bug.cgi?id=147742
Source/_javascript_Core:
Patch by Aleksandr Skachkov <[email protected]> on 2015-09-03
Reviewed by Saam Barati.
Added correct support of prototype property for arrow function. Arrow function
doesn’t have own prototype property, so (() => {}).hasOwnProperty('prototype') === false.
Changes prevent from creation of 'prototype' property automatically during initialization
of arrow function and allow to assign & delete it later in js code.
* runtime/JSFunction.cpp:
(JSC::JSFunction::getOwnPropertySlot):
(JSC::JSFunction::deleteProperty):
* tests/stress/arrowfunction-prototype.js: Added.
LayoutTests:
Patch by Aleksandr Skachkov <[email protected]> on 2015-09-04
Reviewed by Saam Barati.
Added tests of prototype property for arrow function. Checks that arrow function does not have
prototype property after creating of it and check if it is possible to add/remove it later.
* js/arrowfunction-prototype-expected.txt: Added.
* js/arrowfunction-prototype.html: Added.
* js/script-tests/arrowfunction-prototype.js: Added.
Modified Paths
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (189340 => 189341)
--- trunk/LayoutTests/ChangeLog 2015-09-04 04:54:09 UTC (rev 189340)
+++ trunk/LayoutTests/ChangeLog 2015-09-04 06:58:40 UTC (rev 189341)
@@ -1,3 +1,17 @@
+2015-09-04 Aleksandr Skachkov <[email protected]>
+
+ [ES6] Implement ES6 arrow function syntax. Prototype of arrow function should be undefined
+ https://bugs.webkit.org/show_bug.cgi?id=147742
+
+ Reviewed by Saam Barati.
+
+ Added tests of prototype property for arrow function. Checks that arrow function does not have
+ prototype property after creating of it and check if it is possible to add/remove it later.
+
+ * js/arrowfunction-prototype-expected.txt: Added.
+ * js/arrowfunction-prototype.html: Added.
+ * js/script-tests/arrowfunction-prototype.js: Added.
+
2015-09-03 Chris Dumez <[email protected]>
Unreviewed, rebaseline http/tests/w3c/html/dom/dynamic-markup-insertion/opening-the-input-stream/007.html
Added: trunk/LayoutTests/js/arrowfunction-prototype-expected.txt (0 => 189341)
--- trunk/LayoutTests/js/arrowfunction-prototype-expected.txt (rev 0)
+++ trunk/LayoutTests/js/arrowfunction-prototype-expected.txt 2015-09-04 06:58:40 UTC (rev 189341)
@@ -0,0 +1,25 @@
+Tests for ES6 arrow function prototype property
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+() => {}
+PASS typeof af1.prototype is 'undefined'
+PASS af1.hasOwnProperty('prototype') is false
+(a) => {a + 1}
+PASS typeof af2.prototype is 'undefined'
+PASS af2.hasOwnProperty('prototype') is false
+(x) => x + 1
+PASS typeof af3.prototype is 'undefined'
+PASS af3.hasOwnProperty('prototype') is false
+af1.prototype = function (x) { return x + 1;}
+PASS typeof af1.prototype is 'function'
+PASS af1.prototype.toString() is 'function (x) { return x + 1;}'
+PASS af1.hasOwnProperty('prototype') is true
+delete af1.prototype
+PASS typeof af1.prototype is 'undefined'
+PASS af1.hasOwnProperty('prototype') is false
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/js/arrowfunction-prototype.html (0 => 189341)
--- trunk/LayoutTests/js/arrowfunction-prototype.html (rev 0)
+++ trunk/LayoutTests/js/arrowfunction-prototype.html 2015-09-04 06:58:40 UTC (rev 189341)
@@ -0,0 +1,10 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<script src=""
+<script src=""
+</body>
+</html>
Added: trunk/LayoutTests/js/script-tests/arrowfunction-prototype.js (0 => 189341)
--- trunk/LayoutTests/js/script-tests/arrowfunction-prototype.js (rev 0)
+++ trunk/LayoutTests/js/script-tests/arrowfunction-prototype.js 2015-09-04 06:58:40 UTC (rev 189341)
@@ -0,0 +1,36 @@
+// Inspired by mozilla tests
+description('Tests for ES6 arrow function prototype property');
+
+var af1 = () => {};
+
+debug('() => {}');
+shouldBe("typeof af1.prototype", "'undefined'");
+shouldBe("af1.hasOwnProperty('prototype')", "false");
+
+var af2 = (a) => {a + 1};
+
+debug('(a) => {a + 1}');
+shouldBe("typeof af2.prototype", "'undefined'");
+shouldBe("af2.hasOwnProperty('prototype')", "false");
+
+var af3 = (x) => x + 1;
+
+debug('(x) => x + 1');
+shouldBe("typeof af3.prototype", "'undefined'");
+shouldBe("af3.hasOwnProperty('prototype')", "false");
+
+
+af1.prototype = function (x) { return x + 1;};
+
+debug('af1.prototype = function (x) { return x + 1;}');
+shouldBe("typeof af1.prototype", "'function'");
+shouldBe("af1.prototype.toString()", "'function (x) { return x + 1;}'");
+shouldBe("af1.hasOwnProperty('prototype')", "true");
+
+delete af1.prototype;
+
+debug('delete af1.prototype');
+shouldBe("typeof af1.prototype", "'undefined'");
+shouldBe("af1.hasOwnProperty('prototype')", "false");
+
+var successfullyParsed = true;
Modified: trunk/Source/_javascript_Core/ChangeLog (189340 => 189341)
--- trunk/Source/_javascript_Core/ChangeLog 2015-09-04 04:54:09 UTC (rev 189340)
+++ trunk/Source/_javascript_Core/ChangeLog 2015-09-04 06:58:40 UTC (rev 189341)
@@ -1,3 +1,21 @@
+2015-09-03 Aleksandr Skachkov <[email protected]>
+
+ [ES6] Implement ES6 arrow function syntax. Prototype of arrow function should be undefined
+ https://bugs.webkit.org/show_bug.cgi?id=147742
+
+ Reviewed by Saam Barati.
+
+ Added correct support of prototype property for arrow function. Arrow function
+ doesn’t have own prototype property, so (() => {}).hasOwnProperty('prototype') === false.
+ Changes prevent from creation of 'prototype' property automatically during initialization
+ of arrow function and allow to assign & delete it later in js code.
+
+
+ * runtime/JSFunction.cpp:
+ (JSC::JSFunction::getOwnPropertySlot):
+ (JSC::JSFunction::deleteProperty):
+ * tests/stress/arrowfunction-prototype.js: Added.
+
2015-09-03 Commit Queue <[email protected]>
Unreviewed, rolling out r189338.
Modified: trunk/Source/_javascript_Core/runtime/JSFunction.cpp (189340 => 189341)
--- trunk/Source/_javascript_Core/runtime/JSFunction.cpp 2015-09-04 04:54:09 UTC (rev 189340)
+++ trunk/Source/_javascript_Core/runtime/JSFunction.cpp 2015-09-04 06:58:40 UTC (rev 189341)
@@ -343,7 +343,7 @@
if (thisObject->isHostOrBuiltinFunction())
return Base::getOwnPropertySlot(thisObject, exec, propertyName, slot);
- if (propertyName == exec->propertyNames().prototype) {
+ if (propertyName == exec->propertyNames().prototype && !thisObject->jsExecutable()->isArrowFunction()) {
VM& vm = exec->vm();
unsigned attributes;
PropertyOffset offset = thisObject->getDirectOffset(vm, propertyName, attributes);
@@ -454,13 +454,16 @@
{
JSFunction* thisObject = jsCast<JSFunction*>(cell);
// For non-host functions, don't let these properties by deleted - except by DefineOwnProperty.
- if (!thisObject->isHostOrBuiltinFunction() && !exec->vm().isInDefineOwnProperty()
- && (propertyName == exec->propertyNames().arguments
+ if (!thisObject->isHostOrBuiltinFunction() && !exec->vm().isInDefineOwnProperty()) {
+ FunctionExecutable* executable = thisObject->jsExecutable();
+ if (propertyName == exec->propertyNames().arguments
|| propertyName == exec->propertyNames().length
|| propertyName == exec->propertyNames().name
- || propertyName == exec->propertyNames().prototype
- || propertyName == exec->propertyNames().caller))
+ || (propertyName == exec->propertyNames().prototype && !executable->isArrowFunction())
+ || propertyName == exec->propertyNames().caller)
return false;
+ }
+
return Base::deleteProperty(thisObject, exec, propertyName);
}
Added: trunk/Source/_javascript_Core/tests/stress/arrowfunction-prototype.js (0 => 189341)
--- trunk/Source/_javascript_Core/tests/stress/arrowfunction-prototype.js (rev 0)
+++ trunk/Source/_javascript_Core/tests/stress/arrowfunction-prototype.js 2015-09-04 06:58:40 UTC (rev 189341)
@@ -0,0 +1,22 @@
+var testCase = function (actual, expected, message) {
+ if (actual !== expected) {
+ throw message + ". Expected '" + expected + "', but was '" + actual + "'";
+ }
+};
+
+var af1 = () => {};
+var af2 = (a) => {a + 1};
+var af3 = (x) => x + 1;
+
+noInline(af1);
+noInline(af2);
+noInline(af3);
+
+for (var i = 0; i < 10000; ++i) {
+ testCase(typeof af1.prototype, 'undefined', "Error: Not correct result for prototype of arrow function #1");
+ testCase(typeof af2.prototype, 'undefined', "Error: Not correct result for prototype of arrow function #2");
+ testCase(typeof af3.prototype, 'undefined', "Error: Not correct result for prototype of arrow function #5");
+ testCase(af1.hasOwnProperty("prototype"), false, "Error: Not correct result for prototype of arrow function #3");
+ testCase(af2.hasOwnProperty("prototype"), false, "Error: Not correct result for prototype of arrow function #4");
+ testCase(af3.hasOwnProperty("prototype"), false, "Error: Not correct result for prototype of arrow function #6");
+}