Changeset 195178 in webkit
- Timestamp:
- Jan 16, 2016 4:04:37 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r195175 r195178 1 2016-01-16 Skachkov Oleksandr <gskachkov@gmail.com> 2 3 [ES6] Arrow function syntax. Arrow function should support the destructuring parameters. 4 https://bugs.webkit.org/show_bug.cgi?id=146934 5 6 Reviewed by Saam Barati. 7 8 * js/arrowfunction-syntax-errors-expected.txt: 9 * js/arrowfunction-syntax-expected.txt: 10 * js/script-tests/arrowfunction-syntax-errors.js: 11 * js/script-tests/arrowfunction-syntax.js: 12 1 13 2016-01-16 Joseph Pecoraro <pecoraro@apple.com> 2 14 -
trunk/LayoutTests/js/arrowfunction-syntax-errors-expected.txt
r187763 r195178 124 124 PASS var af3=(x, y) 125 125 =>y+1 threw exception SyntaxError: Unexpected token '=>'. 126 PASS ([a, b] => a + b)(["a_", "b_"]) threw exception SyntaxError: Unexpected token '=>'. Expected ')' to end a compound expression.. 127 PASS ({a, b} => a + b)({a:"a_", b:"b_"}) threw exception SyntaxError: Unexpected token '=>'. Expected ')' to end a compound expression.. 128 PASS ({c:a,d:b} => a + b)({c:"a_", d:"b_"}) threw exception SyntaxError: Unexpected token '=>'. Expected ')' to end a compound expression.. 129 PASS ({c:b,d:a} => a + b)({c:"a_", d:"b_"}) threw exception SyntaxError: Unexpected token '=>'. Expected ')' to end a compound expression.. 130 PASS var arr1 = [a, b] => a + b; threw exception SyntaxError: Unexpected token '=>'. Expected ';' after variable declaration.. 131 PASS var arr2 = {a, b} => a + b; threw exception SyntaxError: Unexpected token '=>'. Expected ';' after variable declaration.. 132 PASS var arr3 = {c:a,d:b} => a + b; threw exception SyntaxError: Unexpected token '=>'. Expected ';' after variable declaration.. 133 PASS var arr3 = {c:b,d:a} => a + b; threw exception SyntaxError: Unexpected token '=>'. Expected ';' after variable declaration.. 126 134 PASS successfullyParsed is true 127 135 -
trunk/LayoutTests/js/arrowfunction-syntax-expected.txt
r185989 r195178 41 41 PASS (function funcSelfExecAE3(value) { var f = (x) => { x++; return x + 1; }; return f(value);})(123); is 125 42 42 PASS (function funcSelfExecAE4(value) { var f = (x, y) => { x++; return x + y; }; return f(value, value * 2);})(123); is 370 43 PASS (([a, b]) => a + b)(["a_", "b_"]) is "a_b_" 44 PASS (({a, b}) => a + b)({a:"a_", b:"b_"}) is "a_b_" 45 PASS (({c:a, d:b}) => a + b)({c:"a_", d:"b_"}) is "a_b_" 46 PASS (({c:b, d:a}) => a + b)({c:"a_", d:"b_"}) is "b_a_" 47 PASS ((x, y, {c:b, d:a}) => x + y + a + b)("x_", "y_", {c:"a_", d:"b_"}) is "x_y_b_a_" 48 PASS (({c:b, d:a}, x, y) => x + y + a + b)({c:"a_", d:"b_"}, "x_", "y_") is "x_y_b_a_" 49 PASS ((x, y, {c:b, d:a}, [e, f]) => x + y + a + b + e + f)("x_", "y_", {c:"a_", d:"b_"}, ["e_", "f_"]) is "x_y_b_a_e_f_" 50 PASS ((x, y, {c:b, d:a}, [e, f], ...theArgs) => x + y + a + b + e + f + theArgs[0] + theArgs[1])("x_", "y_", {c:"a_", d:"b_"}, ["e_", "f_"], "g_", "h_") is "x_y_b_a_e_f_g_h_" 51 PASS arr1(["a_", "b_"]) is "a_b_" 52 PASS arr2({a:"a_", b:"b_"}) is "a_b_" 53 PASS arr3({c:"a_", d:"b_"}) is "a_b_" 54 PASS arr4({c:"a_", d:"b_"}) is "b_a_" 55 PASS arr5("x_", "y_", {c:"a_", d:"b_"}) is "x_y_b_a_" 56 PASS arr6({c:"a_", d:"b_"}, "x_", "y_") is "x_y_b_a_" 57 PASS arr7("x_", "y_", {c:"a_", d:"b_"}, ["e_", "f_"]) is "x_y_b_a_e_f_" 58 PASS arr8("x_", "y_", {c:"a_", d:"b_"}, ["e_", "f_"], "g_", "h_") is "x_y_b_a_e_f_g_h_" 43 59 PASS successfullyParsed is true 44 60 -
trunk/LayoutTests/js/script-tests/arrowfunction-syntax-errors.js
r186047 r195178 39 39 shouldThrow("var af3=(x, y)\n=>y+1"); 40 40 41 shouldThrow('([a, b] => a + b)(["a_", "b_"])' ); 42 shouldThrow('({a, b} => a + b)({a:"a_", b:"b_"})'); 43 shouldThrow('({c:a,d:b} => a + b)({c:"a_", d:"b_"})'); 44 shouldThrow('({c:b,d:a} => a + b)({c:"a_", d:"b_"})'); 45 46 shouldThrow('var arr1 = [a, b] => a + b;'); 47 shouldThrow('var arr2 = {a, b} => a + b;'); 48 shouldThrow('var arr3 = {c:a,d:b} => a + b;'); 49 shouldThrow('var arr3 = {c:b,d:a} => a + b;'); 50 41 51 var successfullyParsed = true; -
trunk/LayoutTests/js/script-tests/arrowfunction-syntax.js
r185989 r195178 80 80 shouldBe('(function funcSelfExecAE4(value) { var f = (x, y) => { x++; return x + y; }; return f(value, value * 2);})(123);', '370'); 81 81 82 shouldBe('(([a, b]) => a + b)(["a_", "b_"])', '"a_b_"'); 83 shouldBe('(({a, b}) => a + b)({a:"a_", b:"b_"})', '"a_b_"'); 84 shouldBe('(({c:a, d:b}) => a + b)({c:"a_", d:"b_"})', '"a_b_"'); 85 shouldBe('(({c:b, d:a}) => a + b)({c:"a_", d:"b_"})', '"b_a_"'); 86 shouldBe('((x, y, {c:b, d:a}) => x + y + a + b)("x_", "y_", {c:"a_", d:"b_"})', '"x_y_b_a_"'); 87 shouldBe('(({c:b, d:a}, x, y) => x + y + a + b)({c:"a_", d:"b_"}, "x_", "y_")', '"x_y_b_a_"'); 88 shouldBe('((x, y, {c:b, d:a}, [e, f]) => x + y + a + b + e + f)("x_", "y_", {c:"a_", d:"b_"}, ["e_", "f_"])', '"x_y_b_a_e_f_"'); 89 shouldBe('((x, y, {c:b, d:a}, [e, f], ...theArgs) => x + y + a + b + e + f + theArgs[0] + theArgs[1])("x_", "y_", {c:"a_", d:"b_"}, ["e_", "f_"], "g_", "h_")', '"x_y_b_a_e_f_g_h_"'); 90 91 var arr1 = ([a, b]) => a + b; 92 shouldBe('arr1(["a_", "b_"])', '"a_b_"'); 93 94 var arr2 = ({a, b}) => a + b; 95 shouldBe('arr2({a:"a_", b:"b_"})', '"a_b_"'); 96 97 var arr3 = ({c:a, d:b}) => a + b; 98 shouldBe('arr3({c:"a_", d:"b_"})', '"a_b_"'); 99 100 var arr4 = ({c:b, d:a}) => a + b; 101 shouldBe('arr4({c:"a_", d:"b_"})', '"b_a_"'); 102 103 var arr5 = (x, y, {c:b, d:a}) => x + y + a + b; 104 shouldBe('arr5("x_", "y_", {c:"a_", d:"b_"})', '"x_y_b_a_"'); 105 106 var arr6 = ({c:b, d:a}, x, y) => x + y + a + b; 107 shouldBe('arr6({c:"a_", d:"b_"}, "x_", "y_")', '"x_y_b_a_"'); 108 109 var arr7 = (x, y, {c:b, d:a}, [e, f]) => x + y + a + b + e + f; 110 shouldBe('arr7("x_", "y_", {c:"a_", d:"b_"}, ["e_", "f_"])', '"x_y_b_a_e_f_"'); 111 112 var arr8 = (x, y, {c:b, d:a}, [e, f], ...theArgs) => x + y + a + b + e + f + theArgs[0] + theArgs[1]; 113 shouldBe('arr8("x_", "y_", {c:"a_", d:"b_"}, ["e_", "f_"], "g_", "h_")', '"x_y_b_a_e_f_g_h_"'); 114 82 115 var successfullyParsed = true; -
trunk/Source/JavaScriptCore/ChangeLog
r195159 r195178 1 2016-01-16 Skachkov Oleksandr <gskachkov@gmail.com> 2 3 [ES6] Arrow function syntax. Arrow function should support the destructuring parameters. 4 https://bugs.webkit.org/show_bug.cgi?id=146934 5 6 Reviewed by Saam Barati. 7 8 Added support of destructuring parameters, before arrow function expect only simple parameters, 9 e.g. (), (x), (x, y) or x in assigment expressio. To support destructuring parameters added 10 additional check that check for destructuring paramters if check does not pass for simple parameters. 11 12 * parser/Parser.cpp: 13 (JSC::Parser<LexerType>::isArrowFunctionParameters): 14 (JSC::Parser<LexerType>::parseAssignmentExpression): 15 * parser/Parser.h: 16 1 17 2016-01-15 Benjamin Poulain <bpoulain@apple.com> 2 18 -
trunk/Source/JavaScriptCore/parser/Parser.cpp
r194881 r195178 372 372 m_features = features; 373 373 m_numConstants = numConstants; 374 } 375 376 template <typename LexerType> 377 bool Parser<LexerType>::isArrowFunctionParameters() 378 { 379 bool isArrowFunction = false; 380 381 if (match(EOFTOK)) 382 return false; 383 384 bool isOpenParen = match(OPENPAREN); 385 bool isIdent = match(IDENT); 386 387 if (!isOpenParen && !isIdent) 388 return false; 389 390 SavePoint saveArrowFunctionPoint = createSavePoint(); 391 392 if (isIdent) { 393 next(); 394 isArrowFunction = match(ARROWFUNCTION); 395 } else { 396 RELEASE_ASSERT(isOpenParen); 397 next(); 398 if (match(CLOSEPAREN)) { 399 next(); 400 isArrowFunction = match(ARROWFUNCTION); 401 } else { 402 SyntaxChecker syntaxChecker(const_cast<VM*>(m_vm), m_lexer.get()); 403 // We make fake scope, otherwise parseFormalParameters will add variable to current scope that lead to errors 404 AutoPopScopeRef fakeScope(this, pushScope()); 405 fakeScope->setSourceParseMode(SourceParseMode::ArrowFunctionMode); 406 407 unsigned parametersCount = 0; 408 isArrowFunction = parseFormalParameters(syntaxChecker, syntaxChecker.createFormalParameterList(), parametersCount) && consume(CLOSEPAREN) && match(ARROWFUNCTION); 409 410 popScope(fakeScope, syntaxChecker.NeedsFreeVariableInfo); 411 } 412 } 413 414 restoreSavePoint(saveArrowFunctionPoint); 415 416 return isArrowFunction; 374 417 } 375 418 … … 2888 2931 2889 2932 #if ENABLE(ES6_ARROWFUNCTION_SYNTAX) 2890 if (isArrowFunctionParam ters())2933 if (isArrowFunctionParameters()) 2891 2934 return parseArrowFunctionExpression(context); 2892 2935 #endif -
trunk/Source/JavaScriptCore/parser/Parser.h
r194496 r195178 1028 1028 return match(SEMICOLON) || match(COMMA) || match(CLOSEPAREN) || match(CLOSEBRACE) || match(CLOSEBRACKET) || match(EOFTOK) || m_lexer->prevTerminator(); 1029 1029 } 1030 1031 ALWAYS_INLINE bool isArrowFunctionParamters() 1032 { 1033 bool isArrowFunction = false; 1034 1035 if (match(EOFTOK)) 1036 return isArrowFunction; 1037 1038 SavePoint saveArrowFunctionPoint = createSavePoint(); 1039 1040 if (consume(OPENPAREN)) { 1041 bool isArrowFunctionParamters = true; 1042 1043 while (consume(IDENT)) { 1044 if (consume(COMMA)) { 1045 if (!match(IDENT)) { 1046 isArrowFunctionParamters = false; 1047 break; 1048 } 1049 } else 1050 break; 1051 } 1052 1053 if (isArrowFunctionParamters) { 1054 if (consume(CLOSEPAREN) && match(ARROWFUNCTION)) 1055 isArrowFunction = true; 1056 } 1057 } else if (consume(IDENT) && match(ARROWFUNCTION)) 1058 isArrowFunction = true; 1059 1060 restoreSavePoint(saveArrowFunctionPoint); 1061 1062 return isArrowFunction; 1063 } 1064 1030 1065 1031 ALWAYS_INLINE unsigned tokenStart() 1066 1032 { … … 1259 1225 template <class TreeBuilder> NEVER_INLINE bool parseFunctionInfo(TreeBuilder&, FunctionRequirements, SourceParseMode, bool nameIsInContainingScope, ConstructorKind, SuperBinding, int functionKeywordStart, ParserFunctionInfo<TreeBuilder>&, FunctionDefinitionType); 1260 1226 1227 ALWAYS_INLINE bool isArrowFunctionParameters(); 1228 1261 1229 template <class TreeBuilder> NEVER_INLINE int parseFunctionParameters(TreeBuilder&, SourceParseMode, ParserFunctionInfo<TreeBuilder>&); 1262 1230 template <class TreeBuilder> NEVER_INLINE typename TreeBuilder::FormalParameterList createGeneratorParameters(TreeBuilder&);
Note: See TracChangeset
for help on using the changeset viewer.