Index: src/parser.cc |
diff --git a/src/parser.cc b/src/parser.cc |
index 54e4c7cec15b1ed18f2fedcf36db47fb8ed6a126..6f62532ce4eef852610296f09e27b725cfb5e9ff 100644 |
--- a/src/parser.cc |
+++ b/src/parser.cc |
@@ -608,12 +608,9 @@ void ParserTraits::ReportMessageAt(Scanner::Location source_location, |
// and we want to report the stack overflow later. |
return; |
} |
- parser_->has_pending_error_ = true; |
- parser_->pending_error_location_ = source_location; |
- parser_->pending_error_message_ = message; |
- parser_->pending_error_char_arg_ = arg; |
- parser_->pending_error_arg_ = NULL; |
- parser_->pending_error_type_ = error_type; |
+ parser_->pending_error_handler_.ReportMessageAt(source_location.beg_pos, |
+ source_location.end_pos, |
+ message, arg, error_type); |
} |
@@ -640,12 +637,9 @@ void ParserTraits::ReportMessageAt(Scanner::Location source_location, |
// and we want to report the stack overflow later. |
return; |
} |
- parser_->has_pending_error_ = true; |
- parser_->pending_error_location_ = source_location; |
- parser_->pending_error_message_ = message; |
- parser_->pending_error_char_arg_ = NULL; |
- parser_->pending_error_arg_ = arg; |
- parser_->pending_error_type_ = error_type; |
+ parser_->pending_error_handler_.ReportMessageAt(source_location.beg_pos, |
+ source_location.end_pos, |
+ message, arg, error_type); |
} |
@@ -712,7 +706,9 @@ Literal* ParserTraits::ExpressionFromLiteral(Token::Value token, int pos, |
Expression* ParserTraits::ExpressionFromIdentifier(const AstRawString* name, |
- int pos, Scope* scope, |
+ int start_position, |
+ int end_position, |
+ Scope* scope, |
AstNodeFactory* factory) { |
if (parser_->fni_ != NULL) parser_->fni_->PushVariableName(name); |
@@ -721,8 +717,10 @@ Expression* ParserTraits::ExpressionFromIdentifier(const AstRawString* name, |
// for Traits::DeclareArrowParametersFromExpression() to be able to |
// pick the names of the parameters. |
return parser_->parsing_lazy_arrow_parameters_ |
- ? factory->NewVariableProxy(name, false, pos) |
- : scope->NewUnresolved(factory, name, pos); |
+ ? factory->NewVariableProxy(name, false, start_position, |
+ end_position) |
+ : scope->NewUnresolved(factory, name, start_position, |
+ end_position); |
} |
@@ -789,11 +787,6 @@ Parser::Parser(CompilationInfo* info, uintptr_t stack_limit, uint32_t hash_seed, |
compile_options_(info->compile_options()), |
cached_parse_data_(NULL), |
parsing_lazy_arrow_parameters_(false), |
- has_pending_error_(false), |
- pending_error_message_(NULL), |
- pending_error_arg_(NULL), |
- pending_error_char_arg_(NULL), |
- pending_error_type_(kSyntaxError), |
total_preparse_skipped_(0), |
pre_parse_timer_(NULL), |
parsing_on_main_thread_(true) { |
@@ -1792,7 +1785,9 @@ VariableProxy* Parser::NewUnresolved(const AstRawString* name, |
// scope. |
// Let/const variables in harmony mode are always added to the immediately |
// enclosing scope. |
- return DeclarationScope(mode)->NewUnresolved(factory(), name, position()); |
+ return DeclarationScope(mode)->NewUnresolved(factory(), name, |
+ scanner()->location().beg_pos, |
+ scanner()->location().end_pos); |
} |
@@ -1822,10 +1817,12 @@ void Parser::Declare(Declaration* declaration, bool resolve, bool* ok) { |
if (var == NULL) { |
// Declare the name. |
var = declaration_scope->DeclareLocal( |
- name, mode, declaration->initialization(), kNotAssigned); |
- } else if (IsLexicalVariableMode(mode) || IsLexicalVariableMode(var->mode()) |
- || ((mode == CONST_LEGACY || var->mode() == CONST_LEGACY) && |
- !declaration_scope->is_script_scope())) { |
+ name, mode, declaration->initialization(), declaration->position(), |
+ declaration->IsFunctionDeclaration(), kNotAssigned); |
+ } else if (IsLexicalVariableMode(mode) || |
+ IsLexicalVariableMode(var->mode()) || |
+ ((mode == CONST_LEGACY || var->mode() == CONST_LEGACY) && |
+ !declaration_scope->is_script_scope())) { |
// The name was declared in this scope before; check for conflicting |
// re-declarations. We have a conflict if either of the declarations is |
// not a var (in script scope, we also have to ignore legacy const for |
@@ -2811,7 +2808,8 @@ TryStatement* Parser::ParseTryStatement(bool* ok) { |
Expect(Token::RPAREN, CHECK_OK); |
- catch_variable = catch_scope->DeclareLocal(name, VAR, kCreatedInitialized); |
+ catch_variable = catch_scope->DeclareLocal( |
+ name, VAR, kCreatedInitialized, scanner()->location().beg_pos, false); |
BlockState block_state(&scope_, catch_scope); |
catch_block = ParseBlock(NULL, CHECK_OK); |
@@ -3077,15 +3075,15 @@ Statement* Parser::DesugarLetBindingsInForStatement( |
// make statement: let x = temp_x. |
for (int i = 0; i < names->length(); i++) { |
VariableProxy* proxy = NewUnresolved(names->at(i), LET); |
- Declaration* declaration = |
- factory()->NewVariableDeclaration(proxy, LET, scope_, pos); |
+ Declaration* declaration = factory()->NewVariableDeclaration( |
+ proxy, LET, scope_, RelocInfo::kNoPosition); |
Declare(declaration, true, CHECK_OK); |
inner_vars.Add(declaration->proxy()->var(), zone()); |
VariableProxy* temp_proxy = factory()->NewVariableProxy(temps.at(i)); |
Assignment* assignment = factory()->NewAssignment( |
Token::INIT_LET, proxy, temp_proxy, pos); |
- Statement* assignment_statement = factory()->NewExpressionStatement( |
- assignment, pos); |
+ Statement* assignment_statement = |
+ factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition); |
proxy->var()->set_initializer_position(pos); |
inner_block->AddStatement(assignment_statement, zone()); |
} |
@@ -3234,7 +3232,8 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels, |
CHECK_OK); |
bool accept_OF = decl_props == kHasNoInitializers; |
ForEachStatement::VisitMode mode; |
- int each_pos = position(); |
+ int each_beg_pos = scanner()->location().beg_pos; |
+ int each_end_pos = scanner()->location().end_pos; |
if (name != NULL && CheckInOrOf(accept_OF, &mode, ok)) { |
if (!*ok) return nullptr; |
@@ -3245,7 +3244,8 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels, |
Expression* enumerable = ParseExpression(true, CHECK_OK); |
Expect(Token::RPAREN, CHECK_OK); |
- VariableProxy* each = scope_->NewUnresolved(factory(), name, each_pos); |
+ VariableProxy* each = |
+ scope_->NewUnresolved(factory(), name, each_beg_pos, each_end_pos); |
Statement* body = ParseSubStatement(NULL, CHECK_OK); |
InitializeForEachStatement(loop, each, enumerable, body); |
Block* result = |
@@ -3272,7 +3272,8 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels, |
bool accept_IN = name != NULL && decl_props != kHasInitializers; |
bool accept_OF = decl_props == kHasNoInitializers; |
ForEachStatement::VisitMode mode; |
- int each_pos = position(); |
+ int each_beg_pos = scanner()->location().beg_pos; |
+ int each_end_pos = scanner()->location().end_pos; |
if (accept_IN && CheckInOrOf(accept_OF, &mode, ok)) { |
if (!*ok) return nullptr; |
@@ -3294,7 +3295,8 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels, |
// implementing stack allocated block scoped variables. |
Variable* temp = scope_->DeclarationScope()->NewTemporary( |
ast_value_factory()->dot_for_string()); |
- VariableProxy* temp_proxy = factory()->NewVariableProxy(temp, each_pos); |
+ VariableProxy* temp_proxy = |
+ factory()->NewVariableProxy(temp, each_beg_pos, each_end_pos); |
ForEachStatement* loop = |
factory()->NewForEachStatement(mode, labels, stmt_pos); |
Target target(&this->target_stack_, loop); |
@@ -3305,7 +3307,8 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels, |
scope_ = for_scope; |
Expect(Token::RPAREN, CHECK_OK); |
- VariableProxy* each = scope_->NewUnresolved(factory(), name, each_pos); |
+ VariableProxy* each = |
+ scope_->NewUnresolved(factory(), name, each_beg_pos, each_end_pos); |
Statement* body = ParseSubStatement(NULL, CHECK_OK); |
Block* body_block = |
factory()->NewBlock(NULL, 3, false, RelocInfo::kNoPosition); |
@@ -3747,7 +3750,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral( |
DCHECK(function_name != NULL); |
fvar = new (zone()) |
Variable(scope_, function_name, fvar_mode, true /* is valid LHS */, |
- Variable::NORMAL, kCreatedInitialized, kNotAssigned); |
+ Variable::FUNCTION, kCreatedInitialized, kNotAssigned); |
rossberg
2015/02/23 13:45:26
Note that this is not a function declaration, but
marja
2015/02/24 13:29:34
Done, in addition did the same change in Scope::Lo
|
VariableProxy* proxy = factory()->NewVariableProxy(fvar); |
VariableDeclaration* fvar_declaration = factory()->NewVariableDeclaration( |
proxy, fvar_mode, scope_, RelocInfo::kNoPosition); |
@@ -4267,61 +4270,6 @@ void Parser::HandleSourceURLComments(Isolate* isolate, Handle<Script> script) { |
} |
-void Parser::ThrowPendingError(Isolate* isolate, Handle<Script> script) { |
- DCHECK(ast_value_factory()->IsInternalized()); |
- if (has_pending_error_) { |
- MessageLocation location(script, pending_error_location_.beg_pos, |
- pending_error_location_.end_pos); |
- Factory* factory = isolate->factory(); |
- bool has_arg = |
- pending_error_arg_ != NULL || pending_error_char_arg_ != NULL; |
- Handle<FixedArray> elements = factory->NewFixedArray(has_arg ? 1 : 0); |
- if (pending_error_arg_ != NULL) { |
- Handle<String> arg_string = pending_error_arg_->string(); |
- elements->set(0, *arg_string); |
- } else if (pending_error_char_arg_ != NULL) { |
- Handle<String> arg_string = |
- factory->NewStringFromUtf8(CStrVector(pending_error_char_arg_)) |
- .ToHandleChecked(); |
- elements->set(0, *arg_string); |
- } |
- isolate->debug()->OnCompileError(script); |
- |
- Handle<JSArray> array = factory->NewJSArrayWithElements(elements); |
- Handle<Object> error; |
- MaybeHandle<Object> maybe_error; |
- switch (pending_error_type_) { |
- case kReferenceError: |
- maybe_error = factory->NewReferenceError(pending_error_message_, array); |
- break; |
- case kSyntaxError: |
- maybe_error = factory->NewSyntaxError(pending_error_message_, array); |
- break; |
- } |
- DCHECK(!maybe_error.is_null() || isolate->has_pending_exception()); |
- |
- if (maybe_error.ToHandle(&error)) { |
- Handle<JSObject> jserror = Handle<JSObject>::cast(error); |
- |
- Handle<Name> key_start_pos = factory->error_start_pos_symbol(); |
- JSObject::SetProperty(jserror, key_start_pos, |
- handle(Smi::FromInt(location.start_pos()), isolate), |
- SLOPPY).Check(); |
- |
- Handle<Name> key_end_pos = factory->error_end_pos_symbol(); |
- JSObject::SetProperty(jserror, key_end_pos, |
- handle(Smi::FromInt(location.end_pos()), isolate), |
- SLOPPY).Check(); |
- |
- Handle<Name> key_script = factory->error_script_symbol(); |
- JSObject::SetProperty(jserror, key_script, script, SLOPPY).Check(); |
- |
- isolate->Throw(*error, &location); |
- } |
- } |
-} |
- |
- |
void Parser::Internalize(Isolate* isolate, Handle<Script> script, bool error) { |
// Internalize strings. |
ast_value_factory()->Internalize(isolate); |
@@ -4331,7 +4279,8 @@ void Parser::Internalize(Isolate* isolate, Handle<Script> script, bool error) { |
if (stack_overflow()) { |
isolate->StackOverflow(); |
} else { |
- ThrowPendingError(isolate, script); |
+ DCHECK(pending_error_handler_.has_pending_error()); |
+ pending_error_handler_.ThrowPendingError(isolate, script); |
} |
} |