WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
[patch]
Patch
bug-150893-20160126233526.patch (text/plain), 14.97 KB, created by
GSkachkov
on 2016-01-26 14:35:54 PST
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
GSkachkov
Created:
2016-01-26 14:35:54 PST
Size:
14.97 KB
patch
obsolete
>Subversion Revision: 195311 >diff --git a/Source/JavaScriptCore/ChangeLog b/Source/JavaScriptCore/ChangeLog >index faaca72bb13a375d115ce375495594cfe8090c6f..4b742c4eee749d47a085c8f7e82565d5c0b6d29c 100644 >--- a/Source/JavaScriptCore/ChangeLog >+++ b/Source/JavaScriptCore/ChangeLog >@@ -1,3 +1,23 @@ >+2016-01-26 Skachkov Oleksandr <gskachkov@gmail.com> >+ >+ [ES6] Arrow function syntax. Using 'super' in arrow function that declared out of the class should lead to Syntax error >+ https://bugs.webkit.org/show_bug.cgi?id=150893 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ 'super' and 'super()' inside of the arrow function should lead to syntax error if they used out >+ of the class context or they wrapped by ordinary function. >+ >+ * parser/Parser.cpp: >+ (JSC::Parser<LexerType>::parseFunctionInfo): >+ * parser/Parser.h: >+ (JSC::Scope::Scope): >+ (JSC::Scope::setExpectedSuperBinding): >+ (JSC::Scope::expectedSuperBinding): >+ (JSC::Scope::setConstructorKind): >+ (JSC::Scope::constructorKind): >+ (JSC::Parser::currentNotArrowfunctionFunctionScope): >+ > 2016-01-19 Skachkov Oleksandr <gskachkov@gmail.com> > > [ES6] Arrow function syntax. Arrow function specific features. Lexical bind "arguments" >diff --git a/Source/JavaScriptCore/parser/Parser.cpp b/Source/JavaScriptCore/parser/Parser.cpp >index e00d8002220439321cbd0cde16f729e936f86225..280c3b383681a8a420211c48fa099845c2626ff0 100644 >--- a/Source/JavaScriptCore/parser/Parser.cpp >+++ b/Source/JavaScriptCore/parser/Parser.cpp >@@ -1944,8 +1944,9 @@ template <class TreeBuilder> bool Parser<LexerType>::parseFunctionInfo(TreeBuild > functionBodyType = StandardFunctionBodyBlock; > } > >- bool isClassConstructor = constructorKind != ConstructorKind::None; >- >+ functionScope->setConstructorKind(constructorKind); >+ functionScope->setExpectedSuperBinding(expectedSuperBinding); >+ > functionInfo.bodyStartColumn = startColumn; > > // If we know about this function already, we can use the cached info and skip the parser to the end of the function. >@@ -2034,12 +2035,17 @@ template <class TreeBuilder> bool Parser<LexerType>::parseFunctionInfo(TreeBuild > semanticFailIfTrue(m_vm->propertyNames->arguments == *functionInfo.name, "'", functionInfo.name->impl(), "' is not a valid function name in strict mode"); > semanticFailIfTrue(m_vm->propertyNames->eval == *functionInfo.name, "'", functionInfo.name->impl(), "' is not a valid function name in strict mode"); > } >- if (functionScope->hasDirectSuper() && functionBodyType == StandardFunctionBodyBlock) { >- semanticFailIfTrue(!isClassConstructor, "Cannot call super() outside of a class constructor"); >- semanticFailIfTrue(constructorKind != ConstructorKind::Derived, "Cannot call super() in a base class constructor"); >+ if (functionScope->hasDirectSuper()) { >+ ConstructorKind functionConstructorKind = functionBodyType == StandardFunctionBodyBlock >+ ? constructorKind >+ : currentNotArrowfunctionFunctionScope()->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"); >+ } >+ if (functionScope->needsSuperBinding()) { >+ SuperBinding functionSuperBinding = functionBodyType == StandardFunctionBodyBlock ? expectedSuperBinding : currentNotArrowfunctionFunctionScope()->expectedSuperBinding(); >+ semanticFailIfTrue(functionSuperBinding == SuperBinding::NotNeeded, "super can only be used in a method of a derived class"); > } >- if (functionScope->needsSuperBinding() && functionBodyType == StandardFunctionBodyBlock) >- semanticFailIfTrue(expectedSuperBinding == SuperBinding::NotNeeded, "super can only be used in a method of a derived class"); > > JSTokenLocation location = JSTokenLocation(m_token.m_location); > functionInfo.endOffset = m_token.m_data.offset; >@@ -2051,7 +2057,9 @@ template <class TreeBuilder> bool Parser<LexerType>::parseFunctionInfo(TreeBuild > > // Cache the tokenizer state and the function scope the first time the function is parsed. > // Any future reparsing can then skip the function. >- static const int minimumFunctionLengthToCache = 16; >+ // For arrow function is 10 = ()=>() + 4 symbols; >+ // For ordinary function is 16 = function(){} + 4 symbols >+ const int minimumFunctionLengthToCache = functionBodyType == StandardFunctionBodyBlock ? 16 : 6; > std::unique_ptr<SourceProviderCacheItem> newInfo; > int functionLength = functionInfo.endOffset - functionInfo.startOffset; > if (TreeBuilder::CanUseFunctionCache && m_functionCache && functionLength > minimumFunctionLengthToCache) { >diff --git a/Source/JavaScriptCore/parser/Parser.h b/Source/JavaScriptCore/parser/Parser.h >index 0aa6b3dde3c36e75924322c0d3afb4b0c6b978cf..ee06404085ede9af7dc1095c9a0b0778e6e190c3 100644 >--- a/Source/JavaScriptCore/parser/Parser.h >+++ b/Source/JavaScriptCore/parser/Parser.h >@@ -174,6 +174,8 @@ struct Scope { > , m_isFunctionBoundary(false) > , m_isValidStrictMode(true) > , m_hasArguments(false) >+ , m_constructorKind(static_cast<unsigned>(ConstructorKind::None)) >+ , m_expectedSuperBinding(static_cast<unsigned>(SuperBinding::NotNeeded)) > , m_loopDepth(0) > , m_switchDepth(0) > { >@@ -196,6 +198,8 @@ struct Scope { > , m_isFunctionBoundary(rhs.m_isFunctionBoundary) > , m_isValidStrictMode(rhs.m_isValidStrictMode) > , m_hasArguments(rhs.m_hasArguments) >+ , m_constructorKind(rhs.m_constructorKind) >+ , m_expectedSuperBinding(rhs.m_expectedSuperBinding) > , m_loopDepth(rhs.m_loopDepth) > , m_switchDepth(rhs.m_switchDepth) > , m_moduleScopeData(rhs.m_moduleScopeData) >@@ -457,6 +461,11 @@ struct Scope { > > bool needsSuperBinding() { return m_needsSuperBinding; } > void setNeedsSuperBinding() { m_needsSuperBinding = true; } >+ >+ void setExpectedSuperBinding(SuperBinding superBinding) { m_expectedSuperBinding = static_cast<unsigned>(superBinding); } >+ SuperBinding expectedSuperBinding() const { return static_cast<SuperBinding>(m_expectedSuperBinding); } >+ void setConstructorKind(ConstructorKind constructorKind) { m_constructorKind = static_cast<unsigned>(constructorKind); } >+ ConstructorKind constructorKind() const { return static_cast<ConstructorKind>(m_constructorKind); } > > void collectFreeVariables(Scope* nestedScope, bool shouldTrackClosedVariables) > { >@@ -613,6 +622,8 @@ private: > bool m_isFunctionBoundary : 1; > bool m_isValidStrictMode : 1; > bool m_hasArguments : 1; >+ unsigned m_constructorKind : 2; >+ unsigned m_expectedSuperBinding : 2; > int m_loopDepth; > int m_switchDepth; > >@@ -864,7 +875,19 @@ private: > // When reaching the top level scope (it can be non function scope), we return it. > return ScopeRef(&m_scopeStack, i); > } >- >+ >+ // Find the closest not 'arrow function' function scope. >+ ScopeRef currentNotArrowfunctionFunctionScope() >+ { >+ unsigned i = m_scopeStack.size() - 1; >+ ASSERT(i < m_scopeStack.size()); >+ while (i && (!m_scopeStack[i].isFunctionBoundary() || m_scopeStack[i].isArrowFunction())) { >+ i--; >+ ASSERT(i < m_scopeStack.size()); >+ } >+ // When reaching the top level scope (it can be non function scope), we return it. >+ return ScopeRef(&m_scopeStack, i); >+ } > > ScopeRef pushScope() > { >diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog >index 35e09502461e1ef899532f46ac5efa53d905308f..de148d06a07254aed36f98bb9c1b9d09c94ff6da 100644 >--- a/LayoutTests/ChangeLog >+++ b/LayoutTests/ChangeLog >@@ -1,3 +1,17 @@ >+2016-01-26 Skachkov Oleksandr <gskachkov@gmail.com> >+ >+ [ES6] Arrow function syntax. Using 'super' in arrow function that declared out of the class should lead to Syntax error >+ https://bugs.webkit.org/show_bug.cgi?id=150893 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Adding tests for using of the 'super' inside of the arrow function >+ >+ * js/arrowfunction-superproperty-expected.txt: >+ * js/arrowfunction-syntax-errors-expected.txt: >+ * js/script-tests/arrowfunction-superproperty.js: >+ * js/script-tests/arrowfunction-syntax-errors.js: >+ > 2016-01-21 Skachkov Oleksandr <gskachkov@gmail.com> > > [ES6] Arrow function. Default arguments in arrow functions >diff --git a/LayoutTests/js/arrowfunction-superproperty-expected.txt b/LayoutTests/js/arrowfunction-superproperty-expected.txt >index 3df2c495fb9ff1e276330f153c140bb5ff5f49d3..476f9d4d1ee87976bcb7439cdb0f615b67bb667b 100644 >--- a/LayoutTests/js/arrowfunction-superproperty-expected.txt >+++ b/LayoutTests/js/arrowfunction-superproperty-expected.txt >@@ -9,7 +9,6 @@ PASS E.getParentStaticValue() is expectedValue > PASS f.prop is expectedValue + "-" + expectedValue > PASS f.prop is expectedValue + "-" + "new-value" > PASS (new F()).getParentValue() is expectedValue >-PASS (new F()).getParentValueWithError()() threw exception TypeError: undefined is not an object (evaluating 'super.getValue'). > PASS successfullyParsed is true > > TEST COMPLETE >diff --git a/LayoutTests/js/arrowfunction-syntax-errors-expected.txt b/LayoutTests/js/arrowfunction-syntax-errors-expected.txt >index 7553f41b9d1847819fc5674dafd32a9da0419ad7..7dcfcb030f226f71ba5f91c9efb441c57a6e0fc9 100644 >--- a/LayoutTests/js/arrowfunction-syntax-errors-expected.txt >+++ b/LayoutTests/js/arrowfunction-syntax-errors-expected.txt >@@ -131,6 +131,19 @@ PASS var arr1 = [a, b] => a + b; threw exception SyntaxError: Unexpected token ' > 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 successfullyParsed is true > > TEST COMPLETE >diff --git a/LayoutTests/js/script-tests/arrowfunction-superproperty.js b/LayoutTests/js/script-tests/arrowfunction-superproperty.js >index e5f249cbbbda288f137a52370f2611cb41571fbe..2f587fd572266ac96d83da21e4955e31f25e9576 100644 >--- a/LayoutTests/js/script-tests/arrowfunction-superproperty.js >+++ b/LayoutTests/js/script-tests/arrowfunction-superproperty.js >@@ -63,12 +63,6 @@ class F extends A { > let arrow = () => () => super.getValue(); > return arrow()(); > } >- getParentValueWithError() { >- var f = function () { >- return () => super.getValue(); >- }; >- return f(); >- } > }; > > shouldBe('(new B()).getValueParentFunction()', 'expectedValue'); >@@ -90,6 +84,4 @@ shouldBe('f.prop', 'expectedValue + "-" + "new-value"'); > > shouldBe('(new F()).getParentValue()', 'expectedValue'); > >-shouldThrow('(new F()).getParentValueWithError()()'); >- > var successfullyParsed = true; >diff --git a/LayoutTests/js/script-tests/arrowfunction-syntax-errors.js b/LayoutTests/js/script-tests/arrowfunction-syntax-errors.js >index 5a22634c8752527e3847452af3665ad678e2ff12..e8f24f4faeae7d32611f3e9b23f0d0cfcf074ad7 100644 >--- a/LayoutTests/js/script-tests/arrowfunction-syntax-errors.js >+++ b/LayoutTests/js/script-tests/arrowfunction-syntax-errors.js >@@ -48,4 +48,21 @@ shouldThrow('var arr2 = {a, b} => a + b;'); > 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 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('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 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."'); >+ > var successfullyParsed = true;
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 150893
:
269925
|
270010
|
270653
|
270654
|
270826
|
270851