haikuwebkit/LayoutTests/js/script-tests/arrowfunction-syntax-errors.js

70 lines
3.1 KiB
JavaScript
Raw Permalink Normal View History

Source/JavaScriptCore: [ES6] Implement ES6 arrow function syntax. Parser of arrow function with execution as common function. https://bugs.webkit.org/show_bug.cgi?id=144955 Reviewed by Yusuke Suzuki. Added support of ES6 arrow function. Changes were made according to following spec http://wiki.ecmascript.org/doku.php?id=harmony:arrow_function_syntax. Patch does not include any arrow function specific behavior e.g. lexical bind this, arguments and etc. This patch implements the simplest cases of arrow function declaration: parameters () => 10 + 20 parameter x => x + 20 parameters (x, y) => x + y function with block x => { return x*10; } Not implemented: bind of the this, arguments, super and etc. exception in case of trying to use 'new' with arrow function Patch by Aleksandr Skachkov <gskachkov@gmail.com> on 2015-06-26 * parser/ASTBuilder.h: (JSC::ASTBuilder::createFunctionExpr): (JSC::ASTBuilder::createArrowFunctionExpr): (JSC::ASTBuilder::createGetterOrSetterProperty): (JSC::ASTBuilder::createFuncDeclStatement): * parser/Lexer.cpp: (JSC::Lexer<T>::setTokenPosition): (JSC::Lexer<T>::lex): * parser/Lexer.h: (JSC::Lexer::lastTokenLocation): (JSC::Lexer::setTerminator): * parser/Parser.cpp: (JSC::Parser<LexerType>::parseInner): (JSC::Parser<LexerType>::parseSourceElements): (JSC::Parser<LexerType>::parseArrowFunctionSingleExpressionBody): (JSC::Parser<LexerType>::parseSwitchClauses): (JSC::Parser<LexerType>::parseSwitchDefaultClause): (JSC::Parser<LexerType>::parseBlockStatement): (JSC::Parser<LexerType>::parseFunctionBody): (JSC::stringForFunctionMode): (JSC::Parser<LexerType>::parseFunctionParameters): (JSC::Parser<LexerType>::parseFunctionInfo): (JSC::Parser<LexerType>::parseFunctionDeclaration): (JSC::Parser<LexerType>::parseClass): (JSC::Parser<LexerType>::parseAssignmentExpression): (JSC::Parser<LexerType>::parsePropertyMethod): (JSC::Parser<LexerType>::parseGetterSetter): (JSC::Parser<LexerType>::parseArrowFunctionExpression): * parser/Parser.h: (JSC::Parser::locationBeforeLastToken): (JSC::Parser::isEndOfArrowFunction): (JSC::Parser::isArrowFunctionParamters): (JSC::Parser::setEndOfStatement): * parser/ParserFunctionInfo.h: * parser/ParserTokens.h: * parser/SourceCode.h: (JSC::SourceCode::subArrowExpression): * parser/SourceProviderCacheItem.h: (JSC::SourceProviderCacheItem::endFunctionToken): (JSC::SourceProviderCacheItem::SourceProviderCacheItem): * parser/SyntaxChecker.h: (JSC::SyntaxChecker::createArrowFunctionExpr): (JSC::SyntaxChecker::setFunctionNameStart): LayoutTests: [ES6] Implement ES6 arrow function syntax. Parser of arrow function with execution as common function https://bugs.webkit.org/show_bug.cgi?id=144955 Reviewed by Yusuke Suzuki. Added arrow function tests Patch by Aleksandr Skachkov <gskachkov@gmail.com> on 2015-06-26 * js/arrowfunction-asparamter-1-expected.txt: Added. * js/arrowfunction-asparamter-1.html: Added. * js/arrowfunction-asparamter-2-expected.txt: Added. * js/arrowfunction-asparamter-2.html: Added. * js/arrowfunction-associativity-1-expected.txt: Added. * js/arrowfunction-associativity-1.html: Added. * js/arrowfunction-associativity-2-expected.txt: Added. * js/arrowfunction-associativity-2.html: Added. * js/arrowfunction-block-1-expected.txt: Added. * js/arrowfunction-block-1.html: Added. * js/arrowfunction-block-2-expected.txt: Added. * js/arrowfunction-block-2.html: Added. * js/arrowfunction-syntax-endings-expected.txt: Added. * js/arrowfunction-syntax-endings.html: Added. * js/arrowfunction-syntax-errors-expected.txt: Added. * js/arrowfunction-syntax-errors.html: Added. * js/arrowfunction-syntax-expected.txt: Added. * js/arrowfunction-syntax.html: Added. * js/script-tests/arrowfunction-asparamter-1.js: Added. * js/script-tests/arrowfunction-asparamter-2.js: Added. * js/script-tests/arrowfunction-associativity-1.js: Added. * js/script-tests/arrowfunction-associativity-2.js: Added. * js/script-tests/arrowfunction-block-1.js: Added. * js/script-tests/arrowfunction-block-2.js: Added. * js/script-tests/arrowfunction-syntax-endings.js: Added. * js/script-tests/arrowfunction-syntax-errors.js: Added. * js/script-tests/arrowfunction-syntax.js: Added. Canonical link: https://commits.webkit.org/164423@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@185989 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-06-26 06:49:20 +00:00
description("Tests for ES6 arrow function syntax errors");
shouldThrow('=>{}');
function checkStatement(statement) {
var unexpectedSymbols = [ "",
"*", "/", "%" , "+", "-" ,
"<<", ">>", ">>>" ,
"<", ">", "<=", ">=", "instanceof", "in" ,
"==", "!=", "===", "!==",
"&" , "^" , "|" ,
"&&" , "||", ";" , ","
];
for (var i = 0; i < unexpectedSymbols.length; i++) {
shouldThrow(statement + unexpectedSymbols[i]);
}
}
checkStatement('x=>');
checkStatement('x=>{');
shouldThrow('x=>}');
checkStatement('var y = x=>');
checkStatement('var y = x=>{');
shouldThrow('var y = x=>}');
shouldThrow('var t = x=>x+1; =>{}');
shouldThrow('[=>x+1]');
shouldThrow('[x=>x+1, =>x+1]');
shouldThrow('var f=>x+1;');
shouldThrow('var x, y=>y+1;');
shouldThrow('debug(=>x+1)');
shouldThrow('debug("xyz", =>x+1)');
shouldThrow("var af1=y\n=>y+1");
shouldThrow("var af2=(y)\n=>y+1");
shouldThrow("var af3=(x, y)\n=>y+1");
shouldThrow('([a, b] => a + b)(["a_", "b_"])' );
shouldThrow('({a, b} => a + b)({a:"a_", b:"b_"})');
shouldThrow('({c:a,d:b} => a + b)({c:"a_", d:"b_"})');
shouldThrow('({c:b,d:a} => a + b)({c:"a_", d:"b_"})');
shouldThrow('var arr1 = [a, b] => a + b;');
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;');
super should be available in object literals https://bugs.webkit.org/show_bug.cgi?id=156933 Reviewed by Saam Barati. Source/JavaScriptCore: 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: Canonical link: https://commits.webkit.org/175044@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@199927 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-04-22 23:04:55 +00:00
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."');
[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 Patch by Skachkov Oleksandr <gskachkov@gmail.com> on 2016-02-08 Reviewed by Saam Barati. Source/JavaScriptCore: 'super' and 'super()' inside of the arrow function should lead to syntax error if they are used out of the class context or they wrapped by ordinary function. Now JSC returns ReferenceError but should return SyntaxError according to the following specs: http://www.ecma-international.org/ecma-262/6.0/#sec-function-definitions-static-semantics-early-errors and http://www.ecma-international.org/ecma-262/6.0/#sec-arrow-function-definitions-runtime-semantics-evaluation Curren patch implemented only one case when super/super() are used inside of the arrow function Case when super/super() are used within the eval: class A {} class B extends A { costructor() { eval("super()");} } is not part of this patch and will be implemented in this issue https://bugs.webkit.org/show_bug.cgi?id=153864. The same for case when eval with super/super() is invoked in arrow function will be implemented in issue https://bugs.webkit.org/show_bug.cgi?id=153977. * 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::closestParentNonArrowFunctionNonLexicalScope): * tests/stress/arrowfunction-lexical-bind-supercall-4.js: * tests/stress/arrowfunction-lexical-bind-superproperty.js: LayoutTests: 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: Canonical link: https://commits.webkit.org/172088@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@196261 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-02-08 19:29:24 +00:00
super should be available in object literals https://bugs.webkit.org/show_bug.cgi?id=156933 Reviewed by Saam Barati. Source/JavaScriptCore: 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: Canonical link: https://commits.webkit.org/175044@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@199927 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-04-22 23:04:55 +00:00
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."');
[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 Patch by Skachkov Oleksandr <gskachkov@gmail.com> on 2016-02-08 Reviewed by Saam Barati. Source/JavaScriptCore: 'super' and 'super()' inside of the arrow function should lead to syntax error if they are used out of the class context or they wrapped by ordinary function. Now JSC returns ReferenceError but should return SyntaxError according to the following specs: http://www.ecma-international.org/ecma-262/6.0/#sec-function-definitions-static-semantics-early-errors and http://www.ecma-international.org/ecma-262/6.0/#sec-arrow-function-definitions-runtime-semantics-evaluation Curren patch implemented only one case when super/super() are used inside of the arrow function Case when super/super() are used within the eval: class A {} class B extends A { costructor() { eval("super()");} } is not part of this patch and will be implemented in this issue https://bugs.webkit.org/show_bug.cgi?id=153864. The same for case when eval with super/super() is invoked in arrow function will be implemented in issue https://bugs.webkit.org/show_bug.cgi?id=153977. * 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::closestParentNonArrowFunctionNonLexicalScope): * tests/stress/arrowfunction-lexical-bind-supercall-4.js: * tests/stress/arrowfunction-lexical-bind-superproperty.js: LayoutTests: 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: Canonical link: https://commits.webkit.org/172088@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@196261 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-02-08 19:29:24 +00:00
super should be available in object literals https://bugs.webkit.org/show_bug.cgi?id=156933 Reviewed by Saam Barati. Source/JavaScriptCore: 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: Canonical link: https://commits.webkit.org/175044@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@199927 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-04-22 23:04:55 +00:00
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."');
[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 Patch by Skachkov Oleksandr <gskachkov@gmail.com> on 2016-02-08 Reviewed by Saam Barati. Source/JavaScriptCore: 'super' and 'super()' inside of the arrow function should lead to syntax error if they are used out of the class context or they wrapped by ordinary function. Now JSC returns ReferenceError but should return SyntaxError according to the following specs: http://www.ecma-international.org/ecma-262/6.0/#sec-function-definitions-static-semantics-early-errors and http://www.ecma-international.org/ecma-262/6.0/#sec-arrow-function-definitions-runtime-semantics-evaluation Curren patch implemented only one case when super/super() are used inside of the arrow function Case when super/super() are used within the eval: class A {} class B extends A { costructor() { eval("super()");} } is not part of this patch and will be implemented in this issue https://bugs.webkit.org/show_bug.cgi?id=153864. The same for case when eval with super/super() is invoked in arrow function will be implemented in issue https://bugs.webkit.org/show_bug.cgi?id=153977. * 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::closestParentNonArrowFunctionNonLexicalScope): * tests/stress/arrowfunction-lexical-bind-supercall-4.js: * tests/stress/arrowfunction-lexical-bind-superproperty.js: LayoutTests: 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: Canonical link: https://commits.webkit.org/172088@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@196261 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-02-08 19:29:24 +00:00
super should be available in object literals https://bugs.webkit.org/show_bug.cgi?id=156933 Reviewed by Saam Barati. Source/JavaScriptCore: 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: Canonical link: https://commits.webkit.org/175044@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@199927 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-04-22 23:04:55 +00:00
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."');
[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 Patch by Skachkov Oleksandr <gskachkov@gmail.com> on 2016-02-08 Reviewed by Saam Barati. Source/JavaScriptCore: 'super' and 'super()' inside of the arrow function should lead to syntax error if they are used out of the class context or they wrapped by ordinary function. Now JSC returns ReferenceError but should return SyntaxError according to the following specs: http://www.ecma-international.org/ecma-262/6.0/#sec-function-definitions-static-semantics-early-errors and http://www.ecma-international.org/ecma-262/6.0/#sec-arrow-function-definitions-runtime-semantics-evaluation Curren patch implemented only one case when super/super() are used inside of the arrow function Case when super/super() are used within the eval: class A {} class B extends A { costructor() { eval("super()");} } is not part of this patch and will be implemented in this issue https://bugs.webkit.org/show_bug.cgi?id=153864. The same for case when eval with super/super() is invoked in arrow function will be implemented in issue https://bugs.webkit.org/show_bug.cgi?id=153977. * 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::closestParentNonArrowFunctionNonLexicalScope): * tests/stress/arrowfunction-lexical-bind-supercall-4.js: * tests/stress/arrowfunction-lexical-bind-superproperty.js: LayoutTests: 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: Canonical link: https://commits.webkit.org/172088@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@196261 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-02-08 19:29:24 +00:00
Source/JavaScriptCore: [ES6] Implement ES6 arrow function syntax. Parser of arrow function with execution as common function. https://bugs.webkit.org/show_bug.cgi?id=144955 Reviewed by Yusuke Suzuki. Added support of ES6 arrow function. Changes were made according to following spec http://wiki.ecmascript.org/doku.php?id=harmony:arrow_function_syntax. Patch does not include any arrow function specific behavior e.g. lexical bind this, arguments and etc. This patch implements the simplest cases of arrow function declaration: parameters () => 10 + 20 parameter x => x + 20 parameters (x, y) => x + y function with block x => { return x*10; } Not implemented: bind of the this, arguments, super and etc. exception in case of trying to use 'new' with arrow function Patch by Aleksandr Skachkov <gskachkov@gmail.com> on 2015-06-26 * parser/ASTBuilder.h: (JSC::ASTBuilder::createFunctionExpr): (JSC::ASTBuilder::createArrowFunctionExpr): (JSC::ASTBuilder::createGetterOrSetterProperty): (JSC::ASTBuilder::createFuncDeclStatement): * parser/Lexer.cpp: (JSC::Lexer<T>::setTokenPosition): (JSC::Lexer<T>::lex): * parser/Lexer.h: (JSC::Lexer::lastTokenLocation): (JSC::Lexer::setTerminator): * parser/Parser.cpp: (JSC::Parser<LexerType>::parseInner): (JSC::Parser<LexerType>::parseSourceElements): (JSC::Parser<LexerType>::parseArrowFunctionSingleExpressionBody): (JSC::Parser<LexerType>::parseSwitchClauses): (JSC::Parser<LexerType>::parseSwitchDefaultClause): (JSC::Parser<LexerType>::parseBlockStatement): (JSC::Parser<LexerType>::parseFunctionBody): (JSC::stringForFunctionMode): (JSC::Parser<LexerType>::parseFunctionParameters): (JSC::Parser<LexerType>::parseFunctionInfo): (JSC::Parser<LexerType>::parseFunctionDeclaration): (JSC::Parser<LexerType>::parseClass): (JSC::Parser<LexerType>::parseAssignmentExpression): (JSC::Parser<LexerType>::parsePropertyMethod): (JSC::Parser<LexerType>::parseGetterSetter): (JSC::Parser<LexerType>::parseArrowFunctionExpression): * parser/Parser.h: (JSC::Parser::locationBeforeLastToken): (JSC::Parser::isEndOfArrowFunction): (JSC::Parser::isArrowFunctionParamters): (JSC::Parser::setEndOfStatement): * parser/ParserFunctionInfo.h: * parser/ParserTokens.h: * parser/SourceCode.h: (JSC::SourceCode::subArrowExpression): * parser/SourceProviderCacheItem.h: (JSC::SourceProviderCacheItem::endFunctionToken): (JSC::SourceProviderCacheItem::SourceProviderCacheItem): * parser/SyntaxChecker.h: (JSC::SyntaxChecker::createArrowFunctionExpr): (JSC::SyntaxChecker::setFunctionNameStart): LayoutTests: [ES6] Implement ES6 arrow function syntax. Parser of arrow function with execution as common function https://bugs.webkit.org/show_bug.cgi?id=144955 Reviewed by Yusuke Suzuki. Added arrow function tests Patch by Aleksandr Skachkov <gskachkov@gmail.com> on 2015-06-26 * js/arrowfunction-asparamter-1-expected.txt: Added. * js/arrowfunction-asparamter-1.html: Added. * js/arrowfunction-asparamter-2-expected.txt: Added. * js/arrowfunction-asparamter-2.html: Added. * js/arrowfunction-associativity-1-expected.txt: Added. * js/arrowfunction-associativity-1.html: Added. * js/arrowfunction-associativity-2-expected.txt: Added. * js/arrowfunction-associativity-2.html: Added. * js/arrowfunction-block-1-expected.txt: Added. * js/arrowfunction-block-1.html: Added. * js/arrowfunction-block-2-expected.txt: Added. * js/arrowfunction-block-2.html: Added. * js/arrowfunction-syntax-endings-expected.txt: Added. * js/arrowfunction-syntax-endings.html: Added. * js/arrowfunction-syntax-errors-expected.txt: Added. * js/arrowfunction-syntax-errors.html: Added. * js/arrowfunction-syntax-expected.txt: Added. * js/arrowfunction-syntax.html: Added. * js/script-tests/arrowfunction-asparamter-1.js: Added. * js/script-tests/arrowfunction-asparamter-2.js: Added. * js/script-tests/arrowfunction-associativity-1.js: Added. * js/script-tests/arrowfunction-associativity-2.js: Added. * js/script-tests/arrowfunction-block-1.js: Added. * js/script-tests/arrowfunction-block-2.js: Added. * js/script-tests/arrowfunction-syntax-endings.js: Added. * js/script-tests/arrowfunction-syntax-errors.js: Added. * js/script-tests/arrowfunction-syntax.js: Added. Canonical link: https://commits.webkit.org/164423@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@185989 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-06-26 06:49:20 +00:00
var successfullyParsed = true;