Commit d0049fb7 authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[parser] Track accept_IN with scopes and a different precendece table

Change-Id: I6da7a3cbf681a5ae691fe0aee2e69536a84f0df0
Reviewed-on: https://chromium-review.googlesource.com/c/1329174
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57400}
parent 1e9ead8a
This diff is collapsed.
......@@ -812,14 +812,11 @@ FunctionLiteral* Parser::DoParseFunction(Isolate* isolate, ParseInfo* info,
SkipFunctionLiterals(info->function_literal_id() - 1);
}
// Pass `accept_IN=true` to ParseArrowFunctionLiteral --- This should
// not be observable, or else the preparser would have failed.
const bool accept_IN = true;
// Any destructuring assignments in the current FunctionState
// actually belong to the arrow function itself.
const int rewritable_length = 0;
Expression* expression =
ParseArrowFunctionLiteral(accept_IN, formals, rewritable_length);
ParseArrowFunctionLiteral(formals, rewritable_length);
// Scanning must end at the same position that was recorded
// previously. If not, parsing has been interrupted due to a stack
// overflow, at which point the partially parsed arrow function
......@@ -1153,7 +1150,8 @@ Statement* Parser::ParseExportDefault() {
default: {
int pos = position();
ExpressionClassifier classifier(this);
Expression* value = ParseAssignmentExpression(true);
AcceptINScope scope(this, true);
Expression* value = ParseAssignmentExpression();
ValidateExpression();
SetFunctionName(value, ast_value_factory()->default_string());
......@@ -3012,8 +3010,9 @@ void Parser::ParseFunction(
*num_parameters = formals.num_parameters();
*function_length = formals.function_length;
AcceptINScope scope(this, true);
ParseFunctionBody(body, function_name, pos, formals, kind, function_type,
FunctionBodyType::kBlock, true);
FunctionBodyType::kBlock);
RewriteDestructuringAssignments();
......
......@@ -302,8 +302,9 @@ PreParser::Expression PreParser::ParseFunctionLiteral(
PreParserScopedStatementList body(pointer_buffer());
int pos = function_token_pos == kNoSourcePosition ? peek_position()
: function_token_pos;
AcceptINScope scope(this, true);
ParseFunctionBody(&body, function_name, pos, formals, kind, function_type,
FunctionBodyType::kBlock, true);
FunctionBodyType::kBlock);
// Parsing the body may change the language mode in our scope.
language_mode = function_scope->language_mode();
......
......@@ -25,9 +25,14 @@ constexpr uint8_t length(const char* str) {
const uint8_t Token::string_length_[NUM_TOKENS] = {TOKEN_LIST(T, T, T)};
#undef T
#define T(name, string, precedence) precedence,
const int8_t Token::precedence_[NUM_TOKENS] = {TOKEN_LIST(T, T, T)};
#undef T
#define T1(name, string, precedence) \
((Token::name == Token::IN) ? 0 : precedence),
#define T2(name, string, precedence) precedence,
// precedence_[0] for accept_IN == false, precedence_[1] for accept_IN = true.
const int8_t Token::precedence_[2][NUM_TOKENS] = {{TOKEN_LIST(T1, T1, T1)},
{TOKEN_LIST(T2, T2, T2)}};
#undef T2
#undef T1
#define KT(a, b, c) 'T',
#define KK(a, b, c) 'K',
......
......@@ -326,16 +326,16 @@ class Token {
// Returns the precedence > 0 for binary and compare
// operators; returns 0 otherwise.
static int Precedence(Value token) {
static int Precedence(Value token, bool accept_IN) {
DCHECK_GT(NUM_TOKENS, token); // token is unsigned
return precedence_[token];
return precedence_[accept_IN][token];
}
private:
static const char* const name_[NUM_TOKENS];
static const char* const string_[NUM_TOKENS];
static const uint8_t string_length_[NUM_TOKENS];
static const int8_t precedence_[NUM_TOKENS];
static const int8_t precedence_[2][NUM_TOKENS];
static const char token_type[NUM_TOKENS];
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment