Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1044)

Unified Diff: src/parsing/parser.cc

Issue 1439693002: [runtime] Support Proxy setPrototypeOf trap (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@2015-11-09_new_Proxy_1417063011
Patch Set: merging with master Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/parsing/parser.h ('k') | src/parsing/pattern-rewriter.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parsing/parser.cc
diff --git a/src/parsing/parser.cc b/src/parsing/parser.cc
index c4f481083ceb6347941355933020480481e21027..7dc60cb2d53f4fc495c1c07680374be80bab1df5 100644
--- a/src/parsing/parser.cc
+++ b/src/parsing/parser.cc
@@ -101,15 +101,17 @@ RegExpBuilder::RegExpBuilder(Zone* zone)
terms_(),
alternatives_()
#ifdef DEBUG
- , last_added_(ADD_NONE)
+ ,
+ last_added_(ADD_NONE)
#endif
- {}
+{
+}
void RegExpBuilder::FlushCharacters() {
pending_empty_ = false;
if (characters_ != NULL) {
- RegExpTree* atom = new(zone()) RegExpAtom(characters_->ToConstVector());
+ RegExpTree* atom = new (zone()) RegExpAtom(characters_->ToConstVector());
characters_ = NULL;
text_.Add(atom, zone());
LAST(ADD_ATOM);
@@ -125,9 +127,8 @@ void RegExpBuilder::FlushText() {
} else if (num_text == 1) {
terms_.Add(text_.last(), zone());
} else {
- RegExpText* text = new(zone()) RegExpText(zone());
- for (int i = 0; i < num_text; i++)
- text_.Get(i)->AppendToText(text, zone());
+ RegExpText* text = new (zone()) RegExpText(zone());
+ for (int i = 0; i < num_text; i++) text_.Get(i)->AppendToText(text, zone());
terms_.Add(text, zone());
}
text_.Clear();
@@ -137,16 +138,14 @@ void RegExpBuilder::FlushText() {
void RegExpBuilder::AddCharacter(uc16 c) {
pending_empty_ = false;
if (characters_ == NULL) {
- characters_ = new(zone()) ZoneList<uc16>(4, zone());
+ characters_ = new (zone()) ZoneList<uc16>(4, zone());
}
characters_->Add(c, zone());
LAST(ADD_CHAR);
}
-void RegExpBuilder::AddEmpty() {
- pending_empty_ = true;
-}
+void RegExpBuilder::AddEmpty() { pending_empty_ = true; }
void RegExpBuilder::AddAtom(RegExpTree* term) {
@@ -172,9 +171,7 @@ void RegExpBuilder::AddAssertion(RegExpTree* assert) {
}
-void RegExpBuilder::NewAlternative() {
- FlushTerms();
-}
+void RegExpBuilder::NewAlternative() { FlushTerms(); }
void RegExpBuilder::FlushTerms() {
@@ -186,7 +183,7 @@ void RegExpBuilder::FlushTerms() {
} else if (num_terms == 1) {
alternative = terms_.last();
} else {
- alternative = new(zone()) RegExpAlternative(terms_.GetList(zone()));
+ alternative = new (zone()) RegExpAlternative(terms_.GetList(zone()));
}
alternatives_.Add(alternative, zone());
terms_.Clear();
@@ -199,7 +196,7 @@ RegExpTree* RegExpBuilder::ToRegExp() {
int num_alternatives = alternatives_.length();
if (num_alternatives == 0) return new (zone()) RegExpEmpty();
if (num_alternatives == 1) return alternatives_.last();
- return new(zone()) RegExpDisjunction(alternatives_.GetList(zone()));
+ return new (zone()) RegExpDisjunction(alternatives_.GetList(zone()));
}
@@ -217,11 +214,11 @@ void RegExpBuilder::AddQuantifierToAtom(
int num_chars = char_vector.length();
if (num_chars > 1) {
Vector<const uc16> prefix = char_vector.SubVector(0, num_chars - 1);
- text_.Add(new(zone()) RegExpAtom(prefix), zone());
+ text_.Add(new (zone()) RegExpAtom(prefix), zone());
char_vector = char_vector.SubVector(num_chars - 1, num_chars);
}
characters_ = NULL;
- atom = new(zone()) RegExpAtom(char_vector);
+ atom = new (zone()) RegExpAtom(char_vector);
FlushText();
} else if (text_.length() > 0) {
DCHECK(last_added_ == ADD_ATOM);
@@ -244,8 +241,8 @@ void RegExpBuilder::AddQuantifierToAtom(
UNREACHABLE();
return;
}
- terms_.Add(
- new(zone()) RegExpQuantifier(min, max, quantifier_type, atom), zone());
+ terms_.Add(new (zone()) RegExpQuantifier(min, max, quantifier_type, atom),
+ zone());
LAST(ADD_TERM);
}
@@ -286,8 +283,7 @@ bool ParseData::IsSane() {
if (functions_size < 0) return false;
if (functions_size % FunctionEntry::kSize != 0) return false;
// Check that the total size has room for header and function entries.
- int minimum_size =
- PreparseDataConstants::kHeaderSize + functions_size;
+ int minimum_size = PreparseDataConstants::kHeaderSize + functions_size;
if (data_length < minimum_size) return false;
return true;
}
@@ -409,9 +405,7 @@ class Target BASE_EMBEDDED {
*variable = this;
}
- ~Target() {
- *variable_ = previous_;
- }
+ ~Target() { *variable_ = previous_; }
Target* previous() { return previous_; }
BreakableStatement* statement() { return statement_; }
@@ -430,9 +424,7 @@ class TargetScope BASE_EMBEDDED {
*variable = NULL;
}
- ~TargetScope() {
- *variable_ = previous_;
- }
+ ~TargetScope() { *variable_ = previous_; }
private:
Target** variable_;
@@ -454,7 +446,7 @@ class TargetScope BASE_EMBEDDED {
#define DUMMY ) // to make indentation work
#undef DUMMY
-#define CHECK_FAILED /**/); \
+#define CHECK_FAILED /**/); \
if (failed_) return NULL; \
((void)0
#define DUMMY ) // to make indentation work
@@ -525,8 +517,7 @@ void ParserTraits::CheckAssigningFunctionLiteralToProperty(Expression* left,
}
-void ParserTraits::CheckPossibleEvalCall(Expression* expression,
- Scope* scope) {
+void ParserTraits::CheckPossibleEvalCall(Expression* expression, Scope* scope) {
VariableProxy* callee = expression->AsVariableProxy();
if (callee != NULL &&
callee->raw_name() == parser_->ast_value_factory()->eval_string()) {
@@ -636,13 +627,13 @@ Expression* ParserTraits::BuildUnaryExpression(Expression* expression,
}
// The same idea for '-foo' => 'foo*(-1)'.
if (op == Token::SUB) {
- return factory->NewBinaryOperation(
- Token::MUL, expression, factory->NewNumberLiteral(-1, pos), pos);
+ return factory->NewBinaryOperation(Token::MUL, expression,
+ factory->NewNumberLiteral(-1, pos), pos);
}
// ...and one more time for '~foo' => 'foo^(~0)'.
if (op == Token::BIT_NOT) {
- return factory->NewBinaryOperation(
- Token::BIT_XOR, expression, factory->NewNumberLiteral(~0, pos), pos);
+ return factory->NewBinaryOperation(Token::BIT_XOR, expression,
+ factory->NewNumberLiteral(~0, pos), pos);
}
return factory->NewUnaryOperation(op, expression, pos);
}
@@ -1051,7 +1042,7 @@ FunctionLiteral* Parser::DoParseProgram(ParseInfo* info) {
// Don't count the mode in the use counters--give the program a chance
// to enable script/module-wide strict/strong mode below.
scope_->SetLanguageMode(info->language_mode());
- ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone());
+ ZoneList<Statement*>* body = new (zone()) ZoneList<Statement*>(16, zone());
bool ok = true;
int beg_pos = scanner()->location().beg_pos;
if (info->is_module()) {
@@ -1080,10 +1071,11 @@ FunctionLiteral* Parser::DoParseProgram(ParseInfo* info) {
}
if (ok && info->parse_restriction() == ONLY_SINGLE_FUNCTION_LITERAL) {
- if (body->length() != 1 ||
- !body->at(0)->IsExpressionStatement() ||
- !body->at(0)->AsExpressionStatement()->
- expression()->IsFunctionLiteral()) {
+ if (body->length() != 1 || !body->at(0)->IsExpressionStatement() ||
+ !body->at(0)
+ ->AsExpressionStatement()
+ ->expression()
+ ->IsFunctionLiteral()) {
ReportMessage(MessageTemplate::kSingleFunctionLiteral);
ok = false;
}
@@ -1127,13 +1119,11 @@ FunctionLiteral* Parser::ParseLazy(Isolate* isolate, ParseInfo* info) {
if (source->IsExternalTwoByteString()) {
ExternalTwoByteStringUtf16CharacterStream stream(
Handle<ExternalTwoByteString>::cast(source),
- shared_info->start_position(),
- shared_info->end_position());
+ shared_info->start_position(), shared_info->end_position());
result = ParseLazy(isolate, info, &stream);
} else {
- GenericStringUtf16CharacterStream stream(source,
- shared_info->start_position(),
- shared_info->end_position());
+ GenericStringUtf16CharacterStream stream(
+ source, shared_info->start_position(), shared_info->end_position());
result = ParseLazy(isolate, info, &stream);
}
@@ -1183,11 +1173,12 @@ FunctionLiteral* Parser::ParseLazy(Isolate* isolate, ParseInfo* info,
DCHECK(is_sloppy(scope->language_mode()) ||
is_strict(info->language_mode()));
DCHECK(info->language_mode() == shared_info->language_mode());
- FunctionLiteral::FunctionType function_type = shared_info->is_expression()
- ? (shared_info->is_anonymous()
- ? FunctionLiteral::ANONYMOUS_EXPRESSION
- : FunctionLiteral::NAMED_EXPRESSION)
- : FunctionLiteral::DECLARATION;
+ FunctionLiteral::FunctionType function_type =
+ shared_info->is_expression()
+ ? (shared_info->is_anonymous()
+ ? FunctionLiteral::ANONYMOUS_EXPRESSION
+ : FunctionLiteral::NAMED_EXPRESSION)
+ : FunctionLiteral::DECLARATION;
bool ok = true;
if (shared_info->is_arrow()) {
@@ -1278,7 +1269,7 @@ void* Parser::ParseStatementList(ZoneList<Statement*>* body, int end_token,
TargetScope scope(&this->target_stack_);
DCHECK(body != NULL);
- bool directive_prologue = true; // Parsing directive prologue.
+ bool directive_prologue = true; // Parsing directive prologue.
while (peek() != end_token) {
if (directive_prologue && peek() != Token::STRING) {
@@ -1309,7 +1300,7 @@ void* Parser::ParseStatementList(ZoneList<Statement*>* body, int end_token,
}
if (stat == NULL || stat->IsEmpty()) {
- directive_prologue = false; // End of directive prologue.
+ directive_prologue = false; // End of directive prologue.
continue;
}
@@ -2238,8 +2229,8 @@ Statement* Parser::ParseFunctionDeclaration(
int pos = position();
bool is_generator = Check(Token::MUL);
bool is_strict_reserved = false;
- const AstRawString* name = ParseIdentifierOrStrictReservedWord(
- &is_strict_reserved, CHECK_OK);
+ const AstRawString* name =
+ ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK);
if (fni_ != NULL) {
fni_->Enter();
@@ -2356,14 +2347,14 @@ Block* Parser::ParseBlock(ZoneList<const AstRawString*>* labels, bool* ok) {
// '{' StatementList '}'
// Construct block expecting 16 statements.
- Block* body =
- factory()->NewBlock(labels, 16, false, RelocInfo::kNoPosition);
+ Block* body = factory()->NewBlock(labels, 16, false, RelocInfo::kNoPosition);
Scope* block_scope = NewScope(scope_, BLOCK_SCOPE);
// Parse the statements and collect escaping labels.
Expect(Token::LBRACE, CHECK_OK);
block_scope->set_start_position(scanner()->location().beg_pos);
- { BlockState block_state(&scope_, block_scope);
+ {
+ BlockState block_state(&scope_, block_scope);
Target target(&this->target_stack_, body);
while (peek() != Token::RBRACE) {
@@ -2592,7 +2583,7 @@ static bool ContainsLabel(ZoneList<const AstRawString*>* labels,
const AstRawString* label) {
DCHECK(label != NULL);
if (labels != NULL) {
- for (int i = labels->length(); i-- > 0; ) {
+ for (int i = labels->length(); i-- > 0;) {
if (labels->at(i) == label) {
return true;
}
@@ -2624,7 +2615,7 @@ Statement* Parser::ParseExpressionOrLabelledStatement(
case Token::THIS:
if (!FLAG_strong_this) break;
- // Fall through.
+ // Fall through.
case Token::SUPER:
if (is_strong(language_mode()) &&
IsClassConstructor(function_state_->kind())) {
@@ -2665,8 +2656,7 @@ Statement* Parser::ParseExpressionOrLabelledStatement(
bool starts_with_idenfifier = peek_any_identifier();
Expression* expr = ParseExpression(true, CHECK_OK);
if (peek() == Token::COLON && starts_with_idenfifier && expr != NULL &&
- expr->AsVariableProxy() != NULL &&
- !expr->AsVariableProxy()->is_this()) {
+ expr->AsVariableProxy() != NULL && !expr->AsVariableProxy()->is_this()) {
// Expression is a single identifier, and not, e.g., a parenthesized
// identifier.
VariableProxy* var = expr->AsVariableProxy();
@@ -2682,7 +2672,7 @@ Statement* Parser::ParseExpressionOrLabelledStatement(
return NULL;
}
if (labels == NULL) {
- labels = new(zone()) ZoneList<const AstRawString*>(4, zone());
+ labels = new (zone()) ZoneList<const AstRawString*>(4, zone());
}
labels->Add(label, zone());
// Remove the "ghost" variable that turned out to be a label
@@ -2738,8 +2728,8 @@ IfStatement* Parser::ParseIfStatement(ZoneList<const AstRawString*>* labels,
} else {
else_statement = factory()->NewEmptyStatement(RelocInfo::kNoPosition);
}
- return factory()->NewIfStatement(
- condition, then_statement, else_statement, pos);
+ return factory()->NewIfStatement(condition, then_statement, else_statement,
+ pos);
}
@@ -2751,8 +2741,8 @@ Statement* Parser::ParseContinueStatement(bool* ok) {
Expect(Token::CONTINUE, CHECK_OK);
const AstRawString* label = NULL;
Token::Value tok = peek();
- if (!scanner()->HasAnyLineTerminatorBeforeNext() &&
- tok != Token::SEMICOLON && tok != Token::RBRACE && tok != Token::EOS) {
+ if (!scanner()->HasAnyLineTerminatorBeforeNext() && tok != Token::SEMICOLON &&
+ tok != Token::RBRACE && tok != Token::EOS) {
// ECMA allows "eval" or "arguments" as labels even in strict mode.
label = ParseIdentifier(kAllowRestrictedIdentifiers, CHECK_OK);
}
@@ -2781,8 +2771,8 @@ Statement* Parser::ParseBreakStatement(ZoneList<const AstRawString*>* labels,
Expect(Token::BREAK, CHECK_OK);
const AstRawString* label = NULL;
Token::Value tok = peek();
- if (!scanner()->HasAnyLineTerminatorBeforeNext() &&
- tok != Token::SEMICOLON && tok != Token::RBRACE && tok != Token::EOS) {
+ if (!scanner()->HasAnyLineTerminatorBeforeNext() && tok != Token::SEMICOLON &&
+ tok != Token::RBRACE && tok != Token::EOS) {
// ECMA allows "eval" or "arguments" as labels even in strict mode.
label = ParseIdentifier(kAllowRestrictedIdentifiers, CHECK_OK);
}
@@ -2823,10 +2813,8 @@ Statement* Parser::ParseReturnStatement(bool* ok) {
Token::Value tok = peek();
Statement* result;
Expression* return_value;
- if (scanner()->HasAnyLineTerminatorBeforeNext() ||
- tok == Token::SEMICOLON ||
- tok == Token::RBRACE ||
- tok == Token::EOS) {
+ if (scanner()->HasAnyLineTerminatorBeforeNext() || tok == Token::SEMICOLON ||
+ tok == Token::RBRACE || tok == Token::EOS) {
if (IsSubclassConstructor(function_state_->kind())) {
return_value = ThisExpression(scope_, factory(), loc.beg_pos);
} else {
@@ -2855,8 +2843,8 @@ Statement* Parser::ParseReturnStatement(bool* ok) {
//
// return (temp = expr) === undefined ? this :
// %_IsSpecObject(temp) ? temp : throw new TypeError(...);
- Variable* temp = scope_->NewTemporary(
- ast_value_factory()->empty_string());
+ Variable* temp =
+ scope_->NewTemporary(ast_value_factory()->empty_string());
Assignment* assign = factory()->NewAssignment(
Token::ASSIGN, factory()->NewVariableProxy(temp), return_value, pos);
@@ -2892,8 +2880,8 @@ Statement* Parser::ParseReturnStatement(bool* ok) {
if (is_generator()) {
Expression* generator = factory()->NewVariableProxy(
function_state_->generator_object_variable());
- Expression* yield = factory()->NewYield(
- generator, return_value, Yield::kFinal, loc.beg_pos);
+ Expression* yield = factory()->NewYield(generator, return_value,
+ Yield::kFinal, loc.beg_pos);
result = factory()->NewExpressionStatement(yield, loc.beg_pos);
} else {
result = factory()->NewReturnStatement(return_value, loc.beg_pos);
@@ -2930,7 +2918,8 @@ Statement* Parser::ParseWithStatement(ZoneList<const AstRawString*>* labels,
scope_->DeclarationScope()->RecordWithStatement();
Scope* with_scope = NewScope(scope_, WITH_SCOPE);
Block* body;
- { BlockState block_state(&scope_, with_scope);
+ {
+ BlockState block_state(&scope_, with_scope);
with_scope->set_start_position(scanner()->peek_location().beg_pos);
// The body of the with statement must be enclosed in an additional
@@ -2975,10 +2964,9 @@ CaseClause* Parser::ParseCaseClause(bool* default_seen_ptr, bool* ok) {
Expect(Token::COLON, CHECK_OK);
int pos = position();
ZoneList<Statement*>* statements =
- new(zone()) ZoneList<Statement*>(5, zone());
+ new (zone()) ZoneList<Statement*>(5, zone());
Statement* stat = NULL;
- while (peek() != Token::CASE &&
- peek() != Token::DEFAULT &&
+ while (peek() != Token::CASE && peek() != Token::DEFAULT &&
peek() != Token::RBRACE) {
stat = ParseStatementListItem(CHECK_OK);
statements->Add(stat, zone());
@@ -3087,8 +3075,8 @@ Statement* Parser::ParseThrowStatement(bool* ok) {
Expression* exception = ParseExpression(true, CHECK_OK);
ExpectSemicolon(CHECK_OK);
- return factory()->NewExpressionStatement(
- factory()->NewThrow(exception, pos), pos);
+ return factory()->NewExpressionStatement(factory()->NewThrow(exception, pos),
+ pos);
}
@@ -3320,16 +3308,15 @@ Expression* Parser::BuildIteratorNextResult(Expression* iterator,
void Parser::InitializeForEachStatement(ForEachStatement* stmt,
- Expression* each,
- Expression* subject,
+ Expression* each, Expression* subject,
Statement* body) {
ForOfStatement* for_of = stmt->AsForOfStatement();
if (for_of != NULL) {
- Variable* iterator = scope_->NewTemporary(
- ast_value_factory()->dot_iterator_string());
- Variable* result = scope_->NewTemporary(
- ast_value_factory()->dot_result_string());
+ Variable* iterator =
+ scope_->NewTemporary(ast_value_factory()->dot_iterator_string());
+ Variable* result =
+ scope_->NewTemporary(ast_value_factory()->dot_result_string());
Expression* assign_iterator;
Expression* next_result;
@@ -3355,8 +3342,8 @@ void Parser::InitializeForEachStatement(ForEachStatement* stmt,
Expression* done_literal = factory()->NewStringLiteral(
ast_value_factory()->done_string(), RelocInfo::kNoPosition);
Expression* result_proxy = factory()->NewVariableProxy(result);
- result_done = factory()->NewProperty(
- result_proxy, done_literal, RelocInfo::kNoPosition);
+ result_done = factory()->NewProperty(result_proxy, done_literal,
+ RelocInfo::kNoPosition);
}
// each = result.value
@@ -3370,11 +3357,8 @@ void Parser::InitializeForEachStatement(ForEachStatement* stmt,
RelocInfo::kNoPosition);
}
- for_of->Initialize(each, subject, body,
- assign_iterator,
- next_result,
- result_done,
- assign_each);
+ for_of->Initialize(each, subject, body, assign_iterator, next_result,
+ result_done, assign_each);
} else {
stmt->Initialize(each, subject, body);
}
@@ -3442,8 +3426,8 @@ Statement* Parser::DesugarLexicalBindingsInForStatement(
VariableProxy* temp_proxy = factory()->NewVariableProxy(temp);
Assignment* assignment = factory()->NewAssignment(
Token::ASSIGN, temp_proxy, proxy, RelocInfo::kNoPosition);
- Statement* assignment_statement = factory()->NewExpressionStatement(
- assignment, RelocInfo::kNoPosition);
+ Statement* assignment_statement =
+ factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition);
outer_block->statements()->Add(assignment_statement, zone());
temps.Add(temp, zone());
}
@@ -3722,8 +3706,8 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels,
// let x; // for TDZ
// }
- Variable* temp = scope_->NewTemporary(
- ast_value_factory()->dot_for_string());
+ Variable* temp =
+ scope_->NewTemporary(ast_value_factory()->dot_for_string());
ForEachStatement* loop =
factory()->NewForEachStatement(mode, labels, stmt_pos);
Target target(&this->target_stack_, loop);
@@ -3904,9 +3888,9 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels,
Statement* result = NULL;
if (lexical_bindings.length() > 0) {
scope_ = for_scope;
- result = DesugarLexicalBindingsInForStatement(
- inner_scope, is_const, &lexical_bindings, loop, init, cond,
- next, body, CHECK_OK);
+ result = DesugarLexicalBindingsInForStatement(inner_scope, is_const,
+ &lexical_bindings, loop, init,
+ cond, next, body, CHECK_OK);
scope_ = saved_scope;
for_scope->set_end_position(scanner()->location().end_pos);
} else {
@@ -4105,8 +4089,8 @@ DoExpression* Parser::ParseDoExpression(bool* ok) {
void ParserTraits::ParseArrowFunctionFormalParameterList(
ParserFormalParameters* parameters, Expression* expr,
- const Scanner::Location& params_loc,
- Scanner::Location* duplicate_loc, bool* ok) {
+ const Scanner::Location& params_loc, Scanner::Location* duplicate_loc,
+ bool* ok) {
if (expr->IsEmptyParentheses()) return;
ParseArrowFunctionFormalParameters(parameters, expr, params_loc, ok);
@@ -4161,8 +4145,8 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
// Setter ::
// '(' PropertySetParameterList ')' '{' FunctionBody '}'
- int pos = function_token_pos == RelocInfo::kNoPosition
- ? peek_position() : function_token_pos;
+ int pos = function_token_pos == RelocInfo::kNoPosition ? peek_position()
+ : function_token_pos;
bool is_generator = IsGeneratorFunction(kind);
@@ -4253,9 +4237,8 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
Expect(Token::RPAREN, CHECK_OK);
int formals_end_position = scanner()->location().end_pos;
- CheckArityRestrictions(arity, arity_restriction,
- formals.has_rest, start_position,
- formals_end_position, CHECK_OK);
+ CheckArityRestrictions(arity, arity_restriction, formals.has_rest,
+ start_position, formals_end_position, CHECK_OK);
Expect(Token::LBRACE, CHECK_OK);
// Determine if the function can be parsed lazily. Lazy parsing is different
@@ -4562,9 +4545,9 @@ Block* Parser::BuildParameterInitializationBlock(
factory()->NewVariableProxy(parameters.scope->parameter(i)),
factory()->NewUndefinedLiteral(RelocInfo::kNoPosition),
RelocInfo::kNoPosition);
- initial_value = factory()->NewConditional(
- condition, parameter.initializer, initial_value,
- RelocInfo::kNoPosition);
+ initial_value =
+ factory()->NewConditional(condition, parameter.initializer,
+ initial_value, RelocInfo::kNoPosition);
descriptor.initialization_pos = parameter.initializer->position();
initializer_position = parameter.initializer_end_position;
} else if (parameter.is_rest) {
@@ -4683,7 +4666,7 @@ ZoneList<Statement*>* Parser::ParseEagerFunctionBody(
// Everything inside an eagerly parsed function will be parsed eagerly
// (see comment above).
ParsingModeScope parsing_mode(this, PARSE_EAGERLY);
- ZoneList<Statement*>* result = new(zone()) ZoneList<Statement*>(8, zone());
+ ZoneList<Statement*>* result = new (zone()) ZoneList<Statement*>(8, zone());
static const int kFunctionNameAssignmentIndex = 0;
if (function_type == FunctionLiteral::NAMED_EXPRESSION) {
@@ -4715,7 +4698,7 @@ ZoneList<Statement*>* Parser::ParseEagerFunctionBody(
// For generators, allocate and yield an iterator on function entry.
if (IsGeneratorFunction(kind)) {
ZoneList<Expression*>* arguments =
- new(zone()) ZoneList<Expression*>(0, zone());
+ new (zone()) ZoneList<Expression*>(0, zone());
CallRuntime* allocation = factory()->NewCallRuntime(
Runtime::kCreateJSGeneratorObject, arguments, pos);
VariableProxy* init_proxy = factory()->NewVariableProxy(
@@ -4724,10 +4707,11 @@ ZoneList<Statement*>* Parser::ParseEagerFunctionBody(
Token::INIT, init_proxy, allocation, RelocInfo::kNoPosition);
VariableProxy* get_proxy = factory()->NewVariableProxy(
function_state_->generator_object_variable());
- Yield* yield = factory()->NewYield(
- get_proxy, assignment, Yield::kInitial, RelocInfo::kNoPosition);
- body->Add(factory()->NewExpressionStatement(
- yield, RelocInfo::kNoPosition), zone());
+ Yield* yield = factory()->NewYield(get_proxy, assignment, Yield::kInitial,
+ RelocInfo::kNoPosition);
+ body->Add(
+ factory()->NewExpressionStatement(yield, RelocInfo::kNoPosition),
+ zone());
}
ParseStatementList(body, Token::RBRACE, CHECK_OK);
@@ -4739,8 +4723,9 @@ ZoneList<Statement*>* Parser::ParseEagerFunctionBody(
factory()->NewUndefinedLiteral(RelocInfo::kNoPosition);
Yield* yield = factory()->NewYield(get_proxy, undefined, Yield::kFinal,
RelocInfo::kNoPosition);
- body->Add(factory()->NewExpressionStatement(
- yield, RelocInfo::kNoPosition), zone());
+ body->Add(
+ factory()->NewExpressionStatement(yield, RelocInfo::kNoPosition),
+ zone());
}
if (IsSubclassConstructor(kind)) {
@@ -4748,7 +4733,7 @@ ZoneList<Statement*>* Parser::ParseEagerFunctionBody(
factory()->NewReturnStatement(
this->ThisExpression(scope_, factory(), RelocInfo::kNoPosition),
RelocInfo::kNoPosition),
- zone());
+ zone());
}
}
@@ -4946,8 +4931,8 @@ Expression* Parser::ParseV8Intrinsic(bool* ok) {
int pos = peek_position();
Expect(Token::MOD, CHECK_OK);
// Allow "eval" or "arguments" for backward compatibility.
- const AstRawString* name = ParseIdentifier(kAllowRestrictedIdentifiers,
- CHECK_OK);
+ const AstRawString* name =
+ ParseIdentifier(kAllowRestrictedIdentifiers, CHECK_OK);
Scanner::Location spread_pos;
ExpressionClassifier classifier;
ZoneList<Expression*>* args =
@@ -5017,9 +5002,10 @@ void Parser::CheckConflictingVarDeclarations(Scope* scope, bool* ok) {
// In ES6, conflicting variable bindings are early errors.
const AstRawString* name = decl->proxy()->raw_name();
int position = decl->proxy()->position();
- Scanner::Location location = position == RelocInfo::kNoPosition
- ? Scanner::Location::invalid()
- : Scanner::Location(position, position + 1);
+ Scanner::Location location =
+ position == RelocInfo::kNoPosition
+ ? Scanner::Location::invalid()
+ : Scanner::Location(position, position + 1);
ParserTraits::ReportMessageAt(location, MessageTemplate::kVarRedeclaration,
name);
*ok = false;
@@ -5043,10 +5029,10 @@ void Parser::InsertShadowingVarBindingInitializers(Block* inner_block) {
if (parameter == nullptr) continue;
VariableProxy* to = inner_scope->NewUnresolved(factory(), name);
VariableProxy* from = factory()->NewVariableProxy(parameter);
- Expression* assignment = factory()->NewAssignment(
- Token::ASSIGN, to, from, RelocInfo::kNoPosition);
- Statement* statement = factory()->NewExpressionStatement(
- assignment, RelocInfo::kNoPosition);
+ Expression* assignment = factory()->NewAssignment(Token::ASSIGN, to, from,
+ RelocInfo::kNoPosition);
+ Statement* statement =
+ factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition);
inner_block->statements()->InsertAt(0, statement, zone());
}
}
@@ -5237,9 +5223,7 @@ void RegExpParser::Advance(int dist) {
}
-bool RegExpParser::simple() {
- return simple_;
-}
+bool RegExpParser::simple() { return simple_; }
bool RegExpParser::IsSyntaxCharacter(uc32 c) {
@@ -5292,342 +5276,357 @@ RegExpTree* RegExpParser::ParseDisjunction() {
RegExpBuilder* builder = initial_state.builder();
while (true) {
switch (current()) {
- case kEndMarker:
- if (state->IsSubexpression()) {
- // Inside a parenthesized group when hitting end of input.
- ReportError(CStrVector("Unterminated group") CHECK_FAILED);
- }
- DCHECK_EQ(INITIAL, state->group_type());
- // Parsing completed successfully.
- return builder->ToRegExp();
- case ')': {
- if (!state->IsSubexpression()) {
- ReportError(CStrVector("Unmatched ')'") CHECK_FAILED);
- }
- DCHECK_NE(INITIAL, state->group_type());
+ case kEndMarker:
+ if (state->IsSubexpression()) {
+ // Inside a parenthesized group when hitting end of input.
+ ReportError(CStrVector("Unterminated group") CHECK_FAILED);
+ }
+ DCHECK_EQ(INITIAL, state->group_type());
+ // Parsing completed successfully.
+ return builder->ToRegExp();
+ case ')': {
+ if (!state->IsSubexpression()) {
+ ReportError(CStrVector("Unmatched ')'") CHECK_FAILED);
+ }
+ DCHECK_NE(INITIAL, state->group_type());
- Advance();
- // End disjunction parsing and convert builder content to new single
- // regexp atom.
- RegExpTree* body = builder->ToRegExp();
-
- int end_capture_index = captures_started();
-
- int capture_index = state->capture_index();
- SubexpressionType group_type = state->group_type();
-
- // Build result of subexpression.
- if (group_type == CAPTURE) {
- RegExpCapture* capture = GetCapture(capture_index);
- capture->set_body(body);
- body = capture;
- } else if (group_type != GROUPING) {
- DCHECK(group_type == POSITIVE_LOOKAROUND ||
- group_type == NEGATIVE_LOOKAROUND);
- bool is_positive = (group_type == POSITIVE_LOOKAROUND);
- body = new (zone()) RegExpLookaround(
- body, is_positive, end_capture_index - capture_index, capture_index,
- state->lookaround_type());
- }
+ Advance();
+ // End disjunction parsing and convert builder content to new single
+ // regexp atom.
+ RegExpTree* body = builder->ToRegExp();
+
+ int end_capture_index = captures_started();
+
+ int capture_index = state->capture_index();
+ SubexpressionType group_type = state->group_type();
+
+ // Build result of subexpression.
+ if (group_type == CAPTURE) {
+ RegExpCapture* capture = GetCapture(capture_index);
+ capture->set_body(body);
+ body = capture;
+ } else if (group_type != GROUPING) {
+ DCHECK(group_type == POSITIVE_LOOKAROUND ||
+ group_type == NEGATIVE_LOOKAROUND);
+ bool is_positive = (group_type == POSITIVE_LOOKAROUND);
+ body = new (zone()) RegExpLookaround(
+ body, is_positive, end_capture_index - capture_index,
+ capture_index, state->lookaround_type());
+ }
- // Restore previous state.
- state = state->previous_state();
- builder = state->builder();
+ // Restore previous state.
+ state = state->previous_state();
+ builder = state->builder();
- builder->AddAtom(body);
- // For compatability with JSC and ES3, we allow quantifiers after
- // lookaheads, and break in all cases.
- break;
- }
- case '|': {
- Advance();
- builder->NewAlternative();
- continue;
- }
- case '*':
- case '+':
- case '?':
- return ReportError(CStrVector("Nothing to repeat"));
- case '^': {
- Advance();
- if (multiline_) {
- builder->AddAssertion(
- new(zone()) RegExpAssertion(RegExpAssertion::START_OF_LINE));
- } else {
- builder->AddAssertion(
- new(zone()) RegExpAssertion(RegExpAssertion::START_OF_INPUT));
- set_contains_anchor();
+ builder->AddAtom(body);
+ // For compatability with JSC and ES3, we allow quantifiers after
+ // lookaheads, and break in all cases.
+ break;
}
- continue;
- }
- case '$': {
- Advance();
- RegExpAssertion::AssertionType assertion_type =
- multiline_ ? RegExpAssertion::END_OF_LINE :
- RegExpAssertion::END_OF_INPUT;
- builder->AddAssertion(new(zone()) RegExpAssertion(assertion_type));
- continue;
- }
- case '.': {
- Advance();
- // everything except \x0a, \x0d, \u2028 and \u2029
- ZoneList<CharacterRange>* ranges =
- new(zone()) ZoneList<CharacterRange>(2, zone());
- CharacterRange::AddClassEscape('.', ranges, zone());
- RegExpTree* atom = new(zone()) RegExpCharacterClass(ranges, false);
- builder->AddAtom(atom);
- break;
- }
- case '(': {
- SubexpressionType subexpr_type = CAPTURE;
- RegExpLookaround::Type lookaround_type = state->lookaround_type();
- Advance();
- if (current() == '?') {
- switch (Next()) {
- case ':':
- subexpr_type = GROUPING;
- break;
- case '=':
- lookaround_type = RegExpLookaround::LOOKAHEAD;
- subexpr_type = POSITIVE_LOOKAROUND;
- break;
- case '!':
- lookaround_type = RegExpLookaround::LOOKAHEAD;
- subexpr_type = NEGATIVE_LOOKAROUND;
- break;
- case '<':
- if (FLAG_harmony_regexp_lookbehind) {
- Advance();
- lookaround_type = RegExpLookaround::LOOKBEHIND;
- if (Next() == '=') {
- subexpr_type = POSITIVE_LOOKAROUND;
- break;
- } else if (Next() == '!') {
- subexpr_type = NEGATIVE_LOOKAROUND;
- break;
- }
- }
- // Fall through.
- default:
- ReportError(CStrVector("Invalid group") CHECK_FAILED);
- break;
- }
- Advance(2);
- } else {
- if (captures_started_ >= kMaxCaptures) {
- ReportError(CStrVector("Too many captures") CHECK_FAILED);
- }
- captures_started_++;
+ case '|': {
+ Advance();
+ builder->NewAlternative();
+ continue;
}
- // Store current state and begin new disjunction parsing.
- state = new (zone()) RegExpParserState(
- state, subexpr_type, lookaround_type, captures_started_, zone());
- builder = state->builder();
- continue;
- }
- case '[': {
- RegExpTree* atom = ParseCharacterClass(CHECK_FAILED);
- builder->AddAtom(atom);
- break;
- }
- // Atom ::
- // \ AtomEscape
- case '\\':
- switch (Next()) {
- case kEndMarker:
- return ReportError(CStrVector("\\ at end of pattern"));
- case 'b':
- Advance(2);
- builder->AddAssertion(
- new(zone()) RegExpAssertion(RegExpAssertion::BOUNDARY));
+ case '*':
+ case '+':
+ case '?':
+ return ReportError(CStrVector("Nothing to repeat"));
+ case '^': {
+ Advance();
+ if (multiline_) {
+ builder->AddAssertion(
+ new (zone()) RegExpAssertion(RegExpAssertion::START_OF_LINE));
+ } else {
+ builder->AddAssertion(
+ new (zone()) RegExpAssertion(RegExpAssertion::START_OF_INPUT));
+ set_contains_anchor();
+ }
continue;
- case 'B':
- Advance(2);
- builder->AddAssertion(
- new(zone()) RegExpAssertion(RegExpAssertion::NON_BOUNDARY));
+ }
+ case '$': {
+ Advance();
+ RegExpAssertion::AssertionType assertion_type =
+ multiline_ ? RegExpAssertion::END_OF_LINE
+ : RegExpAssertion::END_OF_INPUT;
+ builder->AddAssertion(new (zone()) RegExpAssertion(assertion_type));
continue;
- // AtomEscape ::
- // CharacterClassEscape
- //
- // CharacterClassEscape :: one of
- // d D s S w W
- case 'd': case 'D': case 's': case 'S': case 'w': case 'W': {
- uc32 c = Next();
- Advance(2);
+ }
+ case '.': {
+ Advance();
+ // everything except \x0a, \x0d, \u2028 and \u2029
ZoneList<CharacterRange>* ranges =
- new(zone()) ZoneList<CharacterRange>(2, zone());
- CharacterRange::AddClassEscape(c, ranges, zone());
- RegExpTree* atom = new(zone()) RegExpCharacterClass(ranges, false);
+ new (zone()) ZoneList<CharacterRange>(2, zone());
+ CharacterRange::AddClassEscape('.', ranges, zone());
+ RegExpTree* atom = new (zone()) RegExpCharacterClass(ranges, false);
builder->AddAtom(atom);
break;
}
- case '1': case '2': case '3': case '4': case '5': case '6':
- case '7': case '8': case '9': {
- int index = 0;
- if (ParseBackReferenceIndex(&index)) {
- if (state->IsInsideCaptureGroup(index)) {
- // The backreference is inside the capture group it refers to.
- // Nothing can possibly have been captured yet.
- builder->AddEmpty();
- } else {
- RegExpCapture* capture = GetCapture(index);
- RegExpTree* atom = new (zone()) RegExpBackReference(capture);
- builder->AddAtom(atom);
+ case '(': {
+ SubexpressionType subexpr_type = CAPTURE;
+ RegExpLookaround::Type lookaround_type = state->lookaround_type();
+ Advance();
+ if (current() == '?') {
+ switch (Next()) {
+ case ':':
+ subexpr_type = GROUPING;
+ break;
+ case '=':
+ lookaround_type = RegExpLookaround::LOOKAHEAD;
+ subexpr_type = POSITIVE_LOOKAROUND;
+ break;
+ case '!':
+ lookaround_type = RegExpLookaround::LOOKAHEAD;
+ subexpr_type = NEGATIVE_LOOKAROUND;
+ break;
+ case '<':
+ if (FLAG_harmony_regexp_lookbehind) {
+ Advance();
+ lookaround_type = RegExpLookaround::LOOKBEHIND;
+ if (Next() == '=') {
+ subexpr_type = POSITIVE_LOOKAROUND;
+ break;
+ } else if (Next() == '!') {
+ subexpr_type = NEGATIVE_LOOKAROUND;
+ break;
+ }
+ }
+ // Fall through.
+ default:
+ ReportError(CStrVector("Invalid group") CHECK_FAILED);
+ break;
}
- break;
- }
- uc32 first_digit = Next();
- if (first_digit == '8' || first_digit == '9') {
- // If the 'u' flag is present, only syntax characters can be escaped,
- // no other identity escapes are allowed. If the 'u' flag is not
- // present, all identity escapes are allowed.
- if (!FLAG_harmony_unicode_regexps || !unicode_) {
- builder->AddCharacter(first_digit);
- Advance(2);
- } else {
- return ReportError(CStrVector("Invalid escape"));
+ Advance(2);
+ } else {
+ if (captures_started_ >= kMaxCaptures) {
+ ReportError(CStrVector("Too many captures") CHECK_FAILED);
}
- break;
+ captures_started_++;
}
+ // Store current state and begin new disjunction parsing.
+ state = new (zone()) RegExpParserState(
+ state, subexpr_type, lookaround_type, captures_started_, zone());
+ builder = state->builder();
+ continue;
}
- // FALLTHROUGH
- case '0': {
- Advance();
- uc32 octal = ParseOctalLiteral();
- builder->AddCharacter(octal);
- break;
- }
- // ControlEscape :: one of
- // f n r t v
- case 'f':
- Advance(2);
- builder->AddCharacter('\f');
- break;
- case 'n':
- Advance(2);
- builder->AddCharacter('\n');
- break;
- case 'r':
- Advance(2);
- builder->AddCharacter('\r');
- break;
- case 't':
- Advance(2);
- builder->AddCharacter('\t');
- break;
- case 'v':
- Advance(2);
- builder->AddCharacter('\v');
- break;
- case 'c': {
- Advance();
- uc32 controlLetter = Next();
- // Special case if it is an ASCII letter.
- // Convert lower case letters to uppercase.
- uc32 letter = controlLetter & ~('a' ^ 'A');
- if (letter < 'A' || 'Z' < letter) {
- // controlLetter is not in range 'A'-'Z' or 'a'-'z'.
- // This is outside the specification. We match JSC in
- // reading the backslash as a literal character instead
- // of as starting an escape.
- builder->AddCharacter('\\');
- } else {
- Advance(2);
- builder->AddCharacter(controlLetter & 0x1f);
- }
+ case '[': {
+ RegExpTree* atom = ParseCharacterClass(CHECK_FAILED);
+ builder->AddAtom(atom);
break;
}
- case 'x': {
- Advance(2);
- uc32 value;
- if (ParseHexEscape(2, &value)) {
- builder->AddCharacter(value);
- } else if (!FLAG_harmony_unicode_regexps || !unicode_) {
- builder->AddCharacter('x');
- } else {
- // If the 'u' flag is present, invalid escapes are not treated as
- // identity escapes.
- return ReportError(CStrVector("Invalid escape"));
+ // Atom ::
+ // \ AtomEscape
+ case '\\':
+ switch (Next()) {
+ case kEndMarker:
+ return ReportError(CStrVector("\\ at end of pattern"));
+ case 'b':
+ Advance(2);
+ builder->AddAssertion(
+ new (zone()) RegExpAssertion(RegExpAssertion::BOUNDARY));
+ continue;
+ case 'B':
+ Advance(2);
+ builder->AddAssertion(
+ new (zone()) RegExpAssertion(RegExpAssertion::NON_BOUNDARY));
+ continue;
+ // AtomEscape ::
+ // CharacterClassEscape
+ //
+ // CharacterClassEscape :: one of
+ // d D s S w W
+ case 'd':
+ case 'D':
+ case 's':
+ case 'S':
+ case 'w':
+ case 'W': {
+ uc32 c = Next();
+ Advance(2);
+ ZoneList<CharacterRange>* ranges =
+ new (zone()) ZoneList<CharacterRange>(2, zone());
+ CharacterRange::AddClassEscape(c, ranges, zone());
+ RegExpTree* atom = new (zone()) RegExpCharacterClass(ranges, false);
+ builder->AddAtom(atom);
+ break;
+ }
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9': {
+ int index = 0;
+ if (ParseBackReferenceIndex(&index)) {
+ if (state->IsInsideCaptureGroup(index)) {
+ // The backreference is inside the capture group it refers to.
+ // Nothing can possibly have been captured yet.
+ builder->AddEmpty();
+ } else {
+ RegExpCapture* capture = GetCapture(index);
+ RegExpTree* atom = new (zone()) RegExpBackReference(capture);
+ builder->AddAtom(atom);
+ }
+ break;
+ }
+ uc32 first_digit = Next();
+ if (first_digit == '8' || first_digit == '9') {
+ // If the 'u' flag is present, only syntax characters can be
+ // escaped,
+ // no other identity escapes are allowed. If the 'u' flag is not
+ // present, all identity escapes are allowed.
+ if (!FLAG_harmony_unicode_regexps || !unicode_) {
+ builder->AddCharacter(first_digit);
+ Advance(2);
+ } else {
+ return ReportError(CStrVector("Invalid escape"));
+ }
+ break;
+ }
+ }
+ // FALLTHROUGH
+ case '0': {
+ Advance();
+ uc32 octal = ParseOctalLiteral();
+ builder->AddCharacter(octal);
+ break;
+ }
+ // ControlEscape :: one of
+ // f n r t v
+ case 'f':
+ Advance(2);
+ builder->AddCharacter('\f');
+ break;
+ case 'n':
+ Advance(2);
+ builder->AddCharacter('\n');
+ break;
+ case 'r':
+ Advance(2);
+ builder->AddCharacter('\r');
+ break;
+ case 't':
+ Advance(2);
+ builder->AddCharacter('\t');
+ break;
+ case 'v':
+ Advance(2);
+ builder->AddCharacter('\v');
+ break;
+ case 'c': {
+ Advance();
+ uc32 controlLetter = Next();
+ // Special case if it is an ASCII letter.
+ // Convert lower case letters to uppercase.
+ uc32 letter = controlLetter & ~('a' ^ 'A');
+ if (letter < 'A' || 'Z' < letter) {
+ // controlLetter is not in range 'A'-'Z' or 'a'-'z'.
+ // This is outside the specification. We match JSC in
+ // reading the backslash as a literal character instead
+ // of as starting an escape.
+ builder->AddCharacter('\\');
+ } else {
+ Advance(2);
+ builder->AddCharacter(controlLetter & 0x1f);
+ }
+ break;
+ }
+ case 'x': {
+ Advance(2);
+ uc32 value;
+ if (ParseHexEscape(2, &value)) {
+ builder->AddCharacter(value);
+ } else if (!FLAG_harmony_unicode_regexps || !unicode_) {
+ builder->AddCharacter('x');
+ } else {
+ // If the 'u' flag is present, invalid escapes are not treated as
+ // identity escapes.
+ return ReportError(CStrVector("Invalid escape"));
+ }
+ break;
+ }
+ case 'u': {
+ Advance(2);
+ uc32 value;
+ if (ParseUnicodeEscape(&value)) {
+ builder->AddCharacter(value);
+ } else if (!FLAG_harmony_unicode_regexps || !unicode_) {
+ builder->AddCharacter('u');
+ } else {
+ // If the 'u' flag is present, invalid escapes are not treated as
+ // identity escapes.
+ return ReportError(CStrVector("Invalid unicode escape"));
+ }
+ break;
+ }
+ default:
+ Advance();
+ // If the 'u' flag is present, only syntax characters can be
+ // escaped, no
+ // other identity escapes are allowed. If the 'u' flag is not
+ // present,
+ // all identity escapes are allowed.
+ if (!FLAG_harmony_unicode_regexps || !unicode_ ||
+ IsSyntaxCharacter(current())) {
+ builder->AddCharacter(current());
+ Advance();
+ } else {
+ return ReportError(CStrVector("Invalid escape"));
+ }
+ break;
}
break;
- }
- case 'u': {
- Advance(2);
- uc32 value;
- if (ParseUnicodeEscape(&value)) {
- builder->AddCharacter(value);
- } else if (!FLAG_harmony_unicode_regexps || !unicode_) {
- builder->AddCharacter('u');
- } else {
- // If the 'u' flag is present, invalid escapes are not treated as
- // identity escapes.
- return ReportError(CStrVector("Invalid unicode escape"));
+ case '{': {
+ int dummy;
+ if (ParseIntervalQuantifier(&dummy, &dummy)) {
+ ReportError(CStrVector("Nothing to repeat") CHECK_FAILED);
}
- break;
+ // fallthrough
}
default:
+ builder->AddCharacter(current());
Advance();
- // If the 'u' flag is present, only syntax characters can be escaped, no
- // other identity escapes are allowed. If the 'u' flag is not present,
- // all identity escapes are allowed.
- if (!FLAG_harmony_unicode_regexps || !unicode_ ||
- IsSyntaxCharacter(current())) {
- builder->AddCharacter(current());
- Advance();
- } else {
- return ReportError(CStrVector("Invalid escape"));
- }
break;
- }
- break;
- case '{': {
- int dummy;
- if (ParseIntervalQuantifier(&dummy, &dummy)) {
- ReportError(CStrVector("Nothing to repeat") CHECK_FAILED);
- }
- // fallthrough
- }
- default:
- builder->AddCharacter(current());
- Advance();
- break;
} // end switch(current())
int min;
int max;
switch (current()) {
- // QuantifierPrefix ::
- // *
- // +
- // ?
- // {
- case '*':
- min = 0;
- max = RegExpTree::kInfinity;
- Advance();
- break;
- case '+':
- min = 1;
- max = RegExpTree::kInfinity;
- Advance();
- break;
- case '?':
- min = 0;
- max = 1;
- Advance();
- break;
- case '{':
- if (ParseIntervalQuantifier(&min, &max)) {
- if (max < min) {
- ReportError(CStrVector("numbers out of order in {} quantifier.")
- CHECK_FAILED);
- }
+ // QuantifierPrefix ::
+ // *
+ // +
+ // ?
+ // {
+ case '*':
+ min = 0;
+ max = RegExpTree::kInfinity;
+ Advance();
break;
- } else {
+ case '+':
+ min = 1;
+ max = RegExpTree::kInfinity;
+ Advance();
+ break;
+ case '?':
+ min = 0;
+ max = 1;
+ Advance();
+ break;
+ case '{':
+ if (ParseIntervalQuantifier(&min, &max)) {
+ if (max < min) {
+ ReportError(CStrVector("numbers out of order in {} quantifier.")
+ CHECK_FAILED);
+ }
+ break;
+ } else {
+ continue;
+ }
+ default:
continue;
- }
- default:
- continue;
}
RegExpQuantifier::QuantifierType quantifier_type = RegExpQuantifier::GREEDY;
if (current() == '?') {
@@ -5647,9 +5646,12 @@ RegExpTree* RegExpParser::ParseDisjunction() {
// Currently only used in an DCHECK.
static bool IsSpecialClassEscape(uc32 c) {
switch (c) {
- case 'd': case 'D':
- case 's': case 'S':
- case 'w': case 'W':
+ case 'd':
+ case 'D':
+ case 's':
+ case 'S':
+ case 'w':
+ case 'W':
return true;
default:
return false;
@@ -5936,8 +5938,7 @@ uc32 RegExpParser::ParseClassCharacterEscape() {
// For compatibility with JSC, inside a character class
// we also accept digits and underscore as control characters.
if ((controlLetter >= '0' && controlLetter <= '9') ||
- controlLetter == '_' ||
- (letter >= 'A' && letter <= 'Z')) {
+ controlLetter == '_' || (letter >= 'A' && letter <= 'Z')) {
Advance(2);
// Control letters mapped to ASCII control characters in the range
// 0x00-0x1f.
@@ -5947,8 +5948,14 @@ uc32 RegExpParser::ParseClassCharacterEscape() {
// character instead of as starting an escape.
return '\\';
}
- case '0': case '1': case '2': case '3': case '4': case '5':
- case '6': case '7':
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
// For compatibility, we interpret a decimal escape that isn't
// a back reference (and therefore either \0 or not valid according
// to the specification) as a 1..3 digit octal character code.
@@ -6006,7 +6013,12 @@ CharacterRange RegExpParser::ParseClassAtom(uc16* char_class) {
uc32 first = current();
if (first == '\\') {
switch (Next()) {
- case 'w': case 'W': case 'd': case 'D': case 's': case 'S': {
+ case 'w':
+ case 'W':
+ case 'd':
+ case 'D':
+ case 's':
+ case 'S': {
*char_class = Next();
Advance(2);
return CharacterRange::Singleton(0); // Return dummy value.
@@ -6030,8 +6042,7 @@ static const uc16 kNoCharClass = 0;
// If char_class is not kInvalidClass, it's interpreted as a class
// escape (i.e., 's' means whitespace, from '\s').
static inline void AddRangeOrEscape(ZoneList<CharacterRange>* ranges,
- uc16 char_class,
- CharacterRange range,
+ uc16 char_class, CharacterRange range,
Zone* zone) {
if (char_class != kNoCharClass) {
CharacterRange::AddClassEscape(char_class, ranges, zone);
@@ -6053,7 +6064,7 @@ RegExpTree* RegExpParser::ParseCharacterClass() {
Advance();
}
ZoneList<CharacterRange>* ranges =
- new(zone()) ZoneList<CharacterRange>(2, zone());
+ new (zone()) ZoneList<CharacterRange>(2, zone());
while (has_more() && current() != ']') {
uc16 char_class = kNoCharClass;
CharacterRange first = ParseClassAtom(&char_class CHECK_FAILED);
@@ -6249,8 +6260,8 @@ Expression* Parser::CloseTemplateLiteral(TemplateLiteralState* state, int start,
args, sub->position());
expr = factory()->NewBinaryOperation(
- Token::ADD, factory()->NewBinaryOperation(
- Token::ADD, expr, middle, expr->position()),
+ Token::ADD, factory()->NewBinaryOperation(Token::ADD, expr, middle,
+ expr->position()),
cooked_str, sub->position());
}
return expr;
@@ -6266,11 +6277,10 @@ Expression* Parser::CloseTemplateLiteral(TemplateLiteralState* state, int start,
const_cast<ZoneList<Expression*>*>(cooked_strings),
cooked_idx, is_strong(language_mode()), pos),
zone());
- args->Add(
- factory()->NewArrayLiteral(
- const_cast<ZoneList<Expression*>*>(raw_strings), raw_idx,
- is_strong(language_mode()), pos),
- zone());
+ args->Add(factory()->NewArrayLiteral(
+ const_cast<ZoneList<Expression*>*>(raw_strings), raw_idx,
+ is_strong(language_mode()), pos),
+ zone());
// Ensure hash is suitable as a Smi value
Smi* hash_obj = Smi::cast(Internals::IntToSmi(static_cast<int>(hash)));
@@ -6299,8 +6309,8 @@ uint32_t Parser::ComputeTemplateLiteralHash(const TemplateLiteral* lit) {
for (int index = 0; index < total; ++index) {
if (index) {
- running_hash = StringHasher::ComputeRunningHashOneByte(
- running_hash, "${}", 3);
+ running_hash =
+ StringHasher::ComputeRunningHashOneByte(running_hash, "${}", 3);
}
const AstRawString* raw_string =
« no previous file with comments | « src/parsing/parser.h ('k') | src/parsing/pattern-rewriter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698