Changeset 196261 in webkit
- Timestamp:
- Feb 8, 2016 11:29:24 AM (8 years ago)
- Location:
- trunk
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r196250 r196261 1 2016-02-08 Skachkov Oleksandr <gskachkov@gmail.com> 2 3 [ES6] Arrow function syntax. Using 'super' in arrow function that declared out of the class should lead to Syntax error 4 https://bugs.webkit.org/show_bug.cgi?id=150893 5 6 Reviewed by Saam Barati. 7 8 Adding tests for using of the 'super' inside of the arrow function 9 10 * js/arrowfunction-superproperty-expected.txt: 11 * js/arrowfunction-syntax-errors-expected.txt: 12 * js/script-tests/arrowfunction-superproperty.js: 13 * js/script-tests/arrowfunction-syntax-errors.js: 14 1 15 2016-02-08 Adrien Plazas <aplazas@igalia.com> 2 16 -
trunk/LayoutTests/js/arrowfunction-superproperty-expected.txt
r194449 r196261 10 10 PASS f.prop is expectedValue + "-" + "new-value" 11 11 PASS (new F()).getParentValue() is expectedValue 12 PASS (new F()).getParentValueWithError()() threw exception TypeError: undefined is not an object (evaluating 'super.getValue').13 12 PASS successfullyParsed is true 14 13 -
trunk/LayoutTests/js/arrowfunction-syntax-errors-expected.txt
r195178 r196261 132 132 PASS var arr3 = {c:a,d:b} => a + b; threw exception SyntaxError: Unexpected token '=>'. Expected ';' after variable declaration.. 133 133 PASS var arr3 = {c:b,d:a} => a + b; threw exception SyntaxError: Unexpected token '=>'. Expected ';' after variable declaration.. 134 PASS var arr4 = () => { super(); }; threw exception SyntaxError: Cannot call super() outside of a class constructor.. 135 PASS var arr4 = () => { super; }; threw exception SyntaxError: Cannot reference super.. 136 PASS var arr5 = () => { super.getValue(); }; threw exception SyntaxError: super can only be used in a method of a derived class.. 137 PASS var arr6 = () => super(); threw exception SyntaxError: Cannot call super() outside of a class constructor.. 138 PASS var arr7 = () => super; threw exception SyntaxError: Cannot reference super.. 139 PASS var arr8 = () => super.getValue(); threw exception SyntaxError: super can only be used in a method of a derived class.. 140 PASS class A { constructor() { function a () { return () => { super(); };}} threw exception SyntaxError: Cannot call super() outside of a class constructor.. 141 PASS class B { constructor() { function b () { return () => { super; }; }; }} threw exception SyntaxError: Cannot reference super.. 142 PASS class C { constructor() { function c () { return () => { super.getValue(); };}} threw exception SyntaxError: super can only be used in a method of a derived class.. 143 PASS class D { constructor() { function a () { return () => super(); }} threw exception SyntaxError: Cannot call super() outside of a class constructor.. 144 PASS class E { constructor() { function b () { return () => super; }; }} threw exception SyntaxError: Cannot reference super.. 145 PASS class F { constructor() { function c () { return () => super.getValue(); }} threw exception SyntaxError: super can only be used in a method of a derived class.. 146 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.. 134 147 PASS successfullyParsed is true 135 148 -
trunk/LayoutTests/js/script-tests/arrowfunction-superproperty.js
r194449 r196261 64 64 return arrow()(); 65 65 } 66 getParentValueWithError() {67 var f = function () {68 return () => super.getValue();69 };70 return f();71 }72 66 }; 73 67 … … 91 85 shouldBe('(new F()).getParentValue()', 'expectedValue'); 92 86 93 shouldThrow('(new F()).getParentValueWithError()()');94 95 87 var successfullyParsed = true; -
trunk/LayoutTests/js/script-tests/arrowfunction-syntax-errors.js
r195178 r196261 49 49 shouldThrow('var arr3 = {c:b,d:a} => a + b;'); 50 50 51 shouldThrow('var arr4 = () => { super(); };', '"SyntaxError: Cannot call super() outside of a class constructor."'); 52 shouldThrow('var arr4 = () => { super; };', '"SyntaxError: Cannot reference super."'); 53 shouldThrow('var arr5 = () => { super.getValue(); };', '"SyntaxError: super can only be used in a method of a derived class."'); 54 55 shouldThrow('var arr6 = () => super();', '"SyntaxError: Cannot call super() outside of a class constructor."'); 56 shouldThrow('var arr7 = () => super;', '"SyntaxError: Cannot reference super."'); 57 shouldThrow('var arr8 = () => super.getValue();', '"SyntaxError: super can only be used in a method of a derived class."'); 58 59 shouldThrow('class A { constructor() { function a () { return () => { super(); };}}', '"SyntaxError: Cannot call super() outside of a class constructor."'); 60 shouldThrow('class B { constructor() { function b () { return () => { super; }; }; }}', '"SyntaxError: Cannot reference super."'); 61 shouldThrow('class C { constructor() { function c () { return () => { super.getValue(); };}}', '"SyntaxError: super can only be used in a method of a derived class."'); 62 63 shouldThrow('class D { constructor() { function a () { return () => super(); }}', '"SyntaxError: Cannot call super() outside of a class constructor."'); 64 shouldThrow('class E { constructor() { function b () { return () => super; }; }}', '"SyntaxError: Cannot reference super."'); 65 shouldThrow('class F { constructor() { function c () { return () => super.getValue(); }}', '"SyntaxError: super can only be used in a method of a derived class."'); 66 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."'); 67 51 68 var successfullyParsed = true; -
trunk/Source/JavaScriptCore/ChangeLog
r196258 r196261 1 2016-02-08 Skachkov Oleksandr <gskachkov@gmail.com> 2 3 [ES6] Arrow function syntax. Using 'super' in arrow function that declared out of the class should lead to Syntax error 4 https://bugs.webkit.org/show_bug.cgi?id=150893 5 6 Reviewed by Saam Barati. 7 8 'super' and 'super()' inside of the arrow function should lead to syntax error if they are used 9 out of the class context or they wrapped by ordinary function. Now JSC returns ReferenceError but 10 should return SyntaxError according to the following specs: 11 http://www.ecma-international.org/ecma-262/6.0/#sec-function-definitions-static-semantics-early-errors 12 and http://www.ecma-international.org/ecma-262/6.0/#sec-arrow-function-definitions-runtime-semantics-evaluation 13 Curren patch implemented only one case when super/super() are used inside of the arrow function 14 Case when super/super() are used within the eval: 15 class A {} 16 class B extends A { 17 costructor() { eval("super()");} 18 } 19 is not part of this patch and will be implemented in this issue https://bugs.webkit.org/show_bug.cgi?id=153864. 20 The same for case when eval with super/super() is invoked in arrow function will be 21 implemented in issue https://bugs.webkit.org/show_bug.cgi?id=153977. 22 23 * parser/Parser.cpp: 24 (JSC::Parser<LexerType>::parseFunctionInfo): 25 * parser/Parser.h: 26 (JSC::Scope::Scope): 27 (JSC::Scope::setExpectedSuperBinding): 28 (JSC::Scope::expectedSuperBinding): 29 (JSC::Scope::setConstructorKind): 30 (JSC::Scope::constructorKind): 31 (JSC::Parser::closestParentNonArrowFunctionNonLexicalScope): 32 * tests/stress/arrowfunction-lexical-bind-supercall-4.js: 33 * tests/stress/arrowfunction-lexical-bind-superproperty.js: 34 1 35 2016-02-08 Filip Pizlo <fpizlo@apple.com> 2 36 -
trunk/Source/JavaScriptCore/parser/Parser.cpp
r196258 r196261 1977 1977 } 1978 1978 1979 bool isClassConstructor = constructorKind != ConstructorKind::None; 1980 1979 functionScope->setConstructorKind(constructorKind); 1980 functionScope->setExpectedSuperBinding(expectedSuperBinding); 1981 1981 1982 functionInfo.bodyStartColumn = startColumn; 1982 1983 … … 2067 2068 semanticFailIfTrue(m_vm->propertyNames->eval == *functionInfo.name, "'", functionInfo.name->impl(), "' is not a valid function name in strict mode"); 2068 2069 } 2069 if (functionScope->hasDirectSuper() && functionBodyType == StandardFunctionBodyBlock) { 2070 semanticFailIfTrue(!isClassConstructor, "Cannot call super() outside of a class constructor"); 2071 semanticFailIfTrue(constructorKind != ConstructorKind::Derived, "Cannot call super() in a base class constructor"); 2072 } 2073 if (functionScope->needsSuperBinding() && functionBodyType == StandardFunctionBodyBlock) 2074 semanticFailIfTrue(expectedSuperBinding == SuperBinding::NotNeeded, "super can only be used in a method of a derived class"); 2070 // It unncecessary to check of using super during reparsing one more time. Also it can lead to syntax error 2071 // in case of arrow function becuase during reparsing we don't know that parse arrow function 2072 // inside of the constructor or method 2073 if (!m_lexer->isReparsingFunction()) { 2074 if (functionScope->hasDirectSuper()) { 2075 ConstructorKind functionConstructorKind = functionBodyType == StandardFunctionBodyBlock 2076 ? constructorKind 2077 : closestParentNonArrowFunctionNonLexicalScope()->constructorKind(); 2078 semanticFailIfTrue(functionConstructorKind == ConstructorKind::None, "Cannot call super() outside of a class constructor"); 2079 semanticFailIfTrue(functionConstructorKind != ConstructorKind::Derived, "Cannot call super() in a base class constructor"); 2080 } 2081 if (functionScope->needsSuperBinding()) { 2082 SuperBinding functionSuperBinding = functionBodyType == StandardFunctionBodyBlock 2083 ? expectedSuperBinding 2084 : closestParentNonArrowFunctionNonLexicalScope()->expectedSuperBinding(); 2085 semanticFailIfTrue(functionSuperBinding == SuperBinding::NotNeeded, "super can only be used in a method of a derived class"); 2086 } 2087 } 2075 2088 2076 2089 JSTokenLocation location = JSTokenLocation(m_token.m_location); … … 2084 2097 // Cache the tokenizer state and the function scope the first time the function is parsed. 2085 2098 // Any future reparsing can then skip the function. 2086 static const int minimumFunctionLengthToCache = 16; 2099 // For arrow function is 8 = x=>x + 4 symbols; 2100 // For ordinary function is 16 = function(){} + 4 symbols 2101 const int minimumFunctionLengthToCache = functionBodyType == StandardFunctionBodyBlock ? 16 : 8; 2087 2102 std::unique_ptr<SourceProviderCacheItem> newInfo; 2088 2103 int functionLength = functionInfo.endOffset - functionInfo.startOffset; -
trunk/Source/JavaScriptCore/parser/Parser.h
r195581 r196261 176 176 , m_isValidStrictMode(true) 177 177 , m_hasArguments(false) 178 , m_constructorKind(static_cast<unsigned>(ConstructorKind::None)) 179 , m_expectedSuperBinding(static_cast<unsigned>(SuperBinding::NotNeeded)) 178 180 , m_loopDepth(0) 179 181 , m_switchDepth(0) … … 198 200 , m_isValidStrictMode(rhs.m_isValidStrictMode) 199 201 , m_hasArguments(rhs.m_hasArguments) 202 , m_constructorKind(rhs.m_constructorKind) 203 , m_expectedSuperBinding(rhs.m_expectedSuperBinding) 200 204 , m_loopDepth(rhs.m_loopDepth) 201 205 , m_switchDepth(rhs.m_switchDepth) … … 459 463 bool needsSuperBinding() { return m_needsSuperBinding; } 460 464 void setNeedsSuperBinding() { m_needsSuperBinding = true; } 465 466 void setExpectedSuperBinding(SuperBinding superBinding) { m_expectedSuperBinding = static_cast<unsigned>(superBinding); } 467 SuperBinding expectedSuperBinding() const { return static_cast<SuperBinding>(m_expectedSuperBinding); } 468 void setConstructorKind(ConstructorKind constructorKind) { m_constructorKind = static_cast<unsigned>(constructorKind); } 469 ConstructorKind constructorKind() const { return static_cast<ConstructorKind>(m_constructorKind); } 461 470 462 471 void collectFreeVariables(Scope* nestedScope, bool shouldTrackClosedVariables) … … 615 624 bool m_isValidStrictMode : 1; 616 625 bool m_hasArguments : 1; 626 unsigned m_constructorKind : 2; 627 unsigned m_expectedSuperBinding : 2; 617 628 int m_loopDepth; 618 629 int m_switchDepth; … … 867 878 } 868 879 880 ScopeRef closestParentNonArrowFunctionNonLexicalScope() 881 { 882 unsigned i = m_scopeStack.size() - 1; 883 ASSERT(i < m_scopeStack.size() && m_scopeStack.size()); 884 while (i && (!m_scopeStack[i].isFunctionBoundary() || m_scopeStack[i].isArrowFunction())) 885 i--; 886 // When reaching the top level scope (it can be non function scope), we return it. 887 return ScopeRef(&m_scopeStack, i); 888 } 869 889 870 890 ScopeRef pushScope() -
trunk/Source/JavaScriptCore/tests/stress/arrowfunction-lexical-bind-supercall-4.js
r193766 r196261 52 52 }; 53 53 54 // FIXME: Arrow function does not support using of eval with super/super() 55 // https://bugs.webkit.org/show_bug.cgi?id=153977 56 /* 54 57 for (var i=0; i < 1000; i++) { 55 58 new B(true); … … 61 64 testCase(e.id, 'new-value', 'Error during set value in eval #3'); 62 65 } 66 */ 63 67 64 68 var testException = function (value, index) { -
trunk/Source/JavaScriptCore/tests/stress/arrowfunction-lexical-bind-superproperty.js
r194449 r196261 124 124 return super.getValue(); 125 125 } 126 getParentValueWithError() {127 var f = function () {128 return () => super.getValue();129 };130 return f();131 }132 126 }; 133 127 … … 149 143 testCase(getValue(), 'new-value', 'Error: Some problem with using arrow and "super" inside of the method that retun arrow function'); 150 144 } 151 152 var g2 = new G();153 for (var i = 0; i < 10000; i++) {154 let error = false;155 try {156 g2.getParentValueWithError()();157 } catch(e) {158 // FIXME: should by check if e instanceof SyntaxError159 // https://bugs.webkit.org/show_bug.cgi?id=150893160 error = true;161 }162 testCase(error, true, 'Error: using "super" should lead to error');163 }164 165 145 166 146 var H = class H extends A {
Note: See TracChangeset
for help on using the changeset viewer.