Reviewers: rossberg,
Description:
Version 4.5.103.28 (cherry-pick)
Merged bb43d6c0324793380c95b36664fdf184e88fbdbd
Merged 98b56f0da6ad66ecc70de45e843636fd13083bf3
Fix parsing of arrow function formal parameters
Reship arrow functions
BUG=v8:4211
LOG=N
R=rossb...@chromium.org
Please review this at https://codereview.chromium.org/1308213003/
Base URL: https://chromium.googlesource.com/v8/v8.git@4.5
Affected files (+77, -2 lines):
M include/v8-version.h
M src/flag-definitions.h
M src/preparser.h
M test/cctest/test-parsing.cc
Index: include/v8-version.h
diff --git a/include/v8-version.h b/include/v8-version.h
index
85a944df35e0940d4cb5ab0b99f901e6ccf8feb0..66e8c6eaa5835f1f266a9decce3e6970401864fa
100644
--- a/include/v8-version.h
+++ b/include/v8-version.h
@@ -11,7 +11,7 @@
#define V8_MAJOR_VERSION 4
#define V8_MINOR_VERSION 5
#define V8_BUILD_NUMBER 103
-#define V8_PATCH_LEVEL 27
+#define V8_PATCH_LEVEL 28
// Use 1 for candidates and 0 otherwise.
// (Boolean macro values are not supported by all preprocessors.)
Index: src/flag-definitions.h
diff --git a/src/flag-definitions.h b/src/flag-definitions.h
index
8277c7385fc915beb1aa643d1160a07a55822952..a89c8e4d4ba261612a1e4bcc7171b44e9e691dec
100644
--- a/src/flag-definitions.h
+++ b/src/flag-definitions.h
@@ -200,7 +200,6 @@ DEFINE_BOOL(legacy_const, true, "legacy semantics for
const in sloppy mode")
// Features that are complete (but still behind --harmony/es-staging flag).
#define HARMONY_STAGED(V) \
- V(harmony_arrow_functions, "harmony arrow functions") \
V(harmony_tostring, "harmony toString") \
V(harmony_concat_spreadable, "harmony isConcatSpreadable") \
V(harmony_rest_parameters, "harmony rest parameters") \
@@ -209,6 +208,7 @@ DEFINE_BOOL(legacy_const, true, "legacy semantics for
const in sloppy mode")
// Features that are shipping (turned on by default, but internal flag
remains).
#define HARMONY_SHIPPING(V) \
+ V(harmony_arrow_functions, "harmony arrow functions") \
V(harmony_computed_property_names, "harmony computed property names") \
V(harmony_unicode, "harmony unicode escapes") \
V(harmony_object, "harmony Object methods")
Index: src/preparser.h
diff --git a/src/preparser.h b/src/preparser.h
index
9ebc132d92b4977b1877610e32336b8da3e3761a..d9ef1ea31ec515ec55f9b7a59a5822e3661cc2f0
100644
--- a/src/preparser.h
+++ b/src/preparser.h
@@ -2939,6 +2939,7 @@ ParserBase<Traits>::ParseConditionalExpression(bool
accept_IN,
ExpressionT expression =
this->ParseBinaryExpression(4, accept_IN, classifier, CHECK_OK);
if (peek() != Token::CONDITIONAL) return expression;
+ ArrowFormalParametersUnexpectedToken(classifier);
BindingPatternUnexpectedToken(classifier);
Consume(Token::CONDITIONAL);
// In parsing the first assignment expression in conditional
@@ -2964,6 +2965,7 @@ ParserBase<Traits>::ParseBinaryExpression(int prec,
bool accept_IN,
// prec1 >= 4
while (Precedence(peek(), accept_IN) == prec1) {
BindingPatternUnexpectedToken(classifier);
+ ArrowFormalParametersUnexpectedToken(classifier);
Token::Value op = Next();
Scanner::Location op_location = scanner()->location();
int pos = position();
@@ -3026,6 +3028,7 @@
ParserBase<Traits>::ParseUnaryExpression(ExpressionClassifier* classifier,
Token::Value op = peek();
if (Token::IsUnaryOp(op)) {
BindingPatternUnexpectedToken(classifier);
+ ArrowFormalParametersUnexpectedToken(classifier);
op = Next();
int pos = position();
@@ -3048,6 +3051,7 @@
ParserBase<Traits>::ParseUnaryExpression(ExpressionClassifier* classifier,
return this->BuildUnaryExpression(expression, op, pos, factory());
} else if (Token::IsCountOp(op)) {
BindingPatternUnexpectedToken(classifier);
+ ArrowFormalParametersUnexpectedToken(classifier);
op = Next();
Scanner::Location lhs_location = scanner()->peek_location();
ExpressionT expression = this->ParseUnaryExpression(classifier,
CHECK_OK);
@@ -3080,6 +3084,7 @@
ParserBase<Traits>::ParsePostfixExpression(ExpressionClassifier* classifier,
if (!scanner()->HasAnyLineTerminatorBeforeNext() &&
Token::IsCountOp(peek())) {
BindingPatternUnexpectedToken(classifier);
+ ArrowFormalParametersUnexpectedToken(classifier);
expression = this->CheckAndRewriteReferenceExpression(
expression, lhs_location, MessageTemplate::kInvalidLhsInPostfixOp,
@@ -3111,6 +3116,7 @@ ParserBase<Traits>::ParseLeftHandSideExpression(
switch (peek()) {
case Token::LBRACK: {
BindingPatternUnexpectedToken(classifier);
+ ArrowFormalParametersUnexpectedToken(classifier);
Consume(Token::LBRACK);
int pos = position();
ExpressionT index = ParseExpression(true, classifier, CHECK_OK);
@@ -3121,6 +3127,7 @@ ParserBase<Traits>::ParseLeftHandSideExpression(
case Token::LPAREN: {
BindingPatternUnexpectedToken(classifier);
+ ArrowFormalParametersUnexpectedToken(classifier);
if (is_strong(language_mode()) && this->IsIdentifier(result) &&
this->IsEval(this->AsIdentifier(result))) {
@@ -3172,6 +3179,7 @@ ParserBase<Traits>::ParseLeftHandSideExpression(
case Token::PERIOD: {
BindingPatternUnexpectedToken(classifier);
+ ArrowFormalParametersUnexpectedToken(classifier);
Consume(Token::PERIOD);
int pos = position();
IdentifierT name = ParseIdentifierName(CHECK_OK);
@@ -3184,6 +3192,7 @@ ParserBase<Traits>::ParseLeftHandSideExpression(
case Token::TEMPLATE_SPAN:
case Token::TEMPLATE_TAIL: {
BindingPatternUnexpectedToken(classifier);
+ ArrowFormalParametersUnexpectedToken(classifier);
result = ParseTemplateLiteral(result, position(), classifier,
CHECK_OK);
break;
}
@@ -3221,6 +3230,7 @@
ParserBase<Traits>::ParseMemberWithNewPrefixesExpression(
if (peek() == Token::NEW) {
BindingPatternUnexpectedToken(classifier);
+ ArrowFormalParametersUnexpectedToken(classifier);
Consume(Token::NEW);
int new_pos = position();
ExpressionT result = this->EmptyExpression();
@@ -3274,6 +3284,7 @@
ParserBase<Traits>::ParseMemberExpression(ExpressionClassifier* classifier,
ExpressionT result = this->EmptyExpression();
if (peek() == Token::FUNCTION) {
BindingPatternUnexpectedToken(classifier);
+ ArrowFormalParametersUnexpectedToken(classifier);
Consume(Token::FUNCTION);
int function_token_position = position();
@@ -3523,6 +3534,7 @@ ParserBase<Traits>::ParseMemberExpressionContinuation(
switch (peek()) {
case Token::LBRACK: {
BindingPatternUnexpectedToken(classifier);
+ ArrowFormalParametersUnexpectedToken(classifier);
Consume(Token::LBRACK);
int pos = position();
@@ -3536,6 +3548,7 @@ ParserBase<Traits>::ParseMemberExpressionContinuation(
}
case Token::PERIOD: {
BindingPatternUnexpectedToken(classifier);
+ ArrowFormalParametersUnexpectedToken(classifier);
Consume(Token::PERIOD);
int pos = position();
@@ -3550,6 +3563,7 @@ ParserBase<Traits>::ParseMemberExpressionContinuation(
case Token::TEMPLATE_SPAN:
case Token::TEMPLATE_TAIL: {
BindingPatternUnexpectedToken(classifier);
+ ArrowFormalParametersUnexpectedToken(classifier);
int pos;
if (scanner()->current_token() == Token::IDENTIFIER) {
pos = position();
Index: test/cctest/test-parsing.cc
diff --git a/test/cctest/test-parsing.cc b/test/cctest/test-parsing.cc
index
cbb79b16da9cc757f385978cb90193f14614163d..cfb43911aa2b3dc56e551782a400ffc8d0ece5fc
100644
--- a/test/cctest/test-parsing.cc
+++ b/test/cctest/test-parsing.cc
@@ -3516,6 +3516,67 @@ TEST(UseConstLegacyCount) {
}
+TEST(ErrorsArrowFormalParameters) {
+ const char* context_data[][2] = {
+ { "()", "=>{}" },
+ { "()", "=>{};" },
+ { "var x = ()", "=>{}" },
+ { "var x = ()", "=>{};" },
+
+ { "a", "=>{}" },
+ { "a", "=>{};" },
+ { "var x = a", "=>{}" },
+ { "var x = a", "=>{};" },
+
+ { "(a)", "=>{}" },
+ { "(a)", "=>{};" },
+ { "var x = (a)", "=>{}" },
+ { "var x = (a)", "=>{};" },
+
+ { "(...a)", "=>{}" },
+ { "(...a)", "=>{};" },
+ { "var x = (...a)", "=>{}" },
+ { "var x = (...a)", "=>{};" },
+
+ { "(a,b)", "=>{}" },
+ { "(a,b)", "=>{};" },
+ { "var x = (a,b)", "=>{}" },
+ { "var x = (a,b)", "=>{};" },
+
+ { "(a,...b)", "=>{}" },
+ { "(a,...b)", "=>{};" },
+ { "var x = (a,...b)", "=>{}" },
+ { "var x = (a,...b)", "=>{};" },
+
+ { nullptr, nullptr }
+ };
+ const char* assignment_expression_suffix_data[] = {
+ "?c:d=>{}",
+ "=c=>{}",
+ "()",
+ "(c)",
+ "[1]",
+ "[c]",
+ ".c",
+ "-c",
+ "+c",
+ "c++",
+ "`c`",
+ "`${c}`",
+ "`template-head${c}`",
+ "`${c}template-tail`",
+ "`template-head${c}template-tail`",
+ "`${c}template-tail`",
+ nullptr
+ };
+
+ static const ParserFlag always_flags[] = { kAllowHarmonyArrowFunctions,
+ kAllowHarmonyRestParameters };
+ RunParserSyncTest(context_data, assignment_expression_suffix_data,
kError,
+ NULL, 0, always_flags, arraysize(always_flags));
+}
+
+
TEST(ErrorsArrowFunctions) {
// Tests that parser and preparser generate the same kind of errors
// on invalid arrow function syntax.
--
--
v8-dev mailing list
v8-dev@googlegroups.com
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to v8-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.