Title: [199927] trunk
Revision
199927
Author
gga...@apple.com
Date
2016-04-22 16:04:55 -0700 (Fri, 22 Apr 2016)

Log Message

super should be available in object literals
https://bugs.webkit.org/show_bug.cgi?id=156933

Reviewed by Saam Barati.

Source/_javascript_Core:

When we originally implemented classes, super seemed to be a class-only
feature. But the final spec says it's available in object literals too.

* bytecompiler/NodesCodegen.cpp:
(JSC::PropertyListNode::emitBytecode): Having 'super' and being a class
property are no longer synonymous, so we track two separate variables.

(JSC::PropertyListNode::emitPutConstantProperty): Being inside the super
branch no longer guarantees that you're a class property, so we decide
our attributes and our function name dynamically.

* parser/ASTBuilder.h:
(JSC::ASTBuilder::createArrowFunctionExpr):
(JSC::ASTBuilder::createGetterOrSetterProperty):
(JSC::ASTBuilder::createArguments):
(JSC::ASTBuilder::createArgumentsList):
(JSC::ASTBuilder::createProperty):
(JSC::ASTBuilder::createPropertyList): Pass through state to indicate
whether we're a class property, since we can't infer it from 'super'
anymore.

* parser/NodeConstructors.h:
(JSC::PropertyNode::PropertyNode): See ASTBuilder.h.

* parser/Nodes.h:
(JSC::PropertyNode::expressionName):
(JSC::PropertyNode::name):
(JSC::PropertyNode::type):
(JSC::PropertyNode::needsSuperBinding):
(JSC::PropertyNode::isClassProperty):
(JSC::PropertyNode::putType): See ASTBuilder.h.

* parser/Parser.cpp:
(JSC::Parser<LexerType>::parseFunctionInfo):
(JSC::Parser<LexerType>::parseClass):
(JSC::Parser<LexerType>::parseProperty):
(JSC::Parser<LexerType>::parsePropertyMethod):
(JSC::Parser<LexerType>::parseGetterSetter):
(JSC::Parser<LexerType>::parseMemberExpression): I made these error
messages generic because it is no longer practical to say concise things
about the list of places you can use super.

* parser/Parser.h:

* parser/SyntaxChecker.h:
(JSC::SyntaxChecker::createArgumentsList):
(JSC::SyntaxChecker::createProperty):
(JSC::SyntaxChecker::appendExportSpecifier):
(JSC::SyntaxChecker::appendConstDecl):
(JSC::SyntaxChecker::createGetterOrSetterProperty): Updated for
interface change.

* tests/stress/generator-with-super.js:
(test):
* tests/stress/modules-syntax-error.js:
* tests/stress/super-in-lexical-scope.js:
(testSyntaxError):
(testSyntaxError.test):
* tests/stress/tagged-templates-syntax.js: Updated for error message
changes. See Parser.cpp.

LayoutTests:

Updated expected results and added a few new tests.

* js/arrowfunction-syntax-errors-expected.txt:
* js/class-syntax-super-expected.txt:
* js/object-literal-methods-expected.txt:
* js/script-tests/arrowfunction-syntax-errors.js:
* js/script-tests/class-syntax-super.js:
* js/script-tests/object-literal-methods.js:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (199926 => 199927)


--- trunk/LayoutTests/ChangeLog	2016-04-22 23:04:35 UTC (rev 199926)
+++ trunk/LayoutTests/ChangeLog	2016-04-22 23:04:55 UTC (rev 199927)
@@ -1,3 +1,19 @@
+2016-04-22  Geoffrey Garen  <gga...@apple.com>
+
+        super should be available in object literals
+        https://bugs.webkit.org/show_bug.cgi?id=156933
+
+        Reviewed by Saam Barati.
+
+        Updated expected results and added a few new tests.
+
+        * js/arrowfunction-syntax-errors-expected.txt:
+        * js/class-syntax-super-expected.txt:
+        * js/object-literal-methods-expected.txt:
+        * js/script-tests/arrowfunction-syntax-errors.js:
+        * js/script-tests/class-syntax-super.js:
+        * js/script-tests/object-literal-methods.js:
+
 2016-04-22  Ryan Haddad  <ryanhad...@apple.com>
 
         Rebaselining inspector/model/stack-trace.html after r199897

Modified: trunk/LayoutTests/js/arrowfunction-syntax-errors-expected.txt (199926 => 199927)


--- trunk/LayoutTests/js/arrowfunction-syntax-errors-expected.txt	2016-04-22 23:04:35 UTC (rev 199926)
+++ trunk/LayoutTests/js/arrowfunction-syntax-errors-expected.txt	2016-04-22 23:04:55 UTC (rev 199927)
@@ -131,20 +131,20 @@
 PASS var arr2 = {a, b} => a + b; threw exception SyntaxError: Unexpected token '=>'. Expected ';' after variable declaration..
 PASS var arr3 = {c:a,d:b} => a + b; threw exception SyntaxError: Unexpected token '=>'. Expected ';' after variable declaration..
 PASS var arr3 = {c:b,d:a} => a + b; threw exception SyntaxError: Unexpected token '=>'. Expected ';' after variable declaration..
-PASS var arr4 = () => { super(); }; threw exception SyntaxError: Cannot call super() outside of a class constructor..
-PASS var arr4 = () => { super; }; threw exception SyntaxError: Cannot reference super..
-PASS var arr5 = () => { super.getValue(); }; threw exception SyntaxError: super can only be used in a method of a derived class..
-PASS var arr6 = () =>  super(); threw exception SyntaxError: Cannot call super() outside of a class constructor..
-PASS var arr7 = () =>  super; threw exception SyntaxError: Cannot reference super..
-PASS var arr8 = () =>  super.getValue(); threw exception SyntaxError: super can only be used in a method of a derived class..
-PASS class A { constructor() { function a () { return () => { super(); };}} threw exception SyntaxError: Cannot call super() outside of a class constructor..
-PASS class B { constructor() { function b () { return () => { super; }; }; }} threw exception SyntaxError: Cannot reference super..
-PASS class C { constructor() { function c () { return () => { super.getValue(); };}} threw exception SyntaxError: super can only be used in a method of a derived class..
-PASS class D { constructor() { function a () { return () => super(); }} threw exception SyntaxError: Cannot call super() outside of a class constructor..
-PASS class E { constructor() { function b () { return () => super; }; }} threw exception SyntaxError: Cannot reference super..
-PASS class F { constructor() { function c () { return () => super.getValue(); }} threw exception SyntaxError: super can only be used in a method of a derived class..
-PASS class G {}; class G2 extends G { getValue() { function c () { return () => super.getValue(); }} threw exception SyntaxError: super can only be used in a method of a derived class..
-PASS class H {}; class H2 extends H { method() { function *gen() { let arr = () => super.getValue(); arr(); } } } threw exception SyntaxError: super can only be used in a method of a derived class..
+PASS var arr4 = () => { super(); }; threw exception SyntaxError: super is not valid in this context..
+PASS var arr4 = () => { super; }; threw exception SyntaxError: super is not valid in this context..
+PASS var arr5 = () => { super.getValue(); }; threw exception SyntaxError: super is not valid in this context..
+PASS var arr6 = () =>  super(); threw exception SyntaxError: super is not valid in this context..
+PASS var arr7 = () =>  super; threw exception SyntaxError: super is not valid in this context..
+PASS var arr8 = () =>  super.getValue(); threw exception SyntaxError: super is not valid in this context..
+PASS class A { constructor() { function a () { return () => { super(); };}} threw exception SyntaxError: super is not valid in this context..
+PASS class B { constructor() { function b () { return () => { super; }; }; }} threw exception SyntaxError: super is not valid in this context..
+PASS class C { constructor() { function c () { return () => { super.getValue(); };}} threw exception SyntaxError: super is not valid in this context..
+PASS class D { constructor() { function a () { return () => super(); }} threw exception SyntaxError: super is not valid in this context..
+PASS class E { constructor() { function b () { return () => super; }; }} threw exception SyntaxError: super is not valid in this context..
+PASS class F { constructor() { function c () { return () => super.getValue(); }} threw exception SyntaxError: super is not valid in this context..
+PASS class G {}; class G2 extends G { getValue() { function c () { return () => super.getValue(); }} threw exception SyntaxError: super is not valid in this context..
+PASS class H {}; class H2 extends H { method() { function *gen() { let arr = () => super.getValue(); arr(); } } } threw exception SyntaxError: super is not valid in this context..
 PASS successfullyParsed is true
 
 TEST COMPLETE

Modified: trunk/LayoutTests/js/class-syntax-super-expected.txt (199926 => 199927)


--- trunk/LayoutTests/js/class-syntax-super-expected.txt	2016-04-22 23:04:35 UTC (rev 199926)
+++ trunk/LayoutTests/js/class-syntax-super-expected.txt	2016-04-22 23:04:55 UTC (rev 199927)
@@ -16,8 +16,8 @@
 PASS Derived.staticMethod():::"base3"
 PASS (new SecondDerived).chainMethod().toString():::["base", "derived", "secondDerived"].toString()
 PASS x = class extends Base { constructor() { super(); } super() {} }
-PASS x = class extends Base { constructor() { super(); } method() { super() } }:::SyntaxError: Cannot call super() outside of a class constructor.
-PASS x = class extends Base { constructor() { super(); } method() { super } }:::SyntaxError: Cannot reference super.
+PASS x = class extends Base { constructor() { super(); } method() { super() } }:::SyntaxError: super is not valid in this context.
+PASS x = class extends Base { constructor() { super(); } method() { super } }:::SyntaxError: super is not valid in this context.
 PASS x = class extends Base { constructor() { super(); } method() { return new super } }:::SyntaxError: Cannot use new with super.
 PASS x = class extends Base { constructor() { super(); } method1() { delete (super.foo) } method2() { delete super["foo"] } }
 PASS (new x).method1():::ReferenceError: Cannot delete a super property
@@ -37,18 +37,18 @@
 PASS new (class extends null { constructor() { } }):::ReferenceError: Cannot access uninitialized variable.
 PASS new (class extends null { constructor() { return 1; } }):::TypeError: Cannot return a non-object type in the constructor of a derived class.
 PASS new (class extends null { constructor() { super() } }):::TypeError: function is not a constructor (evaluating 'super()')
-PASS new (class { constructor() { super() } }):::SyntaxError: Cannot call super() in a base class constructor.
-PASS function x() { super(); }:::SyntaxError: Cannot call super() outside of a class constructor.
-PASS new (class extends Object { constructor() { function x() { super() } } }):::SyntaxError: Cannot call super() outside of a class constructor.
-PASS new (class extends Object { constructor() { function x() { super.method } } }):::SyntaxError: super can only be used in a method of a derived class.
-PASS function x() { super.method(); }:::SyntaxError: super can only be used in a method of a derived class.
-PASS function x() { super(); }:::SyntaxError: Cannot call super() outside of a class constructor.
-PASS eval("super.method()"):::SyntaxError: 'super' is only valid inside a function or an 'eval' inside a function.
-PASS eval("super()"):::SyntaxError: 'super' is only valid inside a function or an 'eval' inside a function.
-PASS (function () { eval("super.method()");})():::SyntaxError: 'super' is only valid inside a function or an 'eval' inside a function.
-PASS (function () { eval("super()");})():::SyntaxError: 'super' is only valid inside a function or an 'eval' inside a function.
-PASS new (class { constructor() { (function () { eval("super()");})(); } }):::SyntaxError: 'super' is only valid inside a function or an 'eval' inside a function.
-PASS (new (class { method() { (function () { eval("super.method()");})(); }})).method():::SyntaxError: 'super' is only valid inside a function or an 'eval' inside a function.
+PASS new (class { constructor() { super() } }):::SyntaxError: super is not valid in this context.
+PASS function x() { super(); }:::SyntaxError: super is not valid in this context.
+PASS new (class extends Object { constructor() { function x() { super() } } }):::SyntaxError: super is not valid in this context.
+PASS new (class extends Object { constructor() { function x() { super.method } } }):::SyntaxError: super is not valid in this context.
+PASS function x() { super.method(); }:::SyntaxError: super is not valid in this context.
+PASS function x() { super(); }:::SyntaxError: super is not valid in this context.
+PASS eval("super.method()"):::SyntaxError: super is not valid in this context.
+PASS eval("super()"):::SyntaxError: super is not valid in this context.
+PASS (function () { eval("super.method()");})():::SyntaxError: super is not valid in this context.
+PASS (function () { eval("super()");})():::SyntaxError: super is not valid in this context.
+PASS new (class { constructor() { (function () { eval("super()");})(); } }):::SyntaxError: super is not valid in this context.
+PASS (new (class { method() { (function () { eval("super.method()");})(); }})).method():::SyntaxError: super is not valid in this context.
 PASS successfullyParsed
 
 TEST COMPLETE

Modified: trunk/LayoutTests/js/object-literal-methods-expected.txt (199926 => 199927)


--- trunk/LayoutTests/js/object-literal-methods-expected.txt	2016-04-22 23:04:35 UTC (rev 199926)
+++ trunk/LayoutTests/js/object-literal-methods-expected.txt	2016-04-22 23:04:55 UTC (rev 199927)
@@ -68,6 +68,14 @@
 PASS ({__proto__: function(){}}) instanceof Function is true
 PASS ({__proto__(){}}) instanceof Function is false
 PASS ({__proto__(){}}).__proto__ instanceof Function is true
+PASS { f() { return super.f(); } }.f() threw exception SyntaxError: Unexpected token '{'.
+PASS new ({ f() { return super(); }.f) threw exception SyntaxError: super is not valid in this context..
+PASS o = { f() { } }; new ({ __proto__: o, f() { return super(); } }).f threw exception SyntaxError: super is not valid in this context..
+PASS ({ f() { return (() => super.f())(); } }).f() threw exception TypeError: super.f is not a function. (In 'super.f()', 'super.f' is undefined).
+PASS o = { f() { return true; } }; ({ __proto__: o, f() { return super.f(); } }).f() is true
+PASS o = { get p() { return true; } }; ({ __proto__: o, get p() { return super.p; } }).p is true
+PASS o = { set p(p2) { } }; ({ __proto__: o, set p(p2) { super.p = p2; } }).p = true is true
+PASS o = { f() { return true; } }; ({ __proto__: o, f() { return (() => super.f())(); } }).f() is true
 PASS successfullyParsed is true
 
 TEST COMPLETE

Modified: trunk/LayoutTests/js/script-tests/arrowfunction-syntax-errors.js (199926 => 199927)


--- trunk/LayoutTests/js/script-tests/arrowfunction-syntax-errors.js	2016-04-22 23:04:35 UTC (rev 199926)
+++ trunk/LayoutTests/js/script-tests/arrowfunction-syntax-errors.js	2016-04-22 23:04:55 UTC (rev 199927)
@@ -48,22 +48,22 @@
 shouldThrow('var arr3 = {c:a,d:b} => a + b;');
 shouldThrow('var arr3 = {c:b,d:a} => a + b;');
 
-shouldThrow('var arr4 = () => { super(); };', '"SyntaxError: Cannot call super() outside of a class constructor."');
-shouldThrow('var arr4 = () => { super; };', '"SyntaxError: Cannot reference super."');
-shouldThrow('var arr5 = () => { super.getValue(); };', '"SyntaxError: super can only be used in a method of a derived class."');
+shouldThrow('var arr4 = () => { super(); };', '"SyntaxError: super is not valid in this context."');
+shouldThrow('var arr4 = () => { super; };', '"SyntaxError: super is not valid in this context."');
+shouldThrow('var arr5 = () => { super.getValue(); };', '"SyntaxError: super is not valid in this context."');
 
-shouldThrow('var arr6 = () =>  super();', '"SyntaxError: Cannot call super() outside of a class constructor."');
-shouldThrow('var arr7 = () =>  super;', '"SyntaxError: Cannot reference super."');
-shouldThrow('var arr8 = () =>  super.getValue();', '"SyntaxError: super can only be used in a method of a derived class."');
+shouldThrow('var arr6 = () =>  super();', '"SyntaxError: super is not valid in this context."');
+shouldThrow('var arr7 = () =>  super;', '"SyntaxError: super is not valid in this context."');
+shouldThrow('var arr8 = () =>  super.getValue();', '"SyntaxError: super is not valid in this context."');
 
-shouldThrow('class A { constructor() { function a () { return () => { super(); };}}', '"SyntaxError: Cannot call super() outside of a class constructor."');
-shouldThrow('class B { constructor() { function b () { return () => { super; }; }; }}', '"SyntaxError: Cannot reference super."');
-shouldThrow('class C { constructor() { function c () { return () => { super.getValue(); };}}', '"SyntaxError: super can only be used in a method of a derived class."');
+shouldThrow('class A { constructor() { function a () { return () => { super(); };}}', '"SyntaxError: super is not valid in this context."');
+shouldThrow('class B { constructor() { function b () { return () => { super; }; }; }}', '"SyntaxError: super is not valid in this context."');
+shouldThrow('class C { constructor() { function c () { return () => { super.getValue(); };}}', '"SyntaxError: super is not valid in this context."');
 
-shouldThrow('class D { constructor() { function a () { return () => super(); }}', '"SyntaxError: Cannot call super() outside of a class constructor."');
-shouldThrow('class E { constructor() { function b () { return () => super; }; }}', '"SyntaxError: Cannot reference super."');
-shouldThrow('class F { constructor() { function c () { return () => super.getValue(); }}', '"SyntaxError: super can only be used in a method of a derived class."');
-shouldThrow('class G {}; class G2 extends G { getValue() { function c () { return () => super.getValue(); }}', '"SyntaxError: super can only be used in a method of a derived class."');
-shouldThrow('class H {}; class H2 extends H { method() { function *gen() { let arr = () => super.getValue(); arr(); } } }', '"SyntaxError: super can only be used in a method of a derived class."');
+shouldThrow('class D { constructor() { function a () { return () => super(); }}', '"SyntaxError: super is not valid in this context."');
+shouldThrow('class E { constructor() { function b () { return () => super; }; }}', '"SyntaxError: super is not valid in this context."');
+shouldThrow('class F { constructor() { function c () { return () => super.getValue(); }}', '"SyntaxError: super is not valid in this context."');
+shouldThrow('class G {}; class G2 extends G { getValue() { function c () { return () => super.getValue(); }}', '"SyntaxError: super is not valid in this context."');
+shouldThrow('class H {}; class H2 extends H { method() { function *gen() { let arr = () => super.getValue(); arr(); } } }', '"SyntaxError: super is not valid in this context."');
 
 var successfullyParsed = true;

Modified: trunk/LayoutTests/js/script-tests/class-syntax-super.js (199926 => 199927)


--- trunk/LayoutTests/js/script-tests/class-syntax-super.js	2016-04-22 23:04:35 UTC (rev 199926)
+++ trunk/LayoutTests/js/script-tests/class-syntax-super.js	2016-04-22 23:04:55 UTC (rev 199927)
@@ -99,8 +99,8 @@
 shouldBe('(new SecondDerived).chainMethod().toString()', '["base", "derived", "secondDerived"].toString()');
 shouldNotThrow('x = class extends Base { constructor() { super(); } super() {} }');
 shouldThrow('x = class extends Base { constructor() { super(); } method() { super() } }',
-    '"SyntaxError: Cannot call super() outside of a class constructor."');
-shouldThrow('x = class extends Base { constructor() { super(); } method() { super } }', '"SyntaxError: Cannot reference super."');
+    '"SyntaxError: super is not valid in this context."');
+shouldThrow('x = class extends Base { constructor() { super(); } method() { super } }', '"SyntaxError: super is not valid in this context."');
 shouldThrow('x = class extends Base { constructor() { super(); } method() { return new super } }', '"SyntaxError: Cannot use new with super."');
 shouldNotThrow('x = class extends Base { constructor() { super(); } method1() { delete (super.foo) } method2() { delete super["foo"] } }');
 shouldThrow('(new x).method1()', '"ReferenceError: Cannot delete a super property"');
@@ -120,19 +120,19 @@
 shouldThrow('new (class extends null { constructor() { } })', '"ReferenceError: Cannot access uninitialized variable."');
 shouldThrow('new (class extends null { constructor() { return 1; } })', '"TypeError: Cannot return a non-object type in the constructor of a derived class."');
 shouldThrow('new (class extends null { constructor() { super() } })', '"TypeError: function is not a constructor (evaluating \'super()\')"');
-shouldThrow('new (class { constructor() { super() } })', '"SyntaxError: Cannot call super() in a base class constructor."');
-shouldThrow('function x() { super(); }', '"SyntaxError: Cannot call super() outside of a class constructor."');
-shouldThrow('new (class extends Object { constructor() { function x() { super() } } })', '"SyntaxError: Cannot call super() outside of a class constructor."');
-shouldThrow('new (class extends Object { constructor() { function x() { super.method } } })', '"SyntaxError: super can only be used in a method of a derived class."');
-shouldThrow('function x() { super.method(); }', '"SyntaxError: super can only be used in a method of a derived class."');
-shouldThrow('function x() { super(); }', '"SyntaxError: Cannot call super() outside of a class constructor."');
-shouldThrow('eval("super.method()")', '"SyntaxError: \'super\' is only valid inside a function or an \'eval\' inside a function."');
-shouldThrow('eval("super()")', '"SyntaxError: \'super\' is only valid inside a function or an \'eval\' inside a function."');
+shouldThrow('new (class { constructor() { super() } })', '"SyntaxError: super is not valid in this context."');
+shouldThrow('function x() { super(); }', '"SyntaxError: super is not valid in this context."');
+shouldThrow('new (class extends Object { constructor() { function x() { super() } } })', '"SyntaxError: super is not valid in this context."');
+shouldThrow('new (class extends Object { constructor() { function x() { super.method } } })', '"SyntaxError: super is not valid in this context."');
+shouldThrow('function x() { super.method(); }', '"SyntaxError: super is not valid in this context."');
+shouldThrow('function x() { super(); }', '"SyntaxError: super is not valid in this context."');
+shouldThrow('eval("super.method()")', '"SyntaxError: super is not valid in this context."');
+shouldThrow('eval("super()")', '"SyntaxError: super is not valid in this context."');
 
-shouldThrow('(function () { eval("super.method()");})()', '"SyntaxError: \'super\' is only valid inside a function or an \'eval\' inside a function."');
-shouldThrow('(function () { eval("super()");})()', '"SyntaxError: \'super\' is only valid inside a function or an \'eval\' inside a function."');
+shouldThrow('(function () { eval("super.method()");})()', '"SyntaxError: super is not valid in this context."');
+shouldThrow('(function () { eval("super()");})()', '"SyntaxError: super is not valid in this context."');
 
-shouldThrow('new (class { constructor() { (function () { eval("super()");})(); } })', '"SyntaxError: \'super\' is only valid inside a function or an \'eval\' inside a function."');
-shouldThrow('(new (class { method() { (function () { eval("super.method()");})(); }})).method()', '"SyntaxError: \'super\' is only valid inside a function or an \'eval\' inside a function."');
+shouldThrow('new (class { constructor() { (function () { eval("super()");})(); } })', '"SyntaxError: super is not valid in this context."');
+shouldThrow('(new (class { method() { (function () { eval("super.method()");})(); }})).method()', '"SyntaxError: super is not valid in this context."');
 
 var successfullyParsed = true;

Modified: trunk/LayoutTests/js/script-tests/object-literal-methods.js (199926 => 199927)


--- trunk/LayoutTests/js/script-tests/object-literal-methods.js	2016-04-22 23:04:35 UTC (rev 199926)
+++ trunk/LayoutTests/js/script-tests/object-literal-methods.js	2016-04-22 23:04:55 UTC (rev 199927)
@@ -82,3 +82,12 @@
 shouldBeTrue("({__proto__: function(){}}) instanceof Function");
 shouldBeFalse("({__proto__(){}}) instanceof Function");
 shouldBeTrue("({__proto__(){}}).__proto__ instanceof Function");
+
+shouldThrow("{ f() { return super.f(); } }.f()");
+shouldThrow("new ({ f() { return super(); }.f)");
+shouldThrow("o = { f() { } }; new ({ __proto__: o, f() { return super(); } }).f");
+shouldThrow("({ f() { return (() => super.f())(); } }).f()");
+shouldBeTrue("o = { f() { return true; } }; ({ __proto__: o, f() { return super.f(); } }).f()");
+shouldBeTrue("o = { get p() { return true; } }; ({ __proto__: o, get p() { return super.p; } }).p");
+shouldBeTrue("o = { set p(p2) { } }; ({ __proto__: o, set p(p2) { super.p = p2; } }).p = true");
+shouldBeTrue("o = { f() { return true; } }; ({ __proto__: o, f() { return (() => super.f())(); } }).f()");

Modified: trunk/LayoutTests/sputnik/Conformance/07_Lexical_Conventions/7.5_Tokens/7.5.3_Future_Reserved_Words/S7.5.3_A1.27-expected.txt (199926 => 199927)


--- trunk/LayoutTests/sputnik/Conformance/07_Lexical_Conventions/7.5_Tokens/7.5.3_Future_Reserved_Words/S7.5.3_A1.27-expected.txt	2016-04-22 23:04:35 UTC (rev 199926)
+++ trunk/LayoutTests/sputnik/Conformance/07_Lexical_Conventions/7.5_Tokens/7.5.3_Future_Reserved_Words/S7.5.3_A1.27-expected.txt	2016-04-22 23:04:55 UTC (rev 199927)
@@ -1,4 +1,4 @@
-CONSOLE MESSAGE: line 76: SyntaxError: 'super' is only valid inside a function or an 'eval' inside a function.
+CONSOLE MESSAGE: line 76: SyntaxError: super is not valid in this context.
 S7.5.3_A1.27
 
 PASS Expected parsing failure

Modified: trunk/Source/_javascript_Core/ChangeLog (199926 => 199927)


--- trunk/Source/_javascript_Core/ChangeLog	2016-04-22 23:04:35 UTC (rev 199926)
+++ trunk/Source/_javascript_Core/ChangeLog	2016-04-22 23:04:55 UTC (rev 199927)
@@ -1,3 +1,71 @@
+2016-04-22  Geoffrey Garen  <gga...@apple.com>
+
+        super should be available in object literals
+        https://bugs.webkit.org/show_bug.cgi?id=156933
+
+        Reviewed by Saam Barati.
+
+        When we originally implemented classes, super seemed to be a class-only
+        feature. But the final spec says it's available in object literals too.
+
+        * bytecompiler/NodesCodegen.cpp:
+        (JSC::PropertyListNode::emitBytecode): Having 'super' and being a class
+        property are no longer synonymous, so we track two separate variables.
+
+        (JSC::PropertyListNode::emitPutConstantProperty): Being inside the super
+        branch no longer guarantees that you're a class property, so we decide
+        our attributes and our function name dynamically.
+
+        * parser/ASTBuilder.h:
+        (JSC::ASTBuilder::createArrowFunctionExpr):
+        (JSC::ASTBuilder::createGetterOrSetterProperty):
+        (JSC::ASTBuilder::createArguments):
+        (JSC::ASTBuilder::createArgumentsList):
+        (JSC::ASTBuilder::createProperty):
+        (JSC::ASTBuilder::createPropertyList): Pass through state to indicate
+        whether we're a class property, since we can't infer it from 'super'
+        anymore.
+
+        * parser/NodeConstructors.h:
+        (JSC::PropertyNode::PropertyNode): See ASTBuilder.h.
+
+        * parser/Nodes.h:
+        (JSC::PropertyNode::expressionName):
+        (JSC::PropertyNode::name):
+        (JSC::PropertyNode::type):
+        (JSC::PropertyNode::needsSuperBinding):
+        (JSC::PropertyNode::isClassProperty):
+        (JSC::PropertyNode::putType): See ASTBuilder.h.
+
+        * parser/Parser.cpp:
+        (JSC::Parser<LexerType>::parseFunctionInfo):
+        (JSC::Parser<LexerType>::parseClass):
+        (JSC::Parser<LexerType>::parseProperty):
+        (JSC::Parser<LexerType>::parsePropertyMethod):
+        (JSC::Parser<LexerType>::parseGetterSetter):
+        (JSC::Parser<LexerType>::parseMemberExpression): I made these error
+        messages generic because it is no longer practical to say concise things
+        about the list of places you can use super.
+
+        * parser/Parser.h:
+
+        * parser/SyntaxChecker.h:
+        (JSC::SyntaxChecker::createArgumentsList):
+        (JSC::SyntaxChecker::createProperty):
+        (JSC::SyntaxChecker::appendExportSpecifier):
+        (JSC::SyntaxChecker::appendConstDecl):
+        (JSC::SyntaxChecker::createGetterOrSetterProperty): Updated for
+        interface change.
+
+        * tests/stress/generator-with-super.js:
+        (test):
+        * tests/stress/modules-syntax-error.js:
+        * tests/stress/super-in-lexical-scope.js:
+        (testSyntaxError):
+        (testSyntaxError.test):
+        * tests/stress/tagged-templates-syntax.js: Updated for error message
+        changes. See Parser.cpp.
+
 2016-04-22  Filip Pizlo  <fpi...@apple.com>
 
         ASSERT(m_stack.last().isTailDeleted) at ShadowChicken.cpp:127 inspecting the inspector

Modified: trunk/Source/_javascript_Core/bytecompiler/NodesCodegen.cpp (199926 => 199927)


--- trunk/Source/_javascript_Core/bytecompiler/NodesCodegen.cpp	2016-04-22 23:04:35 UTC (rev 199926)
+++ trunk/Source/_javascript_Core/bytecompiler/NodesCodegen.cpp	2016-04-22 23:04:55 UTC (rev 199927)
@@ -498,11 +498,12 @@
             }
 
             RefPtr<RegisterID> value = generator.emitNode(node->m_assign);
-            bool isClassProperty = node->needsSuperBinding();
-            if (isClassProperty)
+            bool needsSuperBinding = node->needsSuperBinding();
+            if (needsSuperBinding)
                 emitPutHomeObject(generator, value.get(), dst);
-            unsigned attribute = isClassProperty ? (Accessor | DontEnum) : Accessor;
 
+            unsigned attributes = node->isClassProperty() ? (Accessor | DontEnum) : Accessor;
+
             ASSERT(node->m_type & (PropertyNode::Getter | PropertyNode::Setter));
 
             // This is a get/set property which may be overridden by a computed property later.
@@ -512,16 +513,16 @@
                     RefPtr<RegisterID> propertyName = generator.emitNode(node->m_expression);
                     generator.emitSetFunctionNameIfNeeded(node->m_assign, value.get(), propertyName.get());
                     if (node->m_type & PropertyNode::Getter)
-                        generator.emitPutGetterByVal(dst, propertyName.get(), attribute, value.get());
+                        generator.emitPutGetterByVal(dst, propertyName.get(), attributes, value.get());
                     else
-                        generator.emitPutSetterByVal(dst, propertyName.get(), attribute, value.get());
+                        generator.emitPutSetterByVal(dst, propertyName.get(), attributes, value.get());
                     continue;
                 }
 
                 if (node->m_type & PropertyNode::Getter)
-                    generator.emitPutGetterById(dst, *node->name(), attribute, value.get());
+                    generator.emitPutGetterById(dst, *node->name(), attributes, value.get());
                 else
-                    generator.emitPutSetterById(dst, *node->name(), attribute, value.get());
+                    generator.emitPutSetterById(dst, *node->name(), attributes, value.get());
                 continue;
             }
 
@@ -562,11 +563,11 @@
                 }
             }
 
-            ASSERT(!pair.second || isClassProperty == pair.second->needsSuperBinding());
-            if (isClassProperty && pair.second)
+            ASSERT(!pair.second || needsSuperBinding == pair.second->needsSuperBinding());
+            if (needsSuperBinding && pair.second)
                 emitPutHomeObject(generator, secondReg, dst);
 
-            generator.emitPutGetterSetter(dst, *node->name(), attribute, getterReg.get(), setterReg.get());
+            generator.emitPutGetterSetter(dst, *node->name(), attributes, getterReg.get(), setterReg.get());
         }
     }
 
@@ -585,8 +586,12 @@
         else
             propertyNameRegister = generator.emitNode(node.m_expression);
 
+        unsigned attributes = BytecodeGenerator::PropertyConfigurable | BytecodeGenerator::PropertyWritable;
+        if (!node.isClassProperty())
+            attributes |= BytecodeGenerator::PropertyEnumerable;
+        generator.emitSetFunctionNameIfNeeded(node.m_assign, value.get(), propertyNameRegister.get());
         generator.emitCallDefineProperty(newObj, propertyNameRegister.get(),
-            value.get(), nullptr, nullptr, BytecodeGenerator::PropertyConfigurable | BytecodeGenerator::PropertyWritable, m_position);
+            value.get(), nullptr, nullptr, attributes, m_position);
         return;
     }
     if (const auto* identifier = node.name()) {

Modified: trunk/Source/_javascript_Core/parser/ASTBuilder.h (199926 => 199927)


--- trunk/Source/_javascript_Core/parser/ASTBuilder.h	2016-04-22 23:04:35 UTC (rev 199926)
+++ trunk/Source/_javascript_Core/parser/ASTBuilder.h	2016-04-22 23:04:55 UTC (rev 199927)
@@ -410,7 +410,7 @@
     }
 
     NEVER_INLINE PropertyNode* createGetterOrSetterProperty(const JSTokenLocation& location, PropertyNode::Type type, bool,
-        const Identifier* name, const ParserFunctionInfo<ASTBuilder>& functionInfo, SuperBinding superBinding)
+        const Identifier* name, const ParserFunctionInfo<ASTBuilder>& functionInfo, bool isClassProperty)
     {
         ASSERT(name);
         functionInfo.body->setLoc(functionInfo.startLine, functionInfo.endLine, location.startOffset, location.lineStartOffset);
@@ -418,27 +418,27 @@
         functionInfo.body->setInferredName(*name);
         SourceCode source = m_sourceCode->subExpression(functionInfo.startOffset, functionInfo.endOffset, functionInfo.startLine, functionInfo.bodyStartColumn);
         MethodDefinitionNode* methodDef = new (m_parserArena) MethodDefinitionNode(location, m_vm->propertyNames->nullIdentifier, functionInfo.body, source);
-        return new (m_parserArena) PropertyNode(*name, methodDef, type, PropertyNode::Unknown, superBinding);
+        return new (m_parserArena) PropertyNode(*name, methodDef, type, PropertyNode::Unknown, SuperBinding::Needed, isClassProperty);
     }
 
     NEVER_INLINE PropertyNode* createGetterOrSetterProperty(const JSTokenLocation& location, PropertyNode::Type type, bool,
-        ExpressionNode* name, const ParserFunctionInfo<ASTBuilder>& functionInfo, SuperBinding superBinding)
+        ExpressionNode* name, const ParserFunctionInfo<ASTBuilder>& functionInfo, bool isClassProperty)
     {
         ASSERT(name);
         functionInfo.body->setLoc(functionInfo.startLine, functionInfo.endLine, location.startOffset, location.lineStartOffset);
         SourceCode source = m_sourceCode->subExpression(functionInfo.startOffset, functionInfo.endOffset, functionInfo.startLine, functionInfo.bodyStartColumn);
         MethodDefinitionNode* methodDef = new (m_parserArena) MethodDefinitionNode(location, m_vm->propertyNames->nullIdentifier, functionInfo.body, source);
-        return new (m_parserArena) PropertyNode(name, methodDef, type, PropertyNode::Unknown, superBinding);
+        return new (m_parserArena) PropertyNode(name, methodDef, type, PropertyNode::Unknown, SuperBinding::Needed, isClassProperty);
     }
 
     NEVER_INLINE PropertyNode* createGetterOrSetterProperty(VM* vm, ParserArena& parserArena, const JSTokenLocation& location, PropertyNode::Type type, bool,
-        double name, const ParserFunctionInfo<ASTBuilder>& functionInfo, SuperBinding superBinding)
+        double name, const ParserFunctionInfo<ASTBuilder>& functionInfo, bool isClassProperty)
     {
         functionInfo.body->setLoc(functionInfo.startLine, functionInfo.endLine, location.startOffset, location.lineStartOffset);
         const Identifier& ident = parserArena.identifierArena().makeNumericIdentifier(vm, name);
         SourceCode source = m_sourceCode->subExpression(functionInfo.startOffset, functionInfo.endOffset, functionInfo.startLine, functionInfo.bodyStartColumn);
         MethodDefinitionNode* methodDef = new (m_parserArena) MethodDefinitionNode(location, vm->propertyNames->nullIdentifier, functionInfo.body, source);
-        return new (m_parserArena) PropertyNode(ident, methodDef, type, PropertyNode::Unknown, superBinding);
+        return new (m_parserArena) PropertyNode(ident, methodDef, type, PropertyNode::Unknown, SuperBinding::Needed, isClassProperty);
     }
 
     ArgumentsNode* createArguments() { return new (m_parserArena) ArgumentsNode(); }
@@ -446,7 +446,7 @@
     ArgumentListNode* createArgumentsList(const JSTokenLocation& location, ExpressionNode* arg) { return new (m_parserArena) ArgumentListNode(location, arg); }
     ArgumentListNode* createArgumentsList(const JSTokenLocation& location, ArgumentListNode* args, ExpressionNode* arg) { return new (m_parserArena) ArgumentListNode(location, args, arg); }
 
-    PropertyNode* createProperty(const Identifier* propertyName, ExpressionNode* node, PropertyNode::Type type, PropertyNode::PutType putType, bool, SuperBinding superBinding = SuperBinding::NotNeeded)
+    PropertyNode* createProperty(const Identifier* propertyName, ExpressionNode* node, PropertyNode::Type type, PropertyNode::PutType putType, bool, SuperBinding superBinding, bool isClassProperty)
     {
         if (node->isFuncExprNode()) {
             auto metadata = static_cast<FuncExprNode*>(node)->metadata();
@@ -454,13 +454,13 @@
             metadata->setInferredName(*propertyName);
         } else if (node->isClassExprNode())
             static_cast<ClassExprNode*>(node)->setEcmaName(*propertyName);
-        return new (m_parserArena) PropertyNode(*propertyName, node, type, putType, superBinding);
+        return new (m_parserArena) PropertyNode(*propertyName, node, type, putType, superBinding, isClassProperty);
     }
-    PropertyNode* createProperty(VM* vm, ParserArena& parserArena, double propertyName, ExpressionNode* node, PropertyNode::Type type, PropertyNode::PutType putType, bool)
+    PropertyNode* createProperty(VM* vm, ParserArena& parserArena, double propertyName, ExpressionNode* node, PropertyNode::Type type, PropertyNode::PutType putType, bool, SuperBinding superBinding, bool isClassProperty)
     {
-        return new (m_parserArena) PropertyNode(parserArena.identifierArena().makeNumericIdentifier(vm, propertyName), node, type, putType);
+        return new (m_parserArena) PropertyNode(parserArena.identifierArena().makeNumericIdentifier(vm, propertyName), node, type, putType, superBinding, isClassProperty);
     }
-    PropertyNode* createProperty(ExpressionNode* propertyName, ExpressionNode* node, PropertyNode::Type type, PropertyNode::PutType putType, bool, SuperBinding superBinding = SuperBinding::NotNeeded) { return new (m_parserArena) PropertyNode(propertyName, node, type, putType, superBinding); }
+    PropertyNode* createProperty(ExpressionNode* propertyName, ExpressionNode* node, PropertyNode::Type type, PropertyNode::PutType putType, bool, SuperBinding superBinding, bool isClassProperty) { return new (m_parserArena) PropertyNode(propertyName, node, type, putType, superBinding, isClassProperty); }
     PropertyListNode* createPropertyList(const JSTokenLocation& location, PropertyNode* property) { return new (m_parserArena) PropertyListNode(location, property); }
     PropertyListNode* createPropertyList(const JSTokenLocation& location, PropertyNode* property, PropertyListNode* tail) { return new (m_parserArena) PropertyListNode(location, property, tail); }
 

Modified: trunk/Source/_javascript_Core/parser/NodeConstructors.h (199926 => 199927)


--- trunk/Source/_javascript_Core/parser/NodeConstructors.h	2016-04-22 23:04:35 UTC (rev 199926)
+++ trunk/Source/_javascript_Core/parser/NodeConstructors.h	2016-04-22 23:04:55 UTC (rev 199927)
@@ -220,22 +220,24 @@
     {
     }
 
-    inline PropertyNode::PropertyNode(const Identifier& name, ExpressionNode* assign, Type type, PutType putType, SuperBinding superBinding = SuperBinding::NotNeeded)
+    inline PropertyNode::PropertyNode(const Identifier& name, ExpressionNode* assign, Type type, PutType putType, SuperBinding superBinding, bool isClassProperty)
         : m_name(&name)
         , m_assign(assign)
         , m_type(type)
         , m_needsSuperBinding(superBinding == SuperBinding::Needed)
         , m_putType(putType)
+        , m_isClassProperty(isClassProperty)
     {
     }
 
-    inline PropertyNode::PropertyNode(ExpressionNode* name, ExpressionNode* assign, Type type, PutType putType, SuperBinding superBinding = SuperBinding::NotNeeded)
+    inline PropertyNode::PropertyNode(ExpressionNode* name, ExpressionNode* assign, Type type, PutType putType, SuperBinding superBinding, bool isClassProperty)
         : m_name(0)
         , m_expression(name)
         , m_assign(assign)
         , m_type(type)
         , m_needsSuperBinding(superBinding == SuperBinding::Needed)
         , m_putType(putType)
+        , m_isClassProperty(isClassProperty)
     {
     }
 

Modified: trunk/Source/_javascript_Core/parser/Nodes.h (199926 => 199927)


--- trunk/Source/_javascript_Core/parser/Nodes.h	2016-04-22 23:04:35 UTC (rev 199926)
+++ trunk/Source/_javascript_Core/parser/Nodes.h	2016-04-22 23:04:55 UTC (rev 199927)
@@ -626,14 +626,15 @@
         enum Type { Constant = 1, Getter = 2, Setter = 4, Computed = 8, Shorthand = 16 };
         enum PutType { Unknown, KnownDirect };
 
-        PropertyNode(const Identifier&, ExpressionNode*, Type, PutType, SuperBinding);
-        PropertyNode(ExpressionNode* propertyName, ExpressionNode*, Type, PutType, SuperBinding);
+        PropertyNode(const Identifier&, ExpressionNode*, Type, PutType, SuperBinding, bool isClassProperty);
+        PropertyNode(ExpressionNode* propertyName, ExpressionNode*, Type, PutType, SuperBinding, bool isClassProperty);
 
         ExpressionNode* expressionName() const { return m_expression; }
         const Identifier* name() const { return m_name; }
 
         Type type() const { return static_cast<Type>(m_type); }
         bool needsSuperBinding() const { return m_needsSuperBinding; }
+        bool isClassProperty() const { return m_isClassProperty; }
         PutType putType() const { return static_cast<PutType>(m_putType); }
 
     private:
@@ -644,6 +645,7 @@
         unsigned m_type : 5;
         unsigned m_needsSuperBinding : 1;
         unsigned m_putType : 1;
+        unsigned m_isClassProperty: 1;
     };
 
     class PropertyListNode : public ExpressionNode {

Modified: trunk/Source/_javascript_Core/parser/Parser.cpp (199926 => 199927)


--- trunk/Source/_javascript_Core/parser/Parser.cpp	2016-04-22 23:04:35 UTC (rev 199926)
+++ trunk/Source/_javascript_Core/parser/Parser.cpp	2016-04-22 23:04:55 UTC (rev 199927)
@@ -2078,9 +2078,9 @@
         if  (generatorBodyScope->strictMode())
             functionScope->setStrictMode();
 
-        semanticFailIfTrue(generatorBodyScope->hasDirectSuper(), "Cannot call super() outside of a class constructor");
+        semanticFailIfTrue(generatorBodyScope->hasDirectSuper(), "super is not valid in this context");
         if (generatorBodyScope->needsSuperBinding())
-            semanticFailIfTrue(expectedSuperBinding == SuperBinding::NotNeeded, "super can only be used in a method of a derived class");
+            semanticFailIfTrue(expectedSuperBinding == SuperBinding::NotNeeded, "super is not valid in this context");
 
         popScope(generatorBodyScope, TreeBuilder::NeedsFreeVariableInfo);
     } else
@@ -2103,15 +2103,15 @@
             ConstructorKind functionConstructorKind = functionBodyType == StandardFunctionBodyBlock && !scopeRef->isEvalContext()
                 ? constructorKind
                 : scopeRef->constructorKind();
-            semanticFailIfTrue(functionConstructorKind == ConstructorKind::None, "Cannot call super() outside of a class constructor");
-            semanticFailIfTrue(functionConstructorKind != ConstructorKind::Derived, "Cannot call super() in a base class constructor");
+            semanticFailIfTrue(functionConstructorKind == ConstructorKind::None, "super is not valid in this context");
+            semanticFailIfTrue(functionConstructorKind != ConstructorKind::Derived, "super is not valid in this context");
         }
         if (functionScope->needsSuperBinding()) {
             ScopeRef scopeRef = closestParentOrdinaryFunctionNonLexicalScope();
             SuperBinding functionSuperBinding = functionBodyType == StandardFunctionBodyBlock && !scopeRef->isEvalContext()
                 ? expectedSuperBinding
                 : scopeRef->expectedSuperBinding();
-            semanticFailIfTrue(functionSuperBinding == SuperBinding::NotNeeded, "super can only be used in a method of a derived class");
+            semanticFailIfTrue(functionSuperBinding == SuperBinding::NotNeeded, "super is not valid in this context");
         }
     }
 
@@ -2335,8 +2335,9 @@
         TreeProperty property;
         const bool alwaysStrictInsideClass = true;
         if (isGetter || isSetter) {
+            bool isClassProperty = true;
             property = parseGetterSetter(context, alwaysStrictInsideClass, isGetter ? PropertyNode::Getter : PropertyNode::Setter, methodStart,
-                ConstructorKind::None, SuperBinding::Needed);
+                ConstructorKind::None, isClassProperty);
             failIfFalse(property, "Cannot parse this method");
         } else {
             ParserFunctionInfo<TreeBuilder> methodInfo;
@@ -2361,11 +2362,13 @@
             // FIXME: Syntax error when super() is called
             semanticFailIfTrue(isStaticMethod && methodInfo.name && *methodInfo.name == propertyNames.prototype,
                 "Cannot declare a static method named 'prototype'");
+
+            bool isClassProperty = true;
             if (computedPropertyName) {
                 property = context.createProperty(computedPropertyName, method, static_cast<PropertyNode::Type>(PropertyNode::Constant | PropertyNode::Computed),
-                    PropertyNode::Unknown, alwaysStrictInsideClass, SuperBinding::Needed);
+                    PropertyNode::Unknown, alwaysStrictInsideClass, SuperBinding::Needed, isClassProperty);
             } else
-                property = context.createProperty(methodInfo.name, method, PropertyNode::Constant, PropertyNode::Unknown, alwaysStrictInsideClass, SuperBinding::Needed);
+                property = context.createProperty(methodInfo.name, method, PropertyNode::Constant, PropertyNode::Unknown, alwaysStrictInsideClass, SuperBinding::Needed, isClassProperty);
         }
 
         TreePropertyList& tail = isStaticMethod ? staticMethodsTail : instanceMethodsTail;
@@ -3257,6 +3260,7 @@
 {
     bool wasIdent = false;
     bool isGenerator = false;
+    bool isClassProperty = false;
 #if ENABLE(ES6_GENERATORS)
     if (consume(TIMES))
         isGenerator = true;
@@ -3279,13 +3283,13 @@
             TreeExpression node = parseAssignmentExpressionOrPropagateErrorClass(context);
             failIfFalse(node, "Cannot parse _expression_ for property declaration");
             context.setEndOffset(node, m_lexer->currentOffset());
-            return context.createProperty(ident, node, PropertyNode::Constant, PropertyNode::Unknown, complete);
+            return context.createProperty(ident, node, PropertyNode::Constant, PropertyNode::Unknown, complete, SuperBinding::NotNeeded, isClassProperty);
         }
 
         if (match(OPENPAREN)) {
             auto method = parsePropertyMethod(context, ident, isGenerator);
             propagateError();
-            return context.createProperty(ident, method, PropertyNode::Constant, PropertyNode::KnownDirect, complete);
+            return context.createProperty(ident, method, PropertyNode::Constant, PropertyNode::KnownDirect, complete, SuperBinding::Needed, isClassProperty);
         }
         failIfTrue(isGenerator, "Expected a parenthesis for argument list");
 
@@ -3298,7 +3302,7 @@
             if (currentScope()->isArrowFunction())
                 currentScope()->setInnerArrowFunctionUsesEval();
             TreeExpression node = context.createResolve(location, *ident, start, lastTokenEndPosition());
-            return context.createProperty(ident, node, static_cast<PropertyNode::Type>(PropertyNode::Constant | PropertyNode::Shorthand), PropertyNode::KnownDirect, complete);
+            return context.createProperty(ident, node, static_cast<PropertyNode::Type>(PropertyNode::Constant | PropertyNode::Shorthand), PropertyNode::KnownDirect, complete, SuperBinding::NotNeeded, isClassProperty);
         }
 
         if (match(EQUAL)) // CoverInitializedName is exclusive to BindingPattern and AssignmentPattern
@@ -3311,7 +3315,7 @@
             type = PropertyNode::Setter;
         else
             failWithMessage("Expected a ':' following the property name '", ident->impl(), "'");
-        return parseGetterSetter(context, complete, type, getterOrSetterStartOffset);
+        return parseGetterSetter(context, complete, type, getterOrSetterStartOffset, ConstructorKind::None, isClassProperty);
     }
     case DOUBLE:
     case INTEGER: {
@@ -3322,7 +3326,7 @@
             const Identifier& ident = m_parserArena.identifierArena().makeNumericIdentifier(const_cast<VM*>(m_vm), propertyName);
             auto method = parsePropertyMethod(context, &ident, isGenerator);
             propagateError();
-            return context.createProperty(&ident, method, PropertyNode::Constant, PropertyNode::Unknown, complete);
+            return context.createProperty(&ident, method, PropertyNode::Constant, PropertyNode::Unknown, complete, SuperBinding::Needed, isClassProperty);
         }
         failIfTrue(isGenerator, "Expected a parenthesis for argument list");
 
@@ -3330,7 +3334,7 @@
         TreeExpression node = parseAssignmentExpression(context);
         failIfFalse(node, "Cannot parse _expression_ for property declaration");
         context.setEndOffset(node, m_lexer->currentOffset());
-        return context.createProperty(const_cast<VM*>(m_vm), m_parserArena, propertyName, node, PropertyNode::Constant, PropertyNode::Unknown, complete);
+        return context.createProperty(const_cast<VM*>(m_vm), m_parserArena, propertyName, node, PropertyNode::Constant, PropertyNode::Unknown, complete, SuperBinding::NotNeeded, isClassProperty);
     }
     case OPENBRACKET: {
         next();
@@ -3341,7 +3345,7 @@
         if (match(OPENPAREN)) {
             auto method = parsePropertyMethod(context, &m_vm->propertyNames->nullIdentifier, isGenerator);
             propagateError();
-            return context.createProperty(propertyName, method, static_cast<PropertyNode::Type>(PropertyNode::Constant | PropertyNode::Computed), PropertyNode::KnownDirect, complete);
+            return context.createProperty(propertyName, method, static_cast<PropertyNode::Type>(PropertyNode::Constant | PropertyNode::Computed), PropertyNode::KnownDirect, complete, SuperBinding::Needed, isClassProperty);
         }
         failIfTrue(isGenerator, "Expected a parenthesis for argument list");
 
@@ -3349,7 +3353,7 @@
         TreeExpression node = parseAssignmentExpression(context);
         failIfFalse(node, "Cannot parse _expression_ for property declaration");
         context.setEndOffset(node, m_lexer->currentOffset());
-        return context.createProperty(propertyName, node, static_cast<PropertyNode::Type>(PropertyNode::Constant | PropertyNode::Computed), PropertyNode::Unknown, complete);
+        return context.createProperty(propertyName, node, static_cast<PropertyNode::Type>(PropertyNode::Constant | PropertyNode::Computed), PropertyNode::Unknown, complete, SuperBinding::NotNeeded, isClassProperty);
     }
     default:
         failIfFalse(m_token.m_type & KeywordTokenFlag, "Expected a property name");
@@ -3364,14 +3368,14 @@
     unsigned methodStart = tokenStart();
     ParserFunctionInfo<TreeBuilder> methodInfo;
     SourceParseMode parseMode = isGenerator ? SourceParseMode::GeneratorWrapperFunctionMode : SourceParseMode::MethodMode;
-    failIfFalse((parseFunctionInfo(context, FunctionNoRequirements, parseMode, false, ConstructorKind::None, SuperBinding::NotNeeded, methodStart, methodInfo, FunctionDefinitionType::Method)), "Cannot parse this method");
+    failIfFalse((parseFunctionInfo(context, FunctionNoRequirements, parseMode, false, ConstructorKind::None, SuperBinding::Needed, methodStart, methodInfo, FunctionDefinitionType::Method)), "Cannot parse this method");
     methodInfo.name = methodName;
     return context.createMethodDefinition(methodLocation, methodInfo);
 }
 
 template <typename LexerType>
 template <class TreeBuilder> TreeProperty Parser<LexerType>::parseGetterSetter(TreeBuilder& context, bool strict, PropertyNode::Type type, unsigned getterOrSetterStartOffset,
-    ConstructorKind constructorKind, SuperBinding superBinding)
+    ConstructorKind constructorKind, bool isClassProperty)
 {
     const Identifier* stringPropertyName = 0;
     double numericPropertyName = 0;
@@ -3381,9 +3385,9 @@
 
     if (matchSpecIdentifier() || match(STRING) || m_token.m_type & KeywordTokenFlag) {
         stringPropertyName = m_token.m_data.ident;
-        semanticFailIfTrue(superBinding == SuperBinding::Needed && *stringPropertyName == m_vm->propertyNames->prototype,
+        semanticFailIfTrue(isClassProperty && *stringPropertyName == m_vm->propertyNames->prototype,
             "Cannot declare a static method named 'prototype'");
-        semanticFailIfTrue(superBinding == SuperBinding::Needed && *stringPropertyName == m_vm->propertyNames->constructor,
+        semanticFailIfTrue(isClassProperty && *stringPropertyName == m_vm->propertyNames->constructor,
             "Cannot declare a getter or setter named 'constructor'");
         next();
     } else if (match(DOUBLE) || match(INTEGER)) {
@@ -3400,19 +3404,19 @@
     ParserFunctionInfo<TreeBuilder> info;
     if (type & PropertyNode::Getter) {
         failIfFalse(match(OPENPAREN), "Expected a parameter list for getter definition");
-        failIfFalse((parseFunctionInfo(context, FunctionNoRequirements, SourceParseMode::GetterMode, false, constructorKind, superBinding, getterOrSetterStartOffset, info, FunctionDefinitionType::Method)), "Cannot parse getter definition");
+        failIfFalse((parseFunctionInfo(context, FunctionNoRequirements, SourceParseMode::GetterMode, false, constructorKind, SuperBinding::Needed, getterOrSetterStartOffset, info, FunctionDefinitionType::Method)), "Cannot parse getter definition");
     } else {
         failIfFalse(match(OPENPAREN), "Expected a parameter list for setter definition");
-        failIfFalse((parseFunctionInfo(context, FunctionNoRequirements, SourceParseMode::SetterMode, false, constructorKind, superBinding, getterOrSetterStartOffset, info, FunctionDefinitionType::Method)), "Cannot parse setter definition");
+        failIfFalse((parseFunctionInfo(context, FunctionNoRequirements, SourceParseMode::SetterMode, false, constructorKind, SuperBinding::Needed, getterOrSetterStartOffset, info, FunctionDefinitionType::Method)), "Cannot parse setter definition");
     }
 
     if (stringPropertyName)
-        return context.createGetterOrSetterProperty(location, type, strict, stringPropertyName, info, superBinding);
+        return context.createGetterOrSetterProperty(location, type, strict, stringPropertyName, info, isClassProperty);
 
     if (computedPropertyName)
-        return context.createGetterOrSetterProperty(location, static_cast<PropertyNode::Type>(type | PropertyNode::Computed), strict, computedPropertyName, info, superBinding);
+        return context.createGetterOrSetterProperty(location, static_cast<PropertyNode::Type>(type | PropertyNode::Computed), strict, computedPropertyName, info, isClassProperty);
 
-    return context.createGetterOrSetterProperty(const_cast<VM*>(m_vm), m_parserArena, location, type, strict, numericPropertyName, info, superBinding);
+    return context.createGetterOrSetterProperty(const_cast<VM*>(m_vm), m_parserArena, location, type, strict, numericPropertyName, info, isClassProperty);
 }
 
 template <typename LexerType>
@@ -3894,7 +3898,7 @@
 
     if (baseIsSuper) {
         ScopeRef scopeRef = closestParentOrdinaryFunctionNonLexicalScope();
-        semanticFailIfFalse(currentScope()->isFunction() || (scopeRef->isEvalContext() && scopeRef->expectedSuperBinding() == SuperBinding::Needed), "'super' is only valid inside a function or an 'eval' inside a function");
+        semanticFailIfFalse(currentScope()->isFunction() || (scopeRef->isEvalContext() && scopeRef->expectedSuperBinding() == SuperBinding::Needed), "super is not valid in this context");
         base = context.createSuperExpr(location);
         next();
         currentFunctionScope()->setNeedsSuperBinding();
@@ -3972,7 +3976,7 @@
         baseIsSuper = false;
     }
 endMemberExpression:
-    semanticFailIfTrue(baseIsSuper, "Cannot reference super");
+    semanticFailIfTrue(baseIsSuper, "super is not valid in this context");
     while (newCount--)
         base = context.createNewExpr(location, base, expressionStart, lastTokenEndPosition());
     return base;

Modified: trunk/Source/_javascript_Core/parser/Parser.h (199926 => 199927)


--- trunk/Source/_javascript_Core/parser/Parser.h	2016-04-22 23:04:35 UTC (rev 199926)
+++ trunk/Source/_javascript_Core/parser/Parser.h	2016-04-22 23:04:55 UTC (rev 199927)
@@ -1388,7 +1388,7 @@
     template <class TreeBuilder> ALWAYS_INLINE TreeExpression parseArgument(TreeBuilder&, ArgumentType&);
     template <class TreeBuilder> TreeProperty parseProperty(TreeBuilder&, bool strict);
     template <class TreeBuilder> TreeExpression parsePropertyMethod(TreeBuilder& context, const Identifier* methodName, bool isGenerator);
-    template <class TreeBuilder> TreeProperty parseGetterSetter(TreeBuilder&, bool strict, PropertyNode::Type, unsigned getterOrSetterStartOffset, ConstructorKind = ConstructorKind::None, SuperBinding = SuperBinding::NotNeeded);
+    template <class TreeBuilder> TreeProperty parseGetterSetter(TreeBuilder&, bool strict, PropertyNode::Type, unsigned getterOrSetterStartOffset, ConstructorKind, bool isClassProperty);
     template <class TreeBuilder> ALWAYS_INLINE TreeFunctionBody parseFunctionBody(TreeBuilder&, const JSTokenLocation&, int, int functionKeywordStart, int functionNameStart, int parametersStart, ConstructorKind, SuperBinding, FunctionBodyType, unsigned, SourceParseMode);
     template <class TreeBuilder> ALWAYS_INLINE bool parseFormalParameters(TreeBuilder&, TreeFormalParameterList, unsigned&);
     enum VarDeclarationListContext { ForLoopContext, VarDeclarationContext };

Modified: trunk/Source/_javascript_Core/parser/SyntaxChecker.h (199926 => 199927)


--- trunk/Source/_javascript_Core/parser/SyntaxChecker.h	2016-04-22 23:04:35 UTC (rev 199926)
+++ trunk/Source/_javascript_Core/parser/SyntaxChecker.h	2016-04-22 23:04:55 UTC (rev 199927)
@@ -202,20 +202,20 @@
 
     int createArgumentsList(const JSTokenLocation&, int) { return ArgumentsListResult; }
     int createArgumentsList(const JSTokenLocation&, int, int) { return ArgumentsListResult; }
-    Property createProperty(const Identifier* name, int, PropertyNode::Type type, PropertyNode::PutType, bool complete, SuperBinding = SuperBinding::NotNeeded)
+    Property createProperty(const Identifier* name, int, PropertyNode::Type type, PropertyNode::PutType, bool complete, SuperBinding, bool)
     {
         if (!complete)
             return Property(type);
         ASSERT(name);
         return Property(name, type);
     }
-    Property createProperty(VM* vm, ParserArena& parserArena, double name, int, PropertyNode::Type type, PropertyNode::PutType, bool complete)
+    Property createProperty(VM* vm, ParserArena& parserArena, double name, int, PropertyNode::Type type, PropertyNode::PutType, bool complete, SuperBinding, bool)
     {
         if (!complete)
             return Property(type);
         return Property(&parserArena.identifierArena().makeNumericIdentifier(vm, name), type);
     }
-    Property createProperty(int, int, PropertyNode::Type type, PropertyNode::PutType, bool, SuperBinding = SuperBinding::NotNeeded)
+    Property createProperty(int, int, PropertyNode::Type type, PropertyNode::PutType, bool, SuperBinding, bool)
     {
         return Property(type);
     }
@@ -269,18 +269,18 @@
     void appendExportSpecifier(ExportSpecifierList, ExportSpecifier) { }
 
     int appendConstDecl(const JSTokenLocation&, int, const Identifier*, int) { return StatementResult; }
-    Property createGetterOrSetterProperty(const JSTokenLocation&, PropertyNode::Type type, bool strict, const Identifier* name, const ParserFunctionInfo<SyntaxChecker>&, SuperBinding)
+    Property createGetterOrSetterProperty(const JSTokenLocation&, PropertyNode::Type type, bool strict, const Identifier* name, const ParserFunctionInfo<SyntaxChecker>&, bool)
     {
         ASSERT(name);
         if (!strict)
             return Property(type);
         return Property(name, type);
     }
-    Property createGetterOrSetterProperty(const JSTokenLocation&, PropertyNode::Type type, bool, int, const ParserFunctionInfo<SyntaxChecker>&, SuperBinding)
+    Property createGetterOrSetterProperty(const JSTokenLocation&, PropertyNode::Type type, bool, int, const ParserFunctionInfo<SyntaxChecker>&, bool)
     {
         return Property(type);
     }
-    Property createGetterOrSetterProperty(VM* vm, ParserArena& parserArena, const JSTokenLocation&, PropertyNode::Type type, bool strict, double name, const ParserFunctionInfo<SyntaxChecker>&, SuperBinding)
+    Property createGetterOrSetterProperty(VM* vm, ParserArena& parserArena, const JSTokenLocation&, PropertyNode::Type type, bool strict, double name, const ParserFunctionInfo<SyntaxChecker>&, bool)
     {
         if (!strict)
             return Property(type);

Modified: trunk/Source/_javascript_Core/tests/stress/generator-with-super.js (199926 => 199927)


--- trunk/Source/_javascript_Core/tests/stress/generator-with-super.js	2016-04-22 23:04:35 UTC (rev 199926)
+++ trunk/Source/_javascript_Core/tests/stress/generator-with-super.js	2016-04-22 23:04:55 UTC (rev 199927)
@@ -23,7 +23,7 @@
         return eval('super');
     }
 
-    shouldThrow(() => test(), "SyntaxError: 'super' is only valid inside a function or an 'eval' inside a function.");
+    shouldThrow(() => test(), "SyntaxError: super is not valid in this context.");
 }());
 
 (function () {

Modified: trunk/Source/_javascript_Core/tests/stress/modules-syntax-error.js (199926 => 199927)


--- trunk/Source/_javascript_Core/tests/stress/modules-syntax-error.js	2016-04-22 23:04:35 UTC (rev 199926)
+++ trunk/Source/_javascript_Core/tests/stress/modules-syntax-error.js	2016-04-22 23:04:55 UTC (rev 199927)
@@ -307,12 +307,12 @@
 
 checkModuleSyntaxError(String.raw`
 super();
-`, `SyntaxError: 'super' is only valid inside a function or an 'eval' inside a function.:2`);
+`, `SyntaxError: super is not valid in this context.:2`);
 
 checkModuleSyntaxError(String.raw`
 super.test();
-`, `SyntaxError: 'super' is only valid inside a function or an 'eval' inside a function.:2`);
+`, `SyntaxError: super is not valid in this context.:2`);
 
 checkModuleSyntaxError(String.raw`
 super.test = 20;
-`, `SyntaxError: 'super' is only valid inside a function or an 'eval' inside a function.:2`);
+`, `SyntaxError: super is not valid in this context.:2`);

Modified: trunk/Source/_javascript_Core/tests/stress/super-in-lexical-scope.js (199926 => 199927)


--- trunk/Source/_javascript_Core/tests/stress/super-in-lexical-scope.js	2016-04-22 23:04:35 UTC (rev 199926)
+++ trunk/Source/_javascript_Core/tests/stress/super-in-lexical-scope.js	2016-04-22 23:04:55 UTC (rev 199927)
@@ -18,33 +18,33 @@
         throw new Error("Expected syntax error not thrown");
 
     if (String(error) !== message)
-        throw new Error("Bad error: " + String(error));
+        throw new Error("Bad error: " + String(error) + "(Expected: " + message + ")");
 }
 
-testSyntaxError(`super()`, `SyntaxError: 'super' is only valid inside a function or an 'eval' inside a function.`);
-testSyntaxError(`super.hello()`, `SyntaxError: 'super' is only valid inside a function or an 'eval' inside a function.`);
+testSyntaxError(`super()`, `SyntaxError: super is not valid in this context.`);
+testSyntaxError(`super.hello()`, `SyntaxError: super is not valid in this context.`);
 testSyntaxError(`
 {
     super();
 }
-`, `SyntaxError: 'super' is only valid inside a function or an 'eval' inside a function.`);
+`, `SyntaxError: super is not valid in this context.`);
 testSyntaxError(`
 {
     super.hello();
 }
-`, `SyntaxError: 'super' is only valid inside a function or an 'eval' inside a function.`);
+`, `SyntaxError: super is not valid in this context.`);
 testSyntaxError(`
 function test()
 {
     super();
 }
-`, `SyntaxError: Cannot call super() outside of a class constructor.`);
+`, `SyntaxError: super is not valid in this context.`);
 testSyntaxError(`
 function test()
 {
     super.hello();
 }
-`, `SyntaxError: super can only be used in a method of a derived class.`);
+`, `SyntaxError: super is not valid in this context.`);
 testSyntaxError(`
 function test()
 {
@@ -52,7 +52,7 @@
         super();
     }
 }
-`, `SyntaxError: Cannot call super() outside of a class constructor.`);
+`, `SyntaxError: super is not valid in this context.`);
 testSyntaxError(`
 function test()
 {
@@ -60,4 +60,4 @@
         super.hello();
     }
 }
-`, `SyntaxError: super can only be used in a method of a derived class.`);
+`, `SyntaxError: super is not valid in this context.`);

Modified: trunk/Source/_javascript_Core/tests/stress/tagged-templates-syntax.js (199926 => 199927)


--- trunk/Source/_javascript_Core/tests/stress/tagged-templates-syntax.js	2016-04-22 23:04:35 UTC (rev 199926)
+++ trunk/Source/_javascript_Core/tests/stress/tagged-templates-syntax.js	2016-04-22 23:04:55 UTC (rev 199927)
@@ -66,5 +66,5 @@
 testSyntax("(class extends Hello { constructor() { super()`${tag} ${tag}` } })");
 testSyntax("(class extends Hello { constructor() { super()`${tag}${tag}` } })");
 
-testSyntaxError("super`Hello${tag}`", "SyntaxError: 'super' is only valid inside a function or an 'eval' inside a function.");
+testSyntaxError("super`Hello${tag}`", "SyntaxError: super is not valid in this context.");
 testSyntaxError("(class { say() { super`Hello${tag}` } })", "SyntaxError: Cannot use super as tag for tagged templates.");
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to