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

Side by Side Diff: src/parser.cc

Issue 8562002: Make the parser track the language mode instead of keeping its own harmony flag. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/parser.h ('k') | src/scanner.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 script_(script), 594 script_(script),
595 scanner_(isolate_->unicode_cache()), 595 scanner_(isolate_->unicode_cache()),
596 top_scope_(NULL), 596 top_scope_(NULL),
597 current_function_state_(NULL), 597 current_function_state_(NULL),
598 target_stack_(NULL), 598 target_stack_(NULL),
599 extension_(extension), 599 extension_(extension),
600 pre_data_(pre_data), 600 pre_data_(pre_data),
601 fni_(NULL), 601 fni_(NULL),
602 allow_natives_syntax_(allow_natives_syntax), 602 allow_natives_syntax_(allow_natives_syntax),
603 stack_overflow_(false), 603 stack_overflow_(false),
604 parenthesized_function_(false), 604 parenthesized_function_(false) {
605 harmony_scoping_(false) { 605 scanner().SetHarmonyScoping(FLAG_harmony_scoping);
606 AstNode::ResetIds(); 606 AstNode::ResetIds();
607 } 607 }
608 608
609 609
610 FunctionLiteral* Parser::ParseProgram(Handle<String> source, 610 FunctionLiteral* Parser::ParseProgram(Handle<String> source,
611 bool in_global_context, 611 bool in_global_context,
612 LanguageMode language_mode) { 612 LanguageMode language_mode) {
613 ZoneScope zone_scope(isolate(), DONT_DELETE_ON_EXIT); 613 ZoneScope zone_scope(isolate(), DONT_DELETE_ON_EXIT);
614 614
615 HistogramTimerScope timer(isolate()->counters()->parse()); 615 HistogramTimerScope timer(isolate()->counters()->parse());
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 ASSERT(top_scope_->language_mode() == CLASSIC_MODE); 659 ASSERT(top_scope_->language_mode() == CLASSIC_MODE);
660 top_scope_->SetLanguageMode(language_mode); 660 top_scope_->SetLanguageMode(language_mode);
661 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16); 661 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16);
662 bool ok = true; 662 bool ok = true;
663 int beg_loc = scanner().location().beg_pos; 663 int beg_loc = scanner().location().beg_pos;
664 ParseSourceElements(body, Token::EOS, &ok); 664 ParseSourceElements(body, Token::EOS, &ok);
665 if (ok && !top_scope_->is_classic_mode()) { 665 if (ok && !top_scope_->is_classic_mode()) {
666 CheckOctalLiteral(beg_loc, scanner().location().end_pos, &ok); 666 CheckOctalLiteral(beg_loc, scanner().location().end_pos, &ok);
667 } 667 }
668 668
669 if (ok && harmony_scoping_) { 669 if (ok && is_extended_mode()) {
670 CheckConflictingVarDeclarations(scope, &ok); 670 CheckConflictingVarDeclarations(scope, &ok);
671 } 671 }
672 672
673 if (ok) { 673 if (ok) {
674 result = new(zone()) FunctionLiteral( 674 result = new(zone()) FunctionLiteral(
675 isolate(), 675 isolate(),
676 no_name, 676 no_name,
677 top_scope_, 677 top_scope_,
678 body, 678 body,
679 function_state.materialized_literal_count(), 679 function_state.materialized_literal_count(),
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 Factory* factory = isolate()->factory(); 826 Factory* factory = isolate()->factory();
827 Handle<FixedArray> elements = factory->NewFixedArray(args.length()); 827 Handle<FixedArray> elements = factory->NewFixedArray(args.length());
828 for (int i = 0; i < args.length(); i++) { 828 for (int i = 0; i < args.length(); i++) {
829 elements->set(i, *args[i]); 829 elements->set(i, *args[i]);
830 } 830 }
831 Handle<JSArray> array = factory->NewJSArrayWithElements(elements); 831 Handle<JSArray> array = factory->NewJSArrayWithElements(elements);
832 Handle<Object> result = factory->NewSyntaxError(type, array); 832 Handle<Object> result = factory->NewSyntaxError(type, array);
833 isolate()->Throw(*result, &location); 833 isolate()->Throw(*result, &location);
834 } 834 }
835 835
836 void Parser::SetHarmonyScoping(bool block_scoping) {
837 scanner().SetHarmonyScoping(block_scoping);
838 harmony_scoping_ = block_scoping;
839 }
840 836
841 // Base class containing common code for the different finder classes used by 837 // Base class containing common code for the different finder classes used by
842 // the parser. 838 // the parser.
843 class ParserFinder { 839 class ParserFinder {
844 protected: 840 protected:
845 ParserFinder() {} 841 ParserFinder() {}
846 static Assignment* AsAssignment(Statement* stat) { 842 static Assignment* AsAssignment(Statement* stat) {
847 if (stat == NULL) return NULL; 843 if (stat == NULL) return NULL;
848 ExpressionStatement* exp_stat = stat->AsExpressionStatement(); 844 ExpressionStatement* exp_stat = stat->AsExpressionStatement();
849 if (exp_stat == NULL) return NULL; 845 if (exp_stat == NULL) return NULL;
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
1192 if ((e_stat = stat->AsExpressionStatement()) != NULL && 1188 if ((e_stat = stat->AsExpressionStatement()) != NULL &&
1193 (literal = e_stat->expression()->AsLiteral()) != NULL && 1189 (literal = e_stat->expression()->AsLiteral()) != NULL &&
1194 literal->handle()->IsString()) { 1190 literal->handle()->IsString()) {
1195 Handle<String> directive = Handle<String>::cast(literal->handle()); 1191 Handle<String> directive = Handle<String>::cast(literal->handle());
1196 1192
1197 // Check "use strict" directive (ES5 14.1). 1193 // Check "use strict" directive (ES5 14.1).
1198 if (top_scope_->is_classic_mode() && 1194 if (top_scope_->is_classic_mode() &&
1199 directive->Equals(isolate()->heap()->use_strict()) && 1195 directive->Equals(isolate()->heap()->use_strict()) &&
1200 token_loc.end_pos - token_loc.beg_pos == 1196 token_loc.end_pos - token_loc.beg_pos ==
1201 isolate()->heap()->use_strict()->length() + 2) { 1197 isolate()->heap()->use_strict()->length() + 2) {
1202 top_scope_->SetLanguageMode(harmony_scoping_ 1198 // TODO(ES6): Fix entering extended mode, once it is specified.
1199 top_scope_->SetLanguageMode(FLAG_harmony_scoping
1203 ? EXTENDED_MODE : STRICT_MODE); 1200 ? EXTENDED_MODE : STRICT_MODE);
1204 // "use strict" is the only directive for now. 1201 // "use strict" is the only directive for now.
1205 directive_prologue = false; 1202 directive_prologue = false;
1206 } 1203 }
1207 } else { 1204 } else {
1208 // End of the directive prologue. 1205 // End of the directive prologue.
1209 directive_prologue = false; 1206 directive_prologue = false;
1210 } 1207 }
1211 } 1208 }
1212 1209
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1406 // function () { let x; { var x; } } 1403 // function () { let x; { var x; } }
1407 // 1404 //
1408 // because the var declaration is hoisted to the function scope where 'x' 1405 // because the var declaration is hoisted to the function scope where 'x'
1409 // is already bound. 1406 // is already bound.
1410 if ((mode != VAR) || (var->mode() != VAR)) { 1407 if ((mode != VAR) || (var->mode() != VAR)) {
1411 // We only have vars, consts and lets in declarations. 1408 // We only have vars, consts and lets in declarations.
1412 ASSERT(var->mode() == VAR || 1409 ASSERT(var->mode() == VAR ||
1413 var->mode() == CONST || 1410 var->mode() == CONST ||
1414 var->mode() == CONST_HARMONY || 1411 var->mode() == CONST_HARMONY ||
1415 var->mode() == LET); 1412 var->mode() == LET);
1416 if (harmony_scoping_) { 1413 if (is_extended_mode()) {
1417 // In harmony mode we treat re-declarations as early errors. See 1414 // In harmony mode we treat re-declarations as early errors. See
1418 // ES5 16 for a definition of early errors. 1415 // ES5 16 for a definition of early errors.
1419 SmartArrayPointer<char> c_string = name->ToCString(DISALLOW_NULLS); 1416 SmartArrayPointer<char> c_string = name->ToCString(DISALLOW_NULLS);
1420 const char* elms[2] = { "Variable", *c_string }; 1417 const char* elms[2] = { "Variable", *c_string };
1421 Vector<const char*> args(elms, 2); 1418 Vector<const char*> args(elms, 2);
1422 ReportMessage("redeclaration", args); 1419 ReportMessage("redeclaration", args);
1423 *ok = false; 1420 *ok = false;
1424 return NULL; 1421 return NULL;
1425 } 1422 }
1426 const char* type = (var->mode() == VAR) 1423 const char* type = (var->mode() == VAR)
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1564 Handle<String> name = ParseIdentifierOrStrictReservedWord( 1561 Handle<String> name = ParseIdentifierOrStrictReservedWord(
1565 &is_strict_reserved, CHECK_OK); 1562 &is_strict_reserved, CHECK_OK);
1566 FunctionLiteral* fun = ParseFunctionLiteral(name, 1563 FunctionLiteral* fun = ParseFunctionLiteral(name,
1567 is_strict_reserved, 1564 is_strict_reserved,
1568 function_token_position, 1565 function_token_position,
1569 FunctionLiteral::DECLARATION, 1566 FunctionLiteral::DECLARATION,
1570 CHECK_OK); 1567 CHECK_OK);
1571 // Even if we're not at the top-level of the global or a function 1568 // Even if we're not at the top-level of the global or a function
1572 // scope, we treat is as such and introduce the function with it's 1569 // scope, we treat is as such and introduce the function with it's
1573 // initial value upon entering the corresponding scope. 1570 // initial value upon entering the corresponding scope.
1574 VariableMode mode = harmony_scoping_ ? LET : VAR; 1571 VariableMode mode = is_extended_mode() ? LET : VAR;
1575 Declare(name, mode, fun, true, CHECK_OK); 1572 Declare(name, mode, fun, true, CHECK_OK);
1576 return EmptyStatement(); 1573 return EmptyStatement();
1577 } 1574 }
1578 1575
1579 1576
1580 Block* Parser::ParseBlock(ZoneStringList* labels, bool* ok) { 1577 Block* Parser::ParseBlock(ZoneStringList* labels, bool* ok) {
1581 if (top_scope_->is_extended_mode()) return ParseScopedBlock(labels, ok); 1578 if (top_scope_->is_extended_mode()) return ParseScopedBlock(labels, ok);
1582 1579
1583 // Block :: 1580 // Block ::
1584 // '{' Statement* '}' 1581 // '{' Statement* '}'
(...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after
2297 if (!top_scope_->is_classic_mode() && IsEvalOrArguments(name)) { 2294 if (!top_scope_->is_classic_mode() && IsEvalOrArguments(name)) {
2298 ReportMessage("strict_catch_variable", Vector<const char*>::empty()); 2295 ReportMessage("strict_catch_variable", Vector<const char*>::empty());
2299 *ok = false; 2296 *ok = false;
2300 return NULL; 2297 return NULL;
2301 } 2298 }
2302 2299
2303 Expect(Token::RPAREN, CHECK_OK); 2300 Expect(Token::RPAREN, CHECK_OK);
2304 2301
2305 if (peek() == Token::LBRACE) { 2302 if (peek() == Token::LBRACE) {
2306 Target target(&this->target_stack_, &catch_collector); 2303 Target target(&this->target_stack_, &catch_collector);
2307 VariableMode mode = harmony_scoping_ ? LET : VAR; 2304 VariableMode mode = is_extended_mode() ? LET : VAR;
2308 catch_variable = 2305 catch_variable =
2309 catch_scope->DeclareLocal(name, mode, kCreatedInitialized); 2306 catch_scope->DeclareLocal(name, mode, kCreatedInitialized);
2310 2307
2311 BlockState block_state(this, catch_scope); 2308 BlockState block_state(this, catch_scope);
2312 catch_block = ParseBlock(NULL, CHECK_OK); 2309 catch_block = ParseBlock(NULL, CHECK_OK);
2313 } else { 2310 } else {
2314 Expect(Token::LBRACE, CHECK_OK); 2311 Expect(Token::LBRACE, CHECK_OK);
2315 } 2312 }
2316 catch_scope->set_end_position(scanner().location().end_pos); 2313 catch_scope->set_end_position(scanner().location().end_pos);
2317 tok = peek(); 2314 tok = peek();
(...skipping 1590 matching lines...) Expand 10 before | Expand all | Expand 10 after
3908 3905
3909 // We want a non-null handle as the function name. 3906 // We want a non-null handle as the function name.
3910 if (should_infer_name) { 3907 if (should_infer_name) {
3911 function_name = isolate()->factory()->empty_symbol(); 3908 function_name = isolate()->factory()->empty_symbol();
3912 } 3909 }
3913 3910
3914 int num_parameters = 0; 3911 int num_parameters = 0;
3915 // Function declarations are function scoped in normal mode, so they are 3912 // Function declarations are function scoped in normal mode, so they are
3916 // hoisted. In harmony block scoping mode they are block scoped, so they 3913 // hoisted. In harmony block scoping mode they are block scoped, so they
3917 // are not hoisted. 3914 // are not hoisted.
3918 Scope* scope = (type == FunctionLiteral::DECLARATION && !harmony_scoping_) 3915 Scope* scope = (type == FunctionLiteral::DECLARATION && !is_extended_mode())
3919 ? NewScope(top_scope_->DeclarationScope(), FUNCTION_SCOPE) 3916 ? NewScope(top_scope_->DeclarationScope(), FUNCTION_SCOPE)
3920 : NewScope(top_scope_, FUNCTION_SCOPE); 3917 : NewScope(top_scope_, FUNCTION_SCOPE);
3921 ZoneList<Statement*>* body = NULL; 3918 ZoneList<Statement*>* body = NULL;
3922 int materialized_literal_count; 3919 int materialized_literal_count;
3923 int expected_property_count; 3920 int expected_property_count;
3924 int handler_count = 0; 3921 int handler_count = 0;
3925 bool only_simple_this_property_assignments; 3922 bool only_simple_this_property_assignments;
3926 Handle<FixedArray> this_property_assignments; 3923 Handle<FixedArray> this_property_assignments;
3927 bool has_duplicate_parameters = false; 3924 bool has_duplicate_parameters = false;
3928 // Parse function body. 3925 // Parse function body.
(...skipping 20 matching lines...) Expand all
3949 name_loc = scanner().location(); 3946 name_loc = scanner().location();
3950 } 3947 }
3951 if (!dupe_loc.IsValid() && top_scope_->IsDeclared(param_name)) { 3948 if (!dupe_loc.IsValid() && top_scope_->IsDeclared(param_name)) {
3952 has_duplicate_parameters = true; 3949 has_duplicate_parameters = true;
3953 dupe_loc = scanner().location(); 3950 dupe_loc = scanner().location();
3954 } 3951 }
3955 if (!reserved_loc.IsValid() && is_strict_reserved) { 3952 if (!reserved_loc.IsValid() && is_strict_reserved) {
3956 reserved_loc = scanner().location(); 3953 reserved_loc = scanner().location();
3957 } 3954 }
3958 3955
3959 top_scope_->DeclareParameter(param_name, harmony_scoping_ ? LET : VAR); 3956 top_scope_->DeclareParameter(param_name, is_extended_mode() ? LET : VAR);
3960 num_parameters++; 3957 num_parameters++;
3961 if (num_parameters > kMaxNumFunctionParameters) { 3958 if (num_parameters > kMaxNumFunctionParameters) {
3962 ReportMessageAt(scanner().location(), "too_many_parameters", 3959 ReportMessageAt(scanner().location(), "too_many_parameters",
3963 Vector<const char*>::empty()); 3960 Vector<const char*>::empty());
3964 *ok = false; 3961 *ok = false;
3965 return NULL; 3962 return NULL;
3966 } 3963 }
3967 done = (peek() == Token::RPAREN); 3964 done = (peek() == Token::RPAREN);
3968 if (!done) Expect(Token::COMMA, CHECK_OK); 3965 if (!done) Expect(Token::COMMA, CHECK_OK);
3969 } 3966 }
3970 Expect(Token::RPAREN, CHECK_OK); 3967 Expect(Token::RPAREN, CHECK_OK);
3971 3968
3972 Expect(Token::LBRACE, CHECK_OK); 3969 Expect(Token::LBRACE, CHECK_OK);
3973 3970
3974 // If we have a named function expression, we add a local variable 3971 // If we have a named function expression, we add a local variable
3975 // declaration to the body of the function with the name of the 3972 // declaration to the body of the function with the name of the
3976 // function and let it refer to the function itself (closure). 3973 // function and let it refer to the function itself (closure).
3977 // NOTE: We create a proxy and resolve it here so that in the 3974 // NOTE: We create a proxy and resolve it here so that in the
3978 // future we can change the AST to only refer to VariableProxies 3975 // future we can change the AST to only refer to VariableProxies
3979 // instead of Variables and Proxis as is the case now. 3976 // instead of Variables and Proxis as is the case now.
3980 Variable* fvar = NULL; 3977 Variable* fvar = NULL;
3981 Token::Value fvar_init_op = Token::INIT_CONST; 3978 Token::Value fvar_init_op = Token::INIT_CONST;
3982 if (type == FunctionLiteral::NAMED_EXPRESSION) { 3979 if (type == FunctionLiteral::NAMED_EXPRESSION) {
3983 VariableMode fvar_mode; 3980 VariableMode fvar_mode;
3984 if (harmony_scoping_) { 3981 if (is_extended_mode()) {
3985 fvar_mode = CONST_HARMONY; 3982 fvar_mode = CONST_HARMONY;
3986 fvar_init_op = Token::INIT_CONST_HARMONY; 3983 fvar_init_op = Token::INIT_CONST_HARMONY;
3987 } else { 3984 } else {
3988 fvar_mode = CONST; 3985 fvar_mode = CONST;
3989 } 3986 }
3990 fvar = top_scope_->DeclareFunctionVar(function_name, fvar_mode); 3987 fvar = top_scope_->DeclareFunctionVar(function_name, fvar_mode);
3991 } 3988 }
3992 3989
3993 // Determine if the function will be lazily compiled. The mode can only 3990 // Determine if the function will be lazily compiled. The mode can only
3994 // be PARSE_LAZILY if the --lazy flag is true. We will not lazily 3991 // be PARSE_LAZILY if the --lazy flag is true. We will not lazily
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
4092 Vector<const char*>::empty()); 4089 Vector<const char*>::empty());
4093 *ok = false; 4090 *ok = false;
4094 return NULL; 4091 return NULL;
4095 } 4092 }
4096 CheckOctalLiteral(scope->start_position(), 4093 CheckOctalLiteral(scope->start_position(),
4097 scope->end_position(), 4094 scope->end_position(),
4098 CHECK_OK); 4095 CHECK_OK);
4099 } 4096 }
4100 } 4097 }
4101 4098
4102 if (harmony_scoping_) { 4099 if (is_extended_mode()) {
4103 CheckConflictingVarDeclarations(scope, CHECK_OK); 4100 CheckConflictingVarDeclarations(scope, CHECK_OK);
4104 } 4101 }
4105 4102
4106 FunctionLiteral* function_literal = 4103 FunctionLiteral* function_literal =
4107 new(zone()) FunctionLiteral(isolate(), 4104 new(zone()) FunctionLiteral(isolate(),
4108 function_name, 4105 function_name,
4109 scope, 4106 scope,
4110 body, 4107 body,
4111 materialized_literal_count, 4108 materialized_literal_count,
4112 expected_property_count, 4109 expected_property_count,
(...skipping 1218 matching lines...) Expand 10 before | Expand all | Expand 10 after
5331 return result; 5328 return result;
5332 } 5329 }
5333 5330
5334 5331
5335 // Create a Scanner for the preparser to use as input, and preparse the source. 5332 // Create a Scanner for the preparser to use as input, and preparse the source.
5336 static ScriptDataImpl* DoPreParse(UC16CharacterStream* source, 5333 static ScriptDataImpl* DoPreParse(UC16CharacterStream* source,
5337 int flags, 5334 int flags,
5338 ParserRecorder* recorder) { 5335 ParserRecorder* recorder) {
5339 Isolate* isolate = Isolate::Current(); 5336 Isolate* isolate = Isolate::Current();
5340 Scanner scanner(isolate->unicode_cache()); 5337 Scanner scanner(isolate->unicode_cache());
5341 scanner.SetHarmonyScoping((flags & kHarmonyScoping) != 0); 5338 scanner.SetHarmonyScoping(FLAG_harmony_scoping);
5342 scanner.Initialize(source); 5339 scanner.Initialize(source);
5343 intptr_t stack_limit = isolate->stack_guard()->real_climit(); 5340 intptr_t stack_limit = isolate->stack_guard()->real_climit();
5344 if (!preparser::PreParser::PreParseProgram(&scanner, 5341 if (!preparser::PreParser::PreParseProgram(&scanner,
5345 recorder, 5342 recorder,
5346 flags, 5343 flags,
5347 stack_limit)) { 5344 stack_limit)) {
5348 isolate->StackOverflow(); 5345 isolate->StackOverflow();
5349 return NULL; 5346 return NULL;
5350 } 5347 }
5351 5348
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
5404 result->capture_count = capture_count; 5401 result->capture_count = capture_count;
5405 } 5402 }
5406 return !parser.failed(); 5403 return !parser.failed();
5407 } 5404 }
5408 5405
5409 5406
5410 bool ParserApi::Parse(CompilationInfo* info) { 5407 bool ParserApi::Parse(CompilationInfo* info) {
5411 ASSERT(info->function() == NULL); 5408 ASSERT(info->function() == NULL);
5412 FunctionLiteral* result = NULL; 5409 FunctionLiteral* result = NULL;
5413 Handle<Script> script = info->script(); 5410 Handle<Script> script = info->script();
5414 bool harmony_scoping = !info->is_native() && FLAG_harmony_scoping;
5415 if (info->is_lazy()) { 5411 if (info->is_lazy()) {
5416 bool allow_natives_syntax = 5412 bool allow_natives_syntax =
5417 FLAG_allow_natives_syntax || 5413 FLAG_allow_natives_syntax ||
5418 info->is_native(); 5414 info->is_native();
5419 Parser parser(script, allow_natives_syntax, NULL, NULL); 5415 Parser parser(script, allow_natives_syntax, NULL, NULL);
5420 parser.SetHarmonyScoping(harmony_scoping);
5421 result = parser.ParseLazy(info); 5416 result = parser.ParseLazy(info);
5422 } else { 5417 } else {
5423 // Whether we allow %identifier(..) syntax. 5418 // Whether we allow %identifier(..) syntax.
5424 bool allow_natives_syntax = 5419 bool allow_natives_syntax =
5425 info->is_native() || FLAG_allow_natives_syntax; 5420 info->is_native() || FLAG_allow_natives_syntax;
5426 ScriptDataImpl* pre_data = info->pre_parse_data(); 5421 ScriptDataImpl* pre_data = info->pre_parse_data();
5427 Parser parser(script, 5422 Parser parser(script,
5428 allow_natives_syntax, 5423 allow_natives_syntax,
5429 info->extension(), 5424 info->extension(),
5430 pre_data); 5425 pre_data);
5431 parser.SetHarmonyScoping(harmony_scoping);
5432 if (pre_data != NULL && pre_data->has_error()) { 5426 if (pre_data != NULL && pre_data->has_error()) {
5433 Scanner::Location loc = pre_data->MessageLocation(); 5427 Scanner::Location loc = pre_data->MessageLocation();
5434 const char* message = pre_data->BuildMessage(); 5428 const char* message = pre_data->BuildMessage();
5435 Vector<const char*> args = pre_data->BuildArgs(); 5429 Vector<const char*> args = pre_data->BuildArgs();
5436 parser.ReportMessageAt(loc, message, args); 5430 parser.ReportMessageAt(loc, message, args);
5437 DeleteArray(message); 5431 DeleteArray(message);
5438 for (int i = 0; i < args.length(); i++) { 5432 for (int i = 0; i < args.length(); i++) {
5439 DeleteArray(args[i]); 5433 DeleteArray(args[i]);
5440 } 5434 }
5441 DeleteArray(args.start()); 5435 DeleteArray(args.start());
5442 ASSERT(info->isolate()->has_pending_exception()); 5436 ASSERT(info->isolate()->has_pending_exception());
5443 } else { 5437 } else {
5444 Handle<String> source = Handle<String>(String::cast(script->source())); 5438 Handle<String> source = Handle<String>(String::cast(script->source()));
5445 result = parser.ParseProgram(source, 5439 result = parser.ParseProgram(source,
5446 info->is_global(), 5440 info->is_global(),
5447 info->language_mode()); 5441 info->language_mode());
5448 } 5442 }
5449 } 5443 }
5450 info->SetFunction(result); 5444 info->SetFunction(result);
5451 return (result != NULL); 5445 return (result != NULL);
5452 } 5446 }
5453 5447
5454 } } // namespace v8::internal 5448 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/parser.h ('k') | src/scanner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698