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

Side by Side Diff: src/parser.cc

Issue 6542061: [Isolates] Less TLS reads in parser and full codegens. (Closed)
Patch Set: Created 9 years, 10 months 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
« no previous file with comments | « src/parser.h ('k') | src/x64/full-codegen-x64.cc » ('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 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 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 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 // Bookkeeping 303 // Bookkeeping
304 TemporaryScope** variable_; 304 TemporaryScope** variable_;
305 TemporaryScope* parent_; 305 TemporaryScope* parent_;
306 }; 306 };
307 307
308 308
309 TemporaryScope::TemporaryScope(TemporaryScope** variable) 309 TemporaryScope::TemporaryScope(TemporaryScope** variable)
310 : materialized_literal_count_(0), 310 : materialized_literal_count_(0),
311 expected_property_count_(0), 311 expected_property_count_(0),
312 only_simple_this_property_assignments_(false), 312 only_simple_this_property_assignments_(false),
313 this_property_assignments_(FACTORY->empty_fixed_array()), 313 this_property_assignments_(
314 Isolate::Current()->factory()->empty_fixed_array()),
314 loop_count_(0), 315 loop_count_(0),
315 variable_(variable), 316 variable_(variable),
316 parent_(*variable) { 317 parent_(*variable) {
317 *variable = this; 318 *variable = this;
318 } 319 }
319 320
320 321
321 TemporaryScope::~TemporaryScope() { 322 TemporaryScope::~TemporaryScope() {
322 *variable_ = parent_; 323 *variable_ = parent_;
323 } 324 }
324 325
325 326
326 Handle<String> Parser::LookupSymbol(int symbol_id, 327 Handle<String> Parser::LookupSymbol(int symbol_id,
327 Vector<const char> string) { 328 Vector<const char> string) {
328 // Length of symbol cache is the number of identified symbols. 329 // Length of symbol cache is the number of identified symbols.
329 // If we are larger than that, or negative, it's not a cached symbol. 330 // If we are larger than that, or negative, it's not a cached symbol.
330 // This might also happen if there is no preparser symbol data, even 331 // This might also happen if there is no preparser symbol data, even
331 // if there is some preparser data. 332 // if there is some preparser data.
332 if (static_cast<unsigned>(symbol_id) 333 if (static_cast<unsigned>(symbol_id)
333 >= static_cast<unsigned>(symbol_cache_.length())) { 334 >= static_cast<unsigned>(symbol_cache_.length())) {
334 return FACTORY->LookupSymbol(string); 335 return isolate()->factory()->LookupSymbol(string);
335 } 336 }
336 return LookupCachedSymbol(symbol_id, string); 337 return LookupCachedSymbol(symbol_id, string);
337 } 338 }
338 339
339 340
340 Handle<String> Parser::LookupCachedSymbol(int symbol_id, 341 Handle<String> Parser::LookupCachedSymbol(int symbol_id,
341 Vector<const char> string) { 342 Vector<const char> string) {
342 // Make sure the cache is large enough to hold the symbol identifier. 343 // Make sure the cache is large enough to hold the symbol identifier.
343 if (symbol_cache_.length() <= symbol_id) { 344 if (symbol_cache_.length() <= symbol_id) {
344 // Increase length to index + 1. 345 // Increase length to index + 1.
345 symbol_cache_.AddBlock(Handle<String>::null(), 346 symbol_cache_.AddBlock(Handle<String>::null(),
346 symbol_id + 1 - symbol_cache_.length()); 347 symbol_id + 1 - symbol_cache_.length());
347 } 348 }
348 Handle<String> result = symbol_cache_.at(symbol_id); 349 Handle<String> result = symbol_cache_.at(symbol_id);
349 if (result.is_null()) { 350 if (result.is_null()) {
350 result = FACTORY->LookupSymbol(string); 351 result = isolate()->factory()->LookupSymbol(string);
351 symbol_cache_.at(symbol_id) = result; 352 symbol_cache_.at(symbol_id) = result;
352 return result; 353 return result;
353 } 354 }
354 COUNTERS->total_preparse_symbols_skipped()->Increment(); 355 COUNTERS->total_preparse_symbols_skipped()->Increment();
355 return result; 356 return result;
356 } 357 }
357 358
358 359
359 FunctionEntry ScriptDataImpl::GetFunctionEntry(int start) { 360 FunctionEntry ScriptDataImpl::GetFunctionEntry(int start) {
360 // The current pre-data entry must be a FunctionEntry with the given 361 // The current pre-data entry must be a FunctionEntry with the given
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 if (pre_data_ != NULL) pre_data_->Initialize(); 616 if (pre_data_ != NULL) pre_data_->Initialize();
616 617
617 // Compute the parsing mode. 618 // Compute the parsing mode.
618 mode_ = FLAG_lazy ? PARSE_LAZILY : PARSE_EAGERLY; 619 mode_ = FLAG_lazy ? PARSE_LAZILY : PARSE_EAGERLY;
619 if (allow_natives_syntax_ || extension_ != NULL) mode_ = PARSE_EAGERLY; 620 if (allow_natives_syntax_ || extension_ != NULL) mode_ = PARSE_EAGERLY;
620 621
621 Scope::Type type = 622 Scope::Type type =
622 in_global_context 623 in_global_context
623 ? Scope::GLOBAL_SCOPE 624 ? Scope::GLOBAL_SCOPE
624 : Scope::EVAL_SCOPE; 625 : Scope::EVAL_SCOPE;
625 Handle<String> no_name = FACTORY->empty_symbol(); 626 Handle<String> no_name = isolate()->factory()->empty_symbol();
626 627
627 FunctionLiteral* result = NULL; 628 FunctionLiteral* result = NULL;
628 { Scope* scope = NewScope(top_scope_, type, inside_with()); 629 { Scope* scope = NewScope(top_scope_, type, inside_with());
629 LexicalScope lexical_scope(&this->top_scope_, &this->with_nesting_level_, 630 LexicalScope lexical_scope(&this->top_scope_, &this->with_nesting_level_,
630 scope); 631 scope);
631 TemporaryScope temp_scope(&this->temp_scope_); 632 TemporaryScope temp_scope(&this->temp_scope_);
632 ZoneList<Statement*>* body = new ZoneList<Statement*>(16); 633 ZoneList<Statement*>* body = new ZoneList<Statement*>(16);
633 bool ok = true; 634 bool ok = true;
634 ParseSourceElements(body, Token::EOS, &ok); 635 ParseSourceElements(body, Token::EOS, &ok);
635 if (ok) { 636 if (ok) {
636 result = new FunctionLiteral( 637 result = new FunctionLiteral(
637 no_name, 638 no_name,
638 top_scope_, 639 top_scope_,
639 body, 640 body,
640 temp_scope.materialized_literal_count(), 641 temp_scope.materialized_literal_count(),
641 temp_scope.expected_property_count(), 642 temp_scope.expected_property_count(),
642 temp_scope.only_simple_this_property_assignments(), 643 temp_scope.only_simple_this_property_assignments(),
643 temp_scope.this_property_assignments(), 644 temp_scope.this_property_assignments(),
644 0, 645 0,
645 0, 646 0,
646 source->length(), 647 source->length(),
647 false, 648 false,
648 temp_scope.ContainsLoops()); 649 temp_scope.ContainsLoops());
649 } else if (stack_overflow_) { 650 } else if (stack_overflow_) {
650 Isolate::Current()->StackOverflow(); 651 isolate()->StackOverflow();
651 } 652 }
652 } 653 }
653 654
654 // Make sure the target stack is empty. 655 // Make sure the target stack is empty.
655 ASSERT(target_stack_ == NULL); 656 ASSERT(target_stack_ == NULL);
656 657
657 // If there was a syntax error we have to get rid of the AST 658 // If there was a syntax error we have to get rid of the AST
658 // and it is not safe to do so before the scope has been deleted. 659 // and it is not safe to do so before the scope has been deleted.
659 if (result == NULL) zone_scope.DeleteOnExit(); 660 if (result == NULL) zone_scope.DeleteOnExit();
660 return result; 661 return result;
(...skipping 14 matching lines...) Expand all
675 source->TryFlatten(); 676 source->TryFlatten();
676 scanner_.Initialize(source, info->start_position(), info->end_position()); 677 scanner_.Initialize(source, info->start_position(), info->end_position());
677 ASSERT(target_stack_ == NULL); 678 ASSERT(target_stack_ == NULL);
678 mode_ = PARSE_EAGERLY; 679 mode_ = PARSE_EAGERLY;
679 680
680 // Place holder for the result. 681 // Place holder for the result.
681 FunctionLiteral* result = NULL; 682 FunctionLiteral* result = NULL;
682 683
683 { 684 {
684 // Parse the function literal. 685 // Parse the function literal.
685 Handle<String> no_name = FACTORY->empty_symbol(); 686 Handle<String> no_name = isolate()->factory()->empty_symbol();
686 Scope* scope = 687 Scope* scope =
687 NewScope(top_scope_, Scope::GLOBAL_SCOPE, inside_with()); 688 NewScope(top_scope_, Scope::GLOBAL_SCOPE, inside_with());
688 LexicalScope lexical_scope(&this->top_scope_, &this->with_nesting_level_, 689 LexicalScope lexical_scope(&this->top_scope_, &this->with_nesting_level_,
689 scope); 690 scope);
690 TemporaryScope temp_scope(&this->temp_scope_); 691 TemporaryScope temp_scope(&this->temp_scope_);
691 692
692 FunctionLiteralType type = 693 FunctionLiteralType type =
693 info->is_expression() ? EXPRESSION : DECLARATION; 694 info->is_expression() ? EXPRESSION : DECLARATION;
694 bool ok = true; 695 bool ok = true;
695 result = ParseFunctionLiteral(name, RelocInfo::kNoPosition, type, &ok); 696 result = ParseFunctionLiteral(name, RelocInfo::kNoPosition, type, &ok);
696 // Make sure the results agree. 697 // Make sure the results agree.
697 ASSERT(ok == (result != NULL)); 698 ASSERT(ok == (result != NULL));
698 // The only errors should be stack overflows. 699 // The only errors should be stack overflows.
699 ASSERT(ok || stack_overflow_); 700 ASSERT(ok || stack_overflow_);
700 } 701 }
701 702
702 // Make sure the target stack is empty. 703 // Make sure the target stack is empty.
703 ASSERT(target_stack_ == NULL); 704 ASSERT(target_stack_ == NULL);
704 705
705 // If there was a stack overflow we have to get rid of AST and it is 706 // If there was a stack overflow we have to get rid of AST and it is
706 // not safe to do before scope has been deleted. 707 // not safe to do before scope has been deleted.
707 if (result == NULL) { 708 if (result == NULL) {
708 Isolate::Current()->StackOverflow(); 709 isolate()->StackOverflow();
709 zone_scope.DeleteOnExit(); 710 zone_scope.DeleteOnExit();
710 } else { 711 } else {
711 Handle<String> inferred_name(info->inferred_name()); 712 Handle<String> inferred_name(info->inferred_name());
712 result->set_inferred_name(inferred_name); 713 result->set_inferred_name(inferred_name);
713 } 714 }
714 return result; 715 return result;
715 } 716 }
716 717
717 718
718 Handle<String> Parser::GetSymbol(bool* ok) { 719 Handle<String> Parser::GetSymbol(bool* ok) {
719 int symbol_id = -1; 720 int symbol_id = -1;
720 if (pre_data() != NULL) { 721 if (pre_data() != NULL) {
721 symbol_id = pre_data()->GetSymbolIdentifier(); 722 symbol_id = pre_data()->GetSymbolIdentifier();
722 } 723 }
723 return LookupSymbol(symbol_id, scanner_.literal()); 724 return LookupSymbol(symbol_id, scanner_.literal());
724 } 725 }
725 726
726 727
727 void Parser::ReportMessage(const char* type, Vector<const char*> args) { 728 void Parser::ReportMessage(const char* type, Vector<const char*> args) {
728 Scanner::Location source_location = scanner_.location(); 729 Scanner::Location source_location = scanner_.location();
729 ReportMessageAt(source_location, type, args); 730 ReportMessageAt(source_location, type, args);
730 } 731 }
731 732
732 733
733 void Parser::ReportMessageAt(Scanner::Location source_location, 734 void Parser::ReportMessageAt(Scanner::Location source_location,
734 const char* type, 735 const char* type,
735 Vector<const char*> args) { 736 Vector<const char*> args) {
736 MessageLocation location(script_, 737 MessageLocation location(script_,
737 source_location.beg_pos, source_location.end_pos); 738 source_location.beg_pos, source_location.end_pos);
738 Handle<JSArray> array = FACTORY->NewJSArray(args.length()); 739 Handle<JSArray> array = isolate()->factory()->NewJSArray(args.length());
739 for (int i = 0; i < args.length(); i++) { 740 for (int i = 0; i < args.length(); i++) {
740 SetElement(array, i, FACTORY->NewStringFromUtf8(CStrVector(args[i]))); 741 SetElement(array, i,
742 isolate()->factory()->NewStringFromUtf8(CStrVector(args[i])));
741 } 743 }
742 Handle<Object> result = FACTORY->NewSyntaxError(type, array); 744 Handle<Object> result = isolate()->factory()->NewSyntaxError(type, array);
743 Isolate::Current()->Throw(*result, &location); 745 isolate()->Throw(*result, &location);
744 } 746 }
745 747
746 748
747 // Base class containing common code for the different finder classes used by 749 // Base class containing common code for the different finder classes used by
748 // the parser. 750 // the parser.
749 class ParserFinder { 751 class ParserFinder {
750 protected: 752 protected:
751 ParserFinder() {} 753 ParserFinder() {}
752 static Assignment* AsAssignment(Statement* stat) { 754 static Assignment* AsAssignment(Statement* stat) {
753 if (stat == NULL) return NULL; 755 if (stat == NULL) return NULL;
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
1189 // The name was declared before; check for conflicting 1191 // The name was declared before; check for conflicting
1190 // re-declarations. If the previous declaration was a const or the 1192 // re-declarations. If the previous declaration was a const or the
1191 // current declaration is a const then we have a conflict. There is 1193 // current declaration is a const then we have a conflict. There is
1192 // similar code in runtime.cc in the Declare functions. 1194 // similar code in runtime.cc in the Declare functions.
1193 if ((mode == Variable::CONST) || (var->mode() == Variable::CONST)) { 1195 if ((mode == Variable::CONST) || (var->mode() == Variable::CONST)) {
1194 // We only have vars and consts in declarations. 1196 // We only have vars and consts in declarations.
1195 ASSERT(var->mode() == Variable::VAR || 1197 ASSERT(var->mode() == Variable::VAR ||
1196 var->mode() == Variable::CONST); 1198 var->mode() == Variable::CONST);
1197 const char* type = (var->mode() == Variable::VAR) ? "var" : "const"; 1199 const char* type = (var->mode() == Variable::VAR) ? "var" : "const";
1198 Handle<String> type_string = 1200 Handle<String> type_string =
1199 FACTORY->NewStringFromUtf8(CStrVector(type), TENURED); 1201 isolate()->factory()->NewStringFromUtf8(CStrVector(type), TENURED);
1200 Expression* expression = 1202 Expression* expression =
1201 NewThrowTypeError(FACTORY->redeclaration_symbol(), 1203 NewThrowTypeError(isolate()->factory()->redeclaration_symbol(),
1202 type_string, name); 1204 type_string, name);
1203 top_scope_->SetIllegalRedeclaration(expression); 1205 top_scope_->SetIllegalRedeclaration(expression);
1204 } 1206 }
1205 } 1207 }
1206 } 1208 }
1207 1209
1208 // We add a declaration node for every declaration. The compiler 1210 // We add a declaration node for every declaration. The compiler
1209 // will only generate code if necessary. In particular, declarations 1211 // will only generate code if necessary. In particular, declarations
1210 // for inner local variables that do not represent functions won't 1212 // for inner local variables that do not represent functions won't
1211 // result in any generated code. 1213 // result in any generated code.
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1297 v8::Handle<v8::FunctionTemplate> fun_template = 1299 v8::Handle<v8::FunctionTemplate> fun_template =
1298 extension_->GetNativeFunction(v8::Utils::ToLocal(name)); 1300 extension_->GetNativeFunction(v8::Utils::ToLocal(name));
1299 ASSERT(!fun_template.IsEmpty()); 1301 ASSERT(!fun_template.IsEmpty());
1300 1302
1301 // Instantiate the function and create a shared function info from it. 1303 // Instantiate the function and create a shared function info from it.
1302 Handle<JSFunction> fun = Utils::OpenHandle(*fun_template->GetFunction()); 1304 Handle<JSFunction> fun = Utils::OpenHandle(*fun_template->GetFunction());
1303 const int literals = fun->NumberOfLiterals(); 1305 const int literals = fun->NumberOfLiterals();
1304 Handle<Code> code = Handle<Code>(fun->shared()->code()); 1306 Handle<Code> code = Handle<Code>(fun->shared()->code());
1305 Handle<Code> construct_stub = Handle<Code>(fun->shared()->construct_stub()); 1307 Handle<Code> construct_stub = Handle<Code>(fun->shared()->construct_stub());
1306 Handle<SharedFunctionInfo> shared = 1308 Handle<SharedFunctionInfo> shared =
1307 FACTORY->NewSharedFunctionInfo(name, literals, code, 1309 isolate()->factory()->NewSharedFunctionInfo(name, literals, code,
1308 Handle<SerializedScopeInfo>(fun->shared()->scope_info())); 1310 Handle<SerializedScopeInfo>(fun->shared()->scope_info()));
1309 shared->set_construct_stub(*construct_stub); 1311 shared->set_construct_stub(*construct_stub);
1310 1312
1311 // Copy the function data to the shared function info. 1313 // Copy the function data to the shared function info.
1312 shared->set_function_data(fun->shared()->function_data()); 1314 shared->set_function_data(fun->shared()->function_data());
1313 int parameters = fun->shared()->formal_parameter_count(); 1315 int parameters = fun->shared()->formal_parameter_count();
1314 shared->set_formal_parameter_count(parameters); 1316 shared->set_formal_parameter_count(parameters);
1315 1317
1316 // TODO(1240846): It's weird that native function declarations are 1318 // TODO(1240846): It's weird that native function declarations are
1317 // introduced dynamically when we meet their declarations, whereas 1319 // introduced dynamically when we meet their declarations, whereas
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
1512 value = NULL; // zap the value to avoid the unnecessary assignment 1514 value = NULL; // zap the value to avoid the unnecessary assignment
1513 } 1515 }
1514 // Construct the call to Runtime::DeclareGlobal{Variable,Const}Locally 1516 // Construct the call to Runtime::DeclareGlobal{Variable,Const}Locally
1515 // and add it to the initialization statement block. Note that 1517 // and add it to the initialization statement block. Note that
1516 // this function does different things depending on if we have 1518 // this function does different things depending on if we have
1517 // 1 or 2 parameters. 1519 // 1 or 2 parameters.
1518 CallRuntime* initialize; 1520 CallRuntime* initialize;
1519 if (is_const) { 1521 if (is_const) {
1520 initialize = 1522 initialize =
1521 new CallRuntime( 1523 new CallRuntime(
1522 FACTORY->InitializeConstGlobal_symbol(), 1524 isolate()->factory()->InitializeConstGlobal_symbol(),
1523 Runtime::FunctionForId(Runtime::kInitializeConstGlobal), 1525 Runtime::FunctionForId(Runtime::kInitializeConstGlobal),
1524 arguments); 1526 arguments);
1525 } else { 1527 } else {
1526 initialize = 1528 initialize =
1527 new CallRuntime( 1529 new CallRuntime(
1528 FACTORY->InitializeVarGlobal_symbol(), 1530 isolate()->factory()->InitializeVarGlobal_symbol(),
1529 Runtime::FunctionForId(Runtime::kInitializeVarGlobal), 1531 Runtime::FunctionForId(Runtime::kInitializeVarGlobal),
1530 arguments); 1532 arguments);
1531 } 1533 }
1532 block->AddStatement(new ExpressionStatement(initialize)); 1534 block->AddStatement(new ExpressionStatement(initialize));
1533 } 1535 }
1534 1536
1535 // Add an assignment node to the initialization statement block if 1537 // Add an assignment node to the initialization statement block if
1536 // we still have a pending initialization value. We must distinguish 1538 // we still have a pending initialization value. We must distinguish
1537 // between variables and constants: Variable initializations are simply 1539 // between variables and constants: Variable initializations are simply
1538 // assignments (with all the consequences if they are inside a 'with' 1540 // assignments (with all the consequences if they are inside a 'with'
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1644 Token::Value tok = peek(); 1646 Token::Value tok = peek();
1645 if (!scanner_.has_line_terminator_before_next() && 1647 if (!scanner_.has_line_terminator_before_next() &&
1646 tok != Token::SEMICOLON && tok != Token::RBRACE && tok != Token::EOS) { 1648 tok != Token::SEMICOLON && tok != Token::RBRACE && tok != Token::EOS) {
1647 label = ParseIdentifier(CHECK_OK); 1649 label = ParseIdentifier(CHECK_OK);
1648 } 1650 }
1649 IterationStatement* target = NULL; 1651 IterationStatement* target = NULL;
1650 target = LookupContinueTarget(label, CHECK_OK); 1652 target = LookupContinueTarget(label, CHECK_OK);
1651 if (target == NULL) { 1653 if (target == NULL) {
1652 // Illegal continue statement. To be consistent with KJS we delay 1654 // Illegal continue statement. To be consistent with KJS we delay
1653 // reporting of the syntax error until runtime. 1655 // reporting of the syntax error until runtime.
1654 Handle<String> error_type = FACTORY->illegal_continue_symbol(); 1656 Handle<String> error_type = isolate()->factory()->illegal_continue_symbol();
1655 if (!label.is_null()) error_type = FACTORY->unknown_label_symbol(); 1657 if (!label.is_null()) {
1658 error_type = isolate()->factory()->unknown_label_symbol();
1659 }
1656 Expression* throw_error = NewThrowSyntaxError(error_type, label); 1660 Expression* throw_error = NewThrowSyntaxError(error_type, label);
1657 return new ExpressionStatement(throw_error); 1661 return new ExpressionStatement(throw_error);
1658 } 1662 }
1659 ExpectSemicolon(CHECK_OK); 1663 ExpectSemicolon(CHECK_OK);
1660 return new ContinueStatement(target); 1664 return new ContinueStatement(target);
1661 } 1665 }
1662 1666
1663 1667
1664 Statement* Parser::ParseBreakStatement(ZoneStringList* labels, bool* ok) { 1668 Statement* Parser::ParseBreakStatement(ZoneStringList* labels, bool* ok) {
1665 // BreakStatement :: 1669 // BreakStatement ::
1666 // 'break' Identifier? ';' 1670 // 'break' Identifier? ';'
1667 1671
1668 Expect(Token::BREAK, CHECK_OK); 1672 Expect(Token::BREAK, CHECK_OK);
1669 Handle<String> label; 1673 Handle<String> label;
1670 Token::Value tok = peek(); 1674 Token::Value tok = peek();
1671 if (!scanner_.has_line_terminator_before_next() && 1675 if (!scanner_.has_line_terminator_before_next() &&
1672 tok != Token::SEMICOLON && tok != Token::RBRACE && tok != Token::EOS) { 1676 tok != Token::SEMICOLON && tok != Token::RBRACE && tok != Token::EOS) {
1673 label = ParseIdentifier(CHECK_OK); 1677 label = ParseIdentifier(CHECK_OK);
1674 } 1678 }
1675 // Parse labeled break statements that target themselves into 1679 // Parse labeled break statements that target themselves into
1676 // empty statements, e.g. 'l1: l2: l3: break l2;' 1680 // empty statements, e.g. 'l1: l2: l3: break l2;'
1677 if (!label.is_null() && ContainsLabel(labels, label)) { 1681 if (!label.is_null() && ContainsLabel(labels, label)) {
1678 return EmptyStatement(); 1682 return EmptyStatement();
1679 } 1683 }
1680 BreakableStatement* target = NULL; 1684 BreakableStatement* target = NULL;
1681 target = LookupBreakTarget(label, CHECK_OK); 1685 target = LookupBreakTarget(label, CHECK_OK);
1682 if (target == NULL) { 1686 if (target == NULL) {
1683 // Illegal break statement. To be consistent with KJS we delay 1687 // Illegal break statement. To be consistent with KJS we delay
1684 // reporting of the syntax error until runtime. 1688 // reporting of the syntax error until runtime.
1685 Handle<String> error_type = FACTORY->illegal_break_symbol(); 1689 Handle<String> error_type = isolate()->factory()->illegal_break_symbol();
1686 if (!label.is_null()) error_type = FACTORY->unknown_label_symbol(); 1690 if (!label.is_null()) {
1691 error_type = isolate()->factory()->unknown_label_symbol();
1692 }
1687 Expression* throw_error = NewThrowSyntaxError(error_type, label); 1693 Expression* throw_error = NewThrowSyntaxError(error_type, label);
1688 return new ExpressionStatement(throw_error); 1694 return new ExpressionStatement(throw_error);
1689 } 1695 }
1690 ExpectSemicolon(CHECK_OK); 1696 ExpectSemicolon(CHECK_OK);
1691 return new BreakStatement(target); 1697 return new BreakStatement(target);
1692 } 1698 }
1693 1699
1694 1700
1695 Statement* Parser::ParseReturnStatement(bool* ok) { 1701 Statement* Parser::ParseReturnStatement(bool* ok) {
1696 // ReturnStatement :: 1702 // ReturnStatement ::
1697 // 'return' Expression? ';' 1703 // 'return' Expression? ';'
1698 1704
1699 // Consume the return token. It is necessary to do the before 1705 // Consume the return token. It is necessary to do the before
1700 // reporting any errors on it, because of the way errors are 1706 // reporting any errors on it, because of the way errors are
1701 // reported (underlining). 1707 // reported (underlining).
1702 Expect(Token::RETURN, CHECK_OK); 1708 Expect(Token::RETURN, CHECK_OK);
1703 1709
1704 // An ECMAScript program is considered syntactically incorrect if it 1710 // An ECMAScript program is considered syntactically incorrect if it
1705 // contains a return statement that is not within the body of a 1711 // contains a return statement that is not within the body of a
1706 // function. See ECMA-262, section 12.9, page 67. 1712 // function. See ECMA-262, section 12.9, page 67.
1707 // 1713 //
1708 // To be consistent with KJS we report the syntax error at runtime. 1714 // To be consistent with KJS we report the syntax error at runtime.
1709 if (!top_scope_->is_function_scope()) { 1715 if (!top_scope_->is_function_scope()) {
1710 Handle<String> type = FACTORY->illegal_return_symbol(); 1716 Handle<String> type = isolate()->factory()->illegal_return_symbol();
1711 Expression* throw_error = NewThrowSyntaxError(type, Handle<Object>::null()); 1717 Expression* throw_error = NewThrowSyntaxError(type, Handle<Object>::null());
1712 return new ExpressionStatement(throw_error); 1718 return new ExpressionStatement(throw_error);
1713 } 1719 }
1714 1720
1715 Token::Value tok = peek(); 1721 Token::Value tok = peek();
1716 if (scanner_.has_line_terminator_before_next() || 1722 if (scanner_.has_line_terminator_before_next() ||
1717 tok == Token::SEMICOLON || 1723 tok == Token::SEMICOLON ||
1718 tok == Token::RBRACE || 1724 tok == Token::RBRACE ||
1719 tok == Token::EOS) { 1725 tok == Token::EOS) {
1720 ExpectSemicolon(CHECK_OK); 1726 ExpectSemicolon(CHECK_OK);
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
1901 has_catch = true; 1907 has_catch = true;
1902 Consume(Token::CATCH); 1908 Consume(Token::CATCH);
1903 1909
1904 Expect(Token::LPAREN, CHECK_OK); 1910 Expect(Token::LPAREN, CHECK_OK);
1905 Handle<String> name = ParseIdentifier(CHECK_OK); 1911 Handle<String> name = ParseIdentifier(CHECK_OK);
1906 Expect(Token::RPAREN, CHECK_OK); 1912 Expect(Token::RPAREN, CHECK_OK);
1907 1913
1908 if (peek() == Token::LBRACE) { 1914 if (peek() == Token::LBRACE) {
1909 // Allocate a temporary for holding the finally state while 1915 // Allocate a temporary for holding the finally state while
1910 // executing the finally block. 1916 // executing the finally block.
1911 catch_var = top_scope_->NewTemporary(FACTORY->catch_var_symbol()); 1917 catch_var =
1918 top_scope_->NewTemporary(isolate()->factory()->catch_var_symbol());
1912 Literal* name_literal = new Literal(name); 1919 Literal* name_literal = new Literal(name);
1913 VariableProxy* catch_var_use = new VariableProxy(catch_var); 1920 VariableProxy* catch_var_use = new VariableProxy(catch_var);
1914 Expression* obj = new CatchExtensionObject(name_literal, catch_var_use); 1921 Expression* obj = new CatchExtensionObject(name_literal, catch_var_use);
1915 { Target target(&this->target_stack_, &catch_collector); 1922 { Target target(&this->target_stack_, &catch_collector);
1916 catch_block = WithHelper(obj, NULL, true, CHECK_OK); 1923 catch_block = WithHelper(obj, NULL, true, CHECK_OK);
1917 } 1924 }
1918 } else { 1925 } else {
1919 Expect(Token::LBRACE, CHECK_OK); 1926 Expect(Token::LBRACE, CHECK_OK);
1920 } 1927 }
1921 1928
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
2052 } 2059 }
2053 2060
2054 } else { 2061 } else {
2055 Expression* expression = ParseExpression(false, CHECK_OK); 2062 Expression* expression = ParseExpression(false, CHECK_OK);
2056 if (peek() == Token::IN) { 2063 if (peek() == Token::IN) {
2057 // Signal a reference error if the expression is an invalid 2064 // Signal a reference error if the expression is an invalid
2058 // left-hand side expression. We could report this as a syntax 2065 // left-hand side expression. We could report this as a syntax
2059 // error here but for compatibility with JSC we choose to report 2066 // error here but for compatibility with JSC we choose to report
2060 // the error at runtime. 2067 // the error at runtime.
2061 if (expression == NULL || !expression->IsValidLeftHandSide()) { 2068 if (expression == NULL || !expression->IsValidLeftHandSide()) {
2062 Handle<String> type = FACTORY->invalid_lhs_in_for_in_symbol(); 2069 Handle<String> type =
2070 isolate()->factory()->invalid_lhs_in_for_in_symbol();
2063 expression = NewThrowReferenceError(type); 2071 expression = NewThrowReferenceError(type);
2064 } 2072 }
2065 ForInStatement* loop = new ForInStatement(labels); 2073 ForInStatement* loop = new ForInStatement(labels);
2066 Target target(&this->target_stack_, loop); 2074 Target target(&this->target_stack_, loop);
2067 2075
2068 Expect(Token::IN, CHECK_OK); 2076 Expect(Token::IN, CHECK_OK);
2069 Expression* enumerable = ParseExpression(true, CHECK_OK); 2077 Expression* enumerable = ParseExpression(true, CHECK_OK);
2070 Expect(Token::RPAREN, CHECK_OK); 2078 Expect(Token::RPAREN, CHECK_OK);
2071 2079
2072 Statement* body = ParseStatement(NULL, CHECK_OK); 2080 Statement* body = ParseStatement(NULL, CHECK_OK);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
2137 if (fni_ != NULL) fni_->Leave(); 2145 if (fni_ != NULL) fni_->Leave();
2138 // Parsed conditional expression only (no assignment). 2146 // Parsed conditional expression only (no assignment).
2139 return expression; 2147 return expression;
2140 } 2148 }
2141 2149
2142 // Signal a reference error if the expression is an invalid left-hand 2150 // Signal a reference error if the expression is an invalid left-hand
2143 // side expression. We could report this as a syntax error here but 2151 // side expression. We could report this as a syntax error here but
2144 // for compatibility with JSC we choose to report the error at 2152 // for compatibility with JSC we choose to report the error at
2145 // runtime. 2153 // runtime.
2146 if (expression == NULL || !expression->IsValidLeftHandSide()) { 2154 if (expression == NULL || !expression->IsValidLeftHandSide()) {
2147 Handle<String> type = FACTORY->invalid_lhs_in_assignment_symbol(); 2155 Handle<String> type =
2156 isolate()->factory()->invalid_lhs_in_assignment_symbol();
2148 expression = NewThrowReferenceError(type); 2157 expression = NewThrowReferenceError(type);
2149 } 2158 }
2150 2159
2151 Token::Value op = Next(); // Get assignment operator. 2160 Token::Value op = Next(); // Get assignment operator.
2152 int pos = scanner().location().beg_pos; 2161 int pos = scanner().location().beg_pos;
2153 Expression* right = ParseAssignmentExpression(accept_IN, CHECK_OK); 2162 Expression* right = ParseAssignmentExpression(accept_IN, CHECK_OK);
2154 2163
2155 // TODO(1231235): We try to estimate the set of properties set by 2164 // TODO(1231235): We try to estimate the set of properties set by
2156 // constructors. We define a new property whenever there is an 2165 // constructors. We define a new property whenever there is an
2157 // assignment to a property of 'this'. We should probably only add 2166 // assignment to a property of 'this'. We should probably only add
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
2384 return new UnaryOperation(op, expression); 2393 return new UnaryOperation(op, expression);
2385 2394
2386 } else if (Token::IsCountOp(op)) { 2395 } else if (Token::IsCountOp(op)) {
2387 op = Next(); 2396 op = Next();
2388 Expression* expression = ParseUnaryExpression(CHECK_OK); 2397 Expression* expression = ParseUnaryExpression(CHECK_OK);
2389 // Signal a reference error if the expression is an invalid 2398 // Signal a reference error if the expression is an invalid
2390 // left-hand side expression. We could report this as a syntax 2399 // left-hand side expression. We could report this as a syntax
2391 // error here but for compatibility with JSC we choose to report the 2400 // error here but for compatibility with JSC we choose to report the
2392 // error at runtime. 2401 // error at runtime.
2393 if (expression == NULL || !expression->IsValidLeftHandSide()) { 2402 if (expression == NULL || !expression->IsValidLeftHandSide()) {
2394 Handle<String> type = FACTORY->invalid_lhs_in_prefix_op_symbol(); 2403 Handle<String> type =
2404 isolate()->factory()->invalid_lhs_in_prefix_op_symbol();
2395 expression = NewThrowReferenceError(type); 2405 expression = NewThrowReferenceError(type);
2396 } 2406 }
2397 int position = scanner().location().beg_pos; 2407 int position = scanner().location().beg_pos;
2398 IncrementOperation* increment = new IncrementOperation(op, expression); 2408 IncrementOperation* increment = new IncrementOperation(op, expression);
2399 return new CountOperation(true /* prefix */, increment, position); 2409 return new CountOperation(true /* prefix */, increment, position);
2400 2410
2401 } else { 2411 } else {
2402 return ParsePostfixExpression(ok); 2412 return ParsePostfixExpression(ok);
2403 } 2413 }
2404 } 2414 }
2405 2415
2406 2416
2407 Expression* Parser::ParsePostfixExpression(bool* ok) { 2417 Expression* Parser::ParsePostfixExpression(bool* ok) {
2408 // PostfixExpression :: 2418 // PostfixExpression ::
2409 // LeftHandSideExpression ('++' | '--')? 2419 // LeftHandSideExpression ('++' | '--')?
2410 2420
2411 Expression* expression = ParseLeftHandSideExpression(CHECK_OK); 2421 Expression* expression = ParseLeftHandSideExpression(CHECK_OK);
2412 if (!scanner_.has_line_terminator_before_next() && Token::IsCountOp(peek())) { 2422 if (!scanner_.has_line_terminator_before_next() && Token::IsCountOp(peek())) {
2413 // Signal a reference error if the expression is an invalid 2423 // Signal a reference error if the expression is an invalid
2414 // left-hand side expression. We could report this as a syntax 2424 // left-hand side expression. We could report this as a syntax
2415 // error here but for compatibility with JSC we choose to report the 2425 // error here but for compatibility with JSC we choose to report the
2416 // error at runtime. 2426 // error at runtime.
2417 if (expression == NULL || !expression->IsValidLeftHandSide()) { 2427 if (expression == NULL || !expression->IsValidLeftHandSide()) {
2418 Handle<String> type = FACTORY->invalid_lhs_in_postfix_op_symbol(); 2428 Handle<String> type =
2429 isolate()->factory()->invalid_lhs_in_postfix_op_symbol();
2419 expression = NewThrowReferenceError(type); 2430 expression = NewThrowReferenceError(type);
2420 } 2431 }
2421 Token::Value next = Next(); 2432 Token::Value next = Next();
2422 int position = scanner().location().beg_pos; 2433 int position = scanner().location().beg_pos;
2423 IncrementOperation* increment = new IncrementOperation(next, expression); 2434 IncrementOperation* increment = new IncrementOperation(next, expression);
2424 expression = new CountOperation(false /* postfix */, increment, position); 2435 expression = new CountOperation(false /* postfix */, increment, position);
2425 } 2436 }
2426 return expression; 2437 return expression;
2427 } 2438 }
2428 2439
(...skipping 26 matching lines...) Expand all
2455 2466
2456 // Keep track of eval() calls since they disable all local variable 2467 // Keep track of eval() calls since they disable all local variable
2457 // optimizations. 2468 // optimizations.
2458 // The calls that need special treatment are the 2469 // The calls that need special treatment are the
2459 // direct (i.e. not aliased) eval calls. These calls are all of the 2470 // direct (i.e. not aliased) eval calls. These calls are all of the
2460 // form eval(...) with no explicit receiver object where eval is not 2471 // form eval(...) with no explicit receiver object where eval is not
2461 // declared in the current scope chain. These calls are marked as 2472 // declared in the current scope chain. These calls are marked as
2462 // potentially direct eval calls. Whether they are actually direct calls 2473 // potentially direct eval calls. Whether they are actually direct calls
2463 // to eval is determined at run time. 2474 // to eval is determined at run time.
2464 VariableProxy* callee = result->AsVariableProxy(); 2475 VariableProxy* callee = result->AsVariableProxy();
2465 if (callee != NULL && callee->IsVariable(FACTORY->eval_symbol())) { 2476 if (callee != NULL &&
2477 callee->IsVariable(isolate()->factory()->eval_symbol())) {
2466 Handle<String> name = callee->name(); 2478 Handle<String> name = callee->name();
2467 Variable* var = top_scope_->Lookup(name); 2479 Variable* var = top_scope_->Lookup(name);
2468 if (var == NULL) { 2480 if (var == NULL) {
2469 top_scope_->RecordEvalCall(); 2481 top_scope_->RecordEvalCall();
2470 } 2482 }
2471 } 2483 }
2472 result = NewCall(result, args, pos); 2484 result = NewCall(result, args, pos);
2473 break; 2485 break;
2474 } 2486 }
2475 2487
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
2648 switch (peek()) { 2660 switch (peek()) {
2649 case Token::THIS: { 2661 case Token::THIS: {
2650 Consume(Token::THIS); 2662 Consume(Token::THIS);
2651 VariableProxy* recv = top_scope_->receiver(); 2663 VariableProxy* recv = top_scope_->receiver();
2652 result = recv; 2664 result = recv;
2653 break; 2665 break;
2654 } 2666 }
2655 2667
2656 case Token::NULL_LITERAL: 2668 case Token::NULL_LITERAL:
2657 Consume(Token::NULL_LITERAL); 2669 Consume(Token::NULL_LITERAL);
2658 result = new Literal(FACTORY->null_value()); 2670 result = new Literal(isolate()->factory()->null_value());
2659 break; 2671 break;
2660 2672
2661 case Token::TRUE_LITERAL: 2673 case Token::TRUE_LITERAL:
2662 Consume(Token::TRUE_LITERAL); 2674 Consume(Token::TRUE_LITERAL);
2663 result = new Literal(FACTORY->true_value()); 2675 result = new Literal(isolate()->factory()->true_value());
2664 break; 2676 break;
2665 2677
2666 case Token::FALSE_LITERAL: 2678 case Token::FALSE_LITERAL:
2667 Consume(Token::FALSE_LITERAL); 2679 Consume(Token::FALSE_LITERAL);
2668 result = new Literal(FACTORY->false_value()); 2680 result = new Literal(isolate()->factory()->false_value());
2669 break; 2681 break;
2670 2682
2671 case Token::IDENTIFIER: { 2683 case Token::IDENTIFIER: {
2672 Handle<String> name = ParseIdentifier(CHECK_OK); 2684 Handle<String> name = ParseIdentifier(CHECK_OK);
2673 if (fni_ != NULL) fni_->PushVariableName(name); 2685 if (fni_ != NULL) fni_->PushVariableName(name);
2674 result = top_scope_->NewUnresolved(name, inside_with()); 2686 result = top_scope_->NewUnresolved(name, inside_with());
2675 break; 2687 break;
2676 } 2688 }
2677 2689
2678 case Token::NUMBER: { 2690 case Token::NUMBER: {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
2778 Expect(Token::COMMA, CHECK_OK); 2790 Expect(Token::COMMA, CHECK_OK);
2779 } 2791 }
2780 } 2792 }
2781 Expect(Token::RBRACK, CHECK_OK); 2793 Expect(Token::RBRACK, CHECK_OK);
2782 2794
2783 // Update the scope information before the pre-parsing bailout. 2795 // Update the scope information before the pre-parsing bailout.
2784 int literal_index = temp_scope_->NextMaterializedLiteralIndex(); 2796 int literal_index = temp_scope_->NextMaterializedLiteralIndex();
2785 2797
2786 // Allocate a fixed array with all the literals. 2798 // Allocate a fixed array with all the literals.
2787 Handle<FixedArray> literals = 2799 Handle<FixedArray> literals =
2788 FACTORY->NewFixedArray(values->length(), TENURED); 2800 isolate()->factory()->NewFixedArray(values->length(), TENURED);
2789 2801
2790 // Fill in the literals. 2802 // Fill in the literals.
2791 bool is_simple = true; 2803 bool is_simple = true;
2792 int depth = 1; 2804 int depth = 1;
2793 for (int i = 0, n = values->length(); i < n; i++) { 2805 for (int i = 0, n = values->length(); i < n; i++) {
2794 MaterializedLiteral* m_literal = values->at(i)->AsMaterializedLiteral(); 2806 MaterializedLiteral* m_literal = values->at(i)->AsMaterializedLiteral();
2795 if (m_literal != NULL && m_literal->depth() + 1 > depth) { 2807 if (m_literal != NULL && m_literal->depth() + 1 > depth) {
2796 depth = m_literal->depth() + 1; 2808 depth = m_literal->depth() + 1;
2797 } 2809 }
2798 Handle<Object> boilerplate_value = GetBoilerplateValue(values->at(i)); 2810 Handle<Object> boilerplate_value = GetBoilerplateValue(values->at(i));
2799 if (boilerplate_value->IsUndefined()) { 2811 if (boilerplate_value->IsUndefined()) {
2800 literals->set_the_hole(i); 2812 literals->set_the_hole(i);
2801 is_simple = false; 2813 is_simple = false;
2802 } else { 2814 } else {
2803 literals->set(i, *boilerplate_value); 2815 literals->set(i, *boilerplate_value);
2804 } 2816 }
2805 } 2817 }
2806 2818
2807 // Simple and shallow arrays can be lazily copied, we transform the 2819 // Simple and shallow arrays can be lazily copied, we transform the
2808 // elements array to a copy-on-write array. 2820 // elements array to a copy-on-write array.
2809 if (is_simple && depth == 1 && values->length() > 0) { 2821 if (is_simple && depth == 1 && values->length() > 0) {
2810 literals->set_map(HEAP->fixed_cow_array_map()); 2822 literals->set_map(isolate()->heap()->fixed_cow_array_map());
2811 } 2823 }
2812 2824
2813 return new ArrayLiteral(literals, values, 2825 return new ArrayLiteral(literals, values,
2814 literal_index, is_simple, depth); 2826 literal_index, is_simple, depth);
2815 } 2827 }
2816 2828
2817 2829
2818 bool Parser::IsBoilerplateProperty(ObjectLiteral::Property* property) { 2830 bool Parser::IsBoilerplateProperty(ObjectLiteral::Property* property) {
2819 return property != NULL && 2831 return property != NULL &&
2820 property->kind() != ObjectLiteral::Property::PROTOTYPE; 2832 property->kind() != ObjectLiteral::Property::PROTOTYPE;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
2873 } 2885 }
2874 2886
2875 2887
2876 Handle<Object> Parser::GetBoilerplateValue(Expression* expression) { 2888 Handle<Object> Parser::GetBoilerplateValue(Expression* expression) {
2877 if (expression->AsLiteral() != NULL) { 2889 if (expression->AsLiteral() != NULL) {
2878 return expression->AsLiteral()->handle(); 2890 return expression->AsLiteral()->handle();
2879 } 2891 }
2880 if (CompileTimeValue::IsCompileTimeValue(expression)) { 2892 if (CompileTimeValue::IsCompileTimeValue(expression)) {
2881 return CompileTimeValue::GetValue(expression); 2893 return CompileTimeValue::GetValue(expression);
2882 } 2894 }
2883 return FACTORY->undefined_value(); 2895 return isolate()->factory()->undefined_value();
2884 } 2896 }
2885 2897
2886 2898
2887 void Parser::BuildObjectLiteralConstantProperties( 2899 void Parser::BuildObjectLiteralConstantProperties(
2888 ZoneList<ObjectLiteral::Property*>* properties, 2900 ZoneList<ObjectLiteral::Property*>* properties,
2889 Handle<FixedArray> constant_properties, 2901 Handle<FixedArray> constant_properties,
2890 bool* is_simple, 2902 bool* is_simple,
2891 bool* fast_elements, 2903 bool* fast_elements,
2892 int* depth) { 2904 int* depth) {
2893 int position = 0; 2905 int position = 0;
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
3062 3074
3063 if (fni_ != NULL) { 3075 if (fni_ != NULL) {
3064 fni_->Infer(); 3076 fni_->Infer();
3065 fni_->Leave(); 3077 fni_->Leave();
3066 } 3078 }
3067 } 3079 }
3068 Expect(Token::RBRACE, CHECK_OK); 3080 Expect(Token::RBRACE, CHECK_OK);
3069 // Computation of literal_index must happen before pre parse bailout. 3081 // Computation of literal_index must happen before pre parse bailout.
3070 int literal_index = temp_scope_->NextMaterializedLiteralIndex(); 3082 int literal_index = temp_scope_->NextMaterializedLiteralIndex();
3071 3083
3072 Handle<FixedArray> constant_properties = 3084 Handle<FixedArray> constant_properties = isolate()->factory()->NewFixedArray(
3073 FACTORY->NewFixedArray(number_of_boilerplate_properties * 2, TENURED); 3085 number_of_boilerplate_properties * 2, TENURED);
3074 3086
3075 bool is_simple = true; 3087 bool is_simple = true;
3076 bool fast_elements = true; 3088 bool fast_elements = true;
3077 int depth = 1; 3089 int depth = 1;
3078 BuildObjectLiteralConstantProperties(properties, 3090 BuildObjectLiteralConstantProperties(properties,
3079 constant_properties, 3091 constant_properties,
3080 &is_simple, 3092 &is_simple,
3081 &fast_elements, 3093 &fast_elements,
3082 &depth); 3094 &depth);
3083 return new ObjectLiteral(constant_properties, 3095 return new ObjectLiteral(constant_properties,
3084 properties, 3096 properties,
3085 literal_index, 3097 literal_index,
3086 is_simple, 3098 is_simple,
3087 fast_elements, 3099 fast_elements,
3088 depth); 3100 depth);
3089 } 3101 }
3090 3102
3091 3103
3092 Expression* Parser::ParseRegExpLiteral(bool seen_equal, bool* ok) { 3104 Expression* Parser::ParseRegExpLiteral(bool seen_equal, bool* ok) {
3093 if (!scanner_.ScanRegExpPattern(seen_equal)) { 3105 if (!scanner_.ScanRegExpPattern(seen_equal)) {
3094 Next(); 3106 Next();
3095 ReportMessage("unterminated_regexp", Vector<const char*>::empty()); 3107 ReportMessage("unterminated_regexp", Vector<const char*>::empty());
3096 *ok = false; 3108 *ok = false;
3097 return NULL; 3109 return NULL;
3098 } 3110 }
3099 3111
3100 int literal_index = temp_scope_->NextMaterializedLiteralIndex(); 3112 int literal_index = temp_scope_->NextMaterializedLiteralIndex();
3101 3113
3102 Handle<String> js_pattern = 3114 Handle<String> js_pattern =
3103 FACTORY->NewStringFromUtf8(scanner_.next_literal(), TENURED); 3115 isolate()->factory()->NewStringFromUtf8(scanner_.next_literal(), TENURED);
3104 scanner_.ScanRegExpFlags(); 3116 scanner_.ScanRegExpFlags();
3105 Handle<String> js_flags = 3117 Handle<String> js_flags =
3106 FACTORY->NewStringFromUtf8(scanner_.next_literal(), TENURED); 3118 isolate()->factory()->NewStringFromUtf8(scanner_.next_literal(), TENURED);
3107 Next(); 3119 Next();
3108 3120
3109 return new RegExpLiteral(js_pattern, js_flags, literal_index); 3121 return new RegExpLiteral(js_pattern, js_flags, literal_index);
3110 } 3122 }
3111 3123
3112 3124
3113 ZoneList<Expression*>* Parser::ParseArguments(bool* ok) { 3125 ZoneList<Expression*>* Parser::ParseArguments(bool* ok) {
3114 // Arguments :: 3126 // Arguments ::
3115 // '(' (AssignmentExpression)*[','] ')' 3127 // '(' (AssignmentExpression)*[','] ')'
3116 3128
(...skipping 16 matching lines...) Expand all
3133 FunctionLiteralType type, 3145 FunctionLiteralType type,
3134 bool* ok) { 3146 bool* ok) {
3135 // Function :: 3147 // Function ::
3136 // '(' FormalParameterList? ')' '{' FunctionBody '}' 3148 // '(' FormalParameterList? ')' '{' FunctionBody '}'
3137 bool is_named = !var_name.is_null(); 3149 bool is_named = !var_name.is_null();
3138 3150
3139 // The name associated with this function. If it's a function expression, 3151 // The name associated with this function. If it's a function expression,
3140 // this is the actual function name, otherwise this is the name of the 3152 // this is the actual function name, otherwise this is the name of the
3141 // variable declared and initialized with the function (expression). In 3153 // variable declared and initialized with the function (expression). In
3142 // that case, we don't have a function name (it's empty). 3154 // that case, we don't have a function name (it's empty).
3143 Handle<String> name = is_named ? var_name : FACTORY->empty_symbol(); 3155 Handle<String> name =
3156 is_named ? var_name : isolate()->factory()->empty_symbol();
3144 // The function name, if any. 3157 // The function name, if any.
3145 Handle<String> function_name = FACTORY->empty_symbol(); 3158 Handle<String> function_name = isolate()->factory()->empty_symbol();
3146 if (is_named && (type == EXPRESSION || type == NESTED)) { 3159 if (is_named && (type == EXPRESSION || type == NESTED)) {
3147 function_name = name; 3160 function_name = name;
3148 } 3161 }
3149 3162
3150 int num_parameters = 0; 3163 int num_parameters = 0;
3151 // Parse function body. 3164 // Parse function body.
3152 { Scope* scope = 3165 { Scope* scope =
3153 NewScope(top_scope_, Scope::FUNCTION_SCOPE, inside_with()); 3166 NewScope(top_scope_, Scope::FUNCTION_SCOPE, inside_with());
3154 LexicalScope lexical_scope(&this->top_scope_, &this->with_nesting_level_, 3167 LexicalScope lexical_scope(&this->top_scope_, &this->with_nesting_level_,
3155 scope); 3168 scope);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
3211 if (end_pos <= function_block_pos) { 3224 if (end_pos <= function_block_pos) {
3212 // End position greater than end of stream is safe, and hard to check. 3225 // End position greater than end of stream is safe, and hard to check.
3213 ReportInvalidPreparseData(name, CHECK_OK); 3226 ReportInvalidPreparseData(name, CHECK_OK);
3214 } 3227 }
3215 COUNTERS->total_preparse_skipped()->Increment( 3228 COUNTERS->total_preparse_skipped()->Increment(
3216 end_pos - function_block_pos); 3229 end_pos - function_block_pos);
3217 scanner_.SeekForward(end_pos); 3230 scanner_.SeekForward(end_pos);
3218 materialized_literal_count = entry.literal_count(); 3231 materialized_literal_count = entry.literal_count();
3219 expected_property_count = entry.property_count(); 3232 expected_property_count = entry.property_count();
3220 only_simple_this_property_assignments = false; 3233 only_simple_this_property_assignments = false;
3221 this_property_assignments = FACTORY->empty_fixed_array(); 3234 this_property_assignments = isolate()->factory()->empty_fixed_array();
3222 Expect(Token::RBRACE, CHECK_OK); 3235 Expect(Token::RBRACE, CHECK_OK);
3223 } else { 3236 } else {
3224 ParseSourceElements(body, Token::RBRACE, CHECK_OK); 3237 ParseSourceElements(body, Token::RBRACE, CHECK_OK);
3225 3238
3226 materialized_literal_count = temp_scope.materialized_literal_count(); 3239 materialized_literal_count = temp_scope.materialized_literal_count();
3227 expected_property_count = temp_scope.expected_property_count(); 3240 expected_property_count = temp_scope.expected_property_count();
3228 only_simple_this_property_assignments = 3241 only_simple_this_property_assignments =
3229 temp_scope.only_simple_this_property_assignments(); 3242 temp_scope.only_simple_this_property_assignments();
3230 this_property_assignments = temp_scope.this_property_assignments(); 3243 this_property_assignments = temp_scope.this_property_assignments();
3231 3244
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
3337 if (scanner_.has_line_terminator_before_next() || 3350 if (scanner_.has_line_terminator_before_next() ||
3338 tok == Token::RBRACE || 3351 tok == Token::RBRACE ||
3339 tok == Token::EOS) { 3352 tok == Token::EOS) {
3340 return; 3353 return;
3341 } 3354 }
3342 Expect(Token::SEMICOLON, ok); 3355 Expect(Token::SEMICOLON, ok);
3343 } 3356 }
3344 3357
3345 3358
3346 Literal* Parser::GetLiteralUndefined() { 3359 Literal* Parser::GetLiteralUndefined() {
3347 return new Literal(FACTORY->undefined_value()); 3360 return new Literal(isolate()->factory()->undefined_value());
3348 } 3361 }
3349 3362
3350 3363
3351 Literal* Parser::GetLiteralTheHole() { 3364 Literal* Parser::GetLiteralTheHole() {
3352 return new Literal(FACTORY->the_hole_value()); 3365 return new Literal(isolate()->factory()->the_hole_value());
3353 } 3366 }
3354 3367
3355 3368
3356 Literal* Parser::GetLiteralNumber(double value) { 3369 Literal* Parser::GetLiteralNumber(double value) {
3357 return NewNumberLiteral(value); 3370 return NewNumberLiteral(value);
3358 } 3371 }
3359 3372
3360 3373
3361 Handle<String> Parser::ParseIdentifier(bool* ok) { 3374 Handle<String> Parser::ParseIdentifier(bool* ok) {
3362 Expect(Token::IDENTIFIER, ok); 3375 Expect(Token::IDENTIFIER, ok);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
3445 // target stack has been used from the top of the target stack. Add 3458 // target stack has been used from the top of the target stack. Add
3446 // the break target to any TargetCollectors passed on the stack. 3459 // the break target to any TargetCollectors passed on the stack.
3447 for (Target* t = target_stack_; t != stop; t = t->previous()) { 3460 for (Target* t = target_stack_; t != stop; t = t->previous()) {
3448 TargetCollector* collector = t->node()->AsTargetCollector(); 3461 TargetCollector* collector = t->node()->AsTargetCollector();
3449 if (collector != NULL) collector->AddTarget(target); 3462 if (collector != NULL) collector->AddTarget(target);
3450 } 3463 }
3451 } 3464 }
3452 3465
3453 3466
3454 Literal* Parser::NewNumberLiteral(double number) { 3467 Literal* Parser::NewNumberLiteral(double number) {
3455 return new Literal(FACTORY->NewNumber(number, TENURED)); 3468 return new Literal(isolate()->factory()->NewNumber(number, TENURED));
3456 } 3469 }
3457 3470
3458 3471
3459 Expression* Parser::NewThrowReferenceError(Handle<String> type) { 3472 Expression* Parser::NewThrowReferenceError(Handle<String> type) {
3460 return NewThrowError(FACTORY->MakeReferenceError_symbol(), 3473 return NewThrowError(isolate()->factory()->MakeReferenceError_symbol(),
3461 type, HandleVector<Object>(NULL, 0)); 3474 type, HandleVector<Object>(NULL, 0));
3462 } 3475 }
3463 3476
3464 3477
3465 Expression* Parser::NewThrowSyntaxError(Handle<String> type, 3478 Expression* Parser::NewThrowSyntaxError(Handle<String> type,
3466 Handle<Object> first) { 3479 Handle<Object> first) {
3467 int argc = first.is_null() ? 0 : 1; 3480 int argc = first.is_null() ? 0 : 1;
3468 Vector< Handle<Object> > arguments = HandleVector<Object>(&first, argc); 3481 Vector< Handle<Object> > arguments = HandleVector<Object>(&first, argc);
3469 return NewThrowError(FACTORY->MakeSyntaxError_symbol(), type, arguments); 3482 return NewThrowError(
3483 isolate()->factory()->MakeSyntaxError_symbol(), type, arguments);
3470 } 3484 }
3471 3485
3472 3486
3473 Expression* Parser::NewThrowTypeError(Handle<String> type, 3487 Expression* Parser::NewThrowTypeError(Handle<String> type,
3474 Handle<Object> first, 3488 Handle<Object> first,
3475 Handle<Object> second) { 3489 Handle<Object> second) {
3476 ASSERT(!first.is_null() && !second.is_null()); 3490 ASSERT(!first.is_null() && !second.is_null());
3477 Handle<Object> elements[] = { first, second }; 3491 Handle<Object> elements[] = { first, second };
3478 Vector< Handle<Object> > arguments = 3492 Vector< Handle<Object> > arguments =
3479 HandleVector<Object>(elements, ARRAY_SIZE(elements)); 3493 HandleVector<Object>(elements, ARRAY_SIZE(elements));
3480 return NewThrowError(FACTORY->MakeTypeError_symbol(), type, arguments); 3494 return NewThrowError(
3495 isolate()->factory()->MakeTypeError_symbol(), type, arguments);
3481 } 3496 }
3482 3497
3483 3498
3484 Expression* Parser::NewThrowError(Handle<String> constructor, 3499 Expression* Parser::NewThrowError(Handle<String> constructor,
3485 Handle<String> type, 3500 Handle<String> type,
3486 Vector< Handle<Object> > arguments) { 3501 Vector< Handle<Object> > arguments) {
3487 int argc = arguments.length(); 3502 int argc = arguments.length();
3488 Handle<JSArray> array = FACTORY->NewJSArray(argc, TENURED); 3503 Handle<JSArray> array = isolate()->factory()->NewJSArray(argc, TENURED);
3489 ASSERT(array->IsJSArray() && array->HasFastElements()); 3504 ASSERT(array->IsJSArray() && array->HasFastElements());
3490 for (int i = 0; i < argc; i++) { 3505 for (int i = 0; i < argc; i++) {
3491 Handle<Object> element = arguments[i]; 3506 Handle<Object> element = arguments[i];
3492 if (!element.is_null()) { 3507 if (!element.is_null()) {
3493 // We know this doesn't cause a GC here because we allocated the JSArray 3508 // We know this doesn't cause a GC here because we allocated the JSArray
3494 // large enough. 3509 // large enough.
3495 array->SetFastElement(i, *element)->ToObjectUnchecked(); 3510 array->SetFastElement(i, *element)->ToObjectUnchecked();
3496 } 3511 }
3497 } 3512 }
3498 ZoneList<Expression*>* args = new ZoneList<Expression*>(2); 3513 ZoneList<Expression*>* args = new ZoneList<Expression*>(2);
3499 args->Add(new Literal(type)); 3514 args->Add(new Literal(type));
3500 args->Add(new Literal(array)); 3515 args->Add(new Literal(array));
3501 return new Throw(new CallRuntime(constructor, NULL, args), 3516 return new Throw(new CallRuntime(constructor, NULL, args),
3502 scanner().location().beg_pos); 3517 scanner().location().beg_pos);
3503 } 3518 }
3504 3519
3505 // ---------------------------------------------------------------------------- 3520 // ----------------------------------------------------------------------------
3506 // JSON 3521 // JSON
3507 3522
3508 Handle<Object> JsonParser::ParseJson(Handle<String> source) { 3523 Handle<Object> JsonParser::ParseJson(Handle<String> source) {
3509 source->TryFlatten(); 3524 source->TryFlatten();
3510 scanner_.Initialize(source); 3525 scanner_.Initialize(source);
3511 stack_overflow_ = false; 3526 stack_overflow_ = false;
3512 Handle<Object> result = ParseJsonValue(); 3527 Handle<Object> result = ParseJsonValue();
3513 if (result.is_null() || scanner_.Next() != Token::EOS) { 3528 if (result.is_null() || scanner_.Next() != Token::EOS) {
3514 if (stack_overflow_) { 3529 if (stack_overflow_) {
3515 // Scanner failed. 3530 // Scanner failed.
3516 Isolate::Current()->StackOverflow(); 3531 isolate()->StackOverflow();
3517 } else { 3532 } else {
3518 // Parse failed. Scanner's current token is the unexpected token. 3533 // Parse failed. Scanner's current token is the unexpected token.
3519 Token::Value token = scanner_.current_token(); 3534 Token::Value token = scanner_.current_token();
3520 3535
3521 const char* message; 3536 const char* message;
3522 const char* name_opt = NULL; 3537 const char* name_opt = NULL;
3523 3538
3524 switch (token) { 3539 switch (token) {
3525 case Token::EOS: 3540 case Token::EOS:
3526 message = "unexpected_eos"; 3541 message = "unexpected_eos";
3527 break; 3542 break;
3528 case Token::NUMBER: 3543 case Token::NUMBER:
3529 message = "unexpected_token_number"; 3544 message = "unexpected_token_number";
3530 break; 3545 break;
3531 case Token::STRING: 3546 case Token::STRING:
3532 message = "unexpected_token_string"; 3547 message = "unexpected_token_string";
3533 break; 3548 break;
3534 case Token::IDENTIFIER: 3549 case Token::IDENTIFIER:
3535 message = "unexpected_token_identifier"; 3550 message = "unexpected_token_identifier";
3536 break; 3551 break;
3537 default: 3552 default:
3538 message = "unexpected_token"; 3553 message = "unexpected_token";
3539 name_opt = Token::String(token); 3554 name_opt = Token::String(token);
3540 ASSERT(name_opt != NULL); 3555 ASSERT(name_opt != NULL);
3541 break; 3556 break;
3542 } 3557 }
3543 3558
3544 Scanner::Location source_location = scanner_.location(); 3559 Scanner::Location source_location = scanner_.location();
3545 MessageLocation location(FACTORY->NewScript(source), 3560 MessageLocation location(isolate()->factory()->NewScript(source),
3546 source_location.beg_pos, 3561 source_location.beg_pos,
3547 source_location.end_pos); 3562 source_location.end_pos);
3548 int argc = (name_opt == NULL) ? 0 : 1; 3563 int argc = (name_opt == NULL) ? 0 : 1;
3549 Handle<JSArray> array = FACTORY->NewJSArray(argc); 3564 Handle<JSArray> array = isolate()->factory()->NewJSArray(argc);
3550 if (name_opt != NULL) { 3565 if (name_opt != NULL) {
3551 SetElement(array, 3566 SetElement(
3552 0, 3567 array,
3553 FACTORY->NewStringFromUtf8(CStrVector(name_opt))); 3568 0,
3569 isolate()->factory()->NewStringFromUtf8(CStrVector(name_opt)));
3554 } 3570 }
3555 Handle<Object> result = FACTORY->NewSyntaxError(message, array); 3571 Handle<Object> result =
3556 Isolate::Current()->Throw(*result, &location); 3572 isolate()->factory()->NewSyntaxError(message, array);
3573 isolate()->Throw(*result, &location);
3557 return Handle<Object>::null(); 3574 return Handle<Object>::null();
3558 } 3575 }
3559 } 3576 }
3560 return result; 3577 return result;
3561 } 3578 }
3562 3579
3563 3580
3564 Handle<String> JsonParser::GetString() { 3581 Handle<String> JsonParser::GetString() {
3565 int literal_length = scanner_.literal_length(); 3582 int literal_length = scanner_.literal_length();
3566 if (literal_length == 0) { 3583 if (literal_length == 0) {
3567 return FACTORY->empty_string(); 3584 return isolate()->factory()->empty_string();
3568 } 3585 }
3569 const char* literal_string = scanner_.literal_string(); 3586 const char* literal_string = scanner_.literal_string();
3570 Vector<const char> literal(literal_string, literal_length); 3587 Vector<const char> literal(literal_string, literal_length);
3571 return FACTORY->NewStringFromUtf8(literal); 3588 return isolate()->factory()->NewStringFromUtf8(literal);
3572 } 3589 }
3573 3590
3574 3591
3575 // Parse any JSON value. 3592 // Parse any JSON value.
3576 Handle<Object> JsonParser::ParseJsonValue() { 3593 Handle<Object> JsonParser::ParseJsonValue() {
3577 Token::Value token = scanner_.Next(); 3594 Token::Value token = scanner_.Next();
3578 switch (token) { 3595 switch (token) {
3579 case Token::STRING: { 3596 case Token::STRING: {
3580 return GetString(); 3597 return GetString();
3581 } 3598 }
3582 case Token::NUMBER: { 3599 case Token::NUMBER: {
3583 double value = StringToDouble(scanner_.literal(), 3600 double value = StringToDouble(scanner_.literal(),
3584 NO_FLAGS, // Hex, octal or trailing junk. 3601 NO_FLAGS, // Hex, octal or trailing junk.
3585 OS::nan_value()); 3602 OS::nan_value());
3586 return FACTORY->NewNumber(value); 3603 return isolate()->factory()->NewNumber(value);
3587 } 3604 }
3588 case Token::FALSE_LITERAL: 3605 case Token::FALSE_LITERAL:
3589 return FACTORY->false_value(); 3606 return isolate()->factory()->false_value();
3590 case Token::TRUE_LITERAL: 3607 case Token::TRUE_LITERAL:
3591 return FACTORY->true_value(); 3608 return isolate()->factory()->true_value();
3592 case Token::NULL_LITERAL: 3609 case Token::NULL_LITERAL:
3593 return FACTORY->null_value(); 3610 return isolate()->factory()->null_value();
3594 case Token::LBRACE: 3611 case Token::LBRACE:
3595 return ParseJsonObject(); 3612 return ParseJsonObject();
3596 case Token::LBRACK: 3613 case Token::LBRACK:
3597 return ParseJsonArray(); 3614 return ParseJsonArray();
3598 default: 3615 default:
3599 return ReportUnexpectedToken(); 3616 return ReportUnexpectedToken();
3600 } 3617 }
3601 } 3618 }
3602 3619
3603 3620
3604 // Parse a JSON object. Scanner must be right after '{' token. 3621 // Parse a JSON object. Scanner must be right after '{' token.
3605 Handle<Object> JsonParser::ParseJsonObject() { 3622 Handle<Object> JsonParser::ParseJsonObject() {
3606 Isolate* isolate = Isolate::Current();
3607 Handle<JSFunction> object_constructor( 3623 Handle<JSFunction> object_constructor(
3608 isolate->global_context()->object_function()); 3624 isolate()->global_context()->object_function());
3609 Handle<JSObject> json_object = 3625 Handle<JSObject> json_object =
3610 isolate->factory()->NewJSObject(object_constructor); 3626 isolate()->factory()->NewJSObject(object_constructor);
3611 if (scanner_.peek() == Token::RBRACE) { 3627 if (scanner_.peek() == Token::RBRACE) {
3612 scanner_.Next(); 3628 scanner_.Next();
3613 } else { 3629 } else {
3614 if (StackLimitCheck(isolate).HasOverflowed()) { 3630 if (StackLimitCheck(isolate()).HasOverflowed()) {
3615 stack_overflow_ = true; 3631 stack_overflow_ = true;
3616 return Handle<Object>::null(); 3632 return Handle<Object>::null();
3617 } 3633 }
3618 do { 3634 do {
3619 if (scanner_.Next() != Token::STRING) { 3635 if (scanner_.Next() != Token::STRING) {
3620 return ReportUnexpectedToken(); 3636 return ReportUnexpectedToken();
3621 } 3637 }
3622 Handle<String> key = GetString(); 3638 Handle<String> key = GetString();
3623 if (scanner_.Next() != Token::COLON) { 3639 if (scanner_.Next() != Token::COLON) {
3624 return ReportUnexpectedToken(); 3640 return ReportUnexpectedToken();
(...skipping 17 matching lines...) Expand all
3642 3658
3643 // Parse a JSON array. Scanner must be right after '[' token. 3659 // Parse a JSON array. Scanner must be right after '[' token.
3644 Handle<Object> JsonParser::ParseJsonArray() { 3660 Handle<Object> JsonParser::ParseJsonArray() {
3645 ZoneScope zone_scope(DELETE_ON_EXIT); 3661 ZoneScope zone_scope(DELETE_ON_EXIT);
3646 ZoneList<Handle<Object> > elements(4); 3662 ZoneList<Handle<Object> > elements(4);
3647 3663
3648 Token::Value token = scanner_.peek(); 3664 Token::Value token = scanner_.peek();
3649 if (token == Token::RBRACK) { 3665 if (token == Token::RBRACK) {
3650 scanner_.Next(); 3666 scanner_.Next();
3651 } else { 3667 } else {
3652 if (StackLimitCheck(Isolate::Current()).HasOverflowed()) { 3668 if (StackLimitCheck(isolate()).HasOverflowed()) {
3653 stack_overflow_ = true; 3669 stack_overflow_ = true;
3654 return Handle<Object>::null(); 3670 return Handle<Object>::null();
3655 } 3671 }
3656 do { 3672 do {
3657 Handle<Object> element = ParseJsonValue(); 3673 Handle<Object> element = ParseJsonValue();
3658 if (element.is_null()) return Handle<Object>::null(); 3674 if (element.is_null()) return Handle<Object>::null();
3659 elements.Add(element); 3675 elements.Add(element);
3660 token = scanner_.Next(); 3676 token = scanner_.Next();
3661 } while (token == Token::COMMA); 3677 } while (token == Token::COMMA);
3662 if (token != Token::RBRACK) { 3678 if (token != Token::RBRACK) {
3663 return ReportUnexpectedToken(); 3679 return ReportUnexpectedToken();
3664 } 3680 }
3665 } 3681 }
3666 3682
3667 // Allocate a fixed array with all the elements. 3683 // Allocate a fixed array with all the elements.
3668 Handle<FixedArray> fast_elements = 3684 Handle<FixedArray> fast_elements =
3669 FACTORY->NewFixedArray(elements.length()); 3685 isolate()->factory()->NewFixedArray(elements.length());
3670 3686
3671 for (int i = 0, n = elements.length(); i < n; i++) { 3687 for (int i = 0, n = elements.length(); i < n; i++) {
3672 fast_elements->set(i, *elements[i]); 3688 fast_elements->set(i, *elements[i]);
3673 } 3689 }
3674 3690
3675 return FACTORY->NewJSArrayWithElements(fast_elements); 3691 return isolate()->factory()->NewJSArrayWithElements(fast_elements);
3676 } 3692 }
3677 3693
3678 // ---------------------------------------------------------------------------- 3694 // ----------------------------------------------------------------------------
3679 // Regular expressions 3695 // Regular expressions
3680 3696
3681 3697
3682 RegExpParser::RegExpParser(FlatStringReader* in, 3698 RegExpParser::RegExpParser(FlatStringReader* in,
3683 Handle<String>* error, 3699 Handle<String>* error,
3684 bool multiline) 3700 bool multiline)
3685 : error_(error), 3701 : isolate_(Isolate::Current()),
3686 captures_(NULL), 3702 error_(error),
3687 in_(in), 3703 captures_(NULL),
3688 current_(kEndMarker), 3704 in_(in),
3689 next_pos_(0), 3705 current_(kEndMarker),
3690 capture_count_(0), 3706 next_pos_(0),
3691 has_more_(true), 3707 capture_count_(0),
3692 multiline_(multiline), 3708 has_more_(true),
3693 simple_(false), 3709 multiline_(multiline),
3694 contains_anchor_(false), 3710 simple_(false),
3695 is_scanned_for_captures_(false), 3711 contains_anchor_(false),
3696 failed_(false) { 3712 is_scanned_for_captures_(false),
3713 failed_(false) {
3697 Advance(1); 3714 Advance(1);
3698 } 3715 }
3699 3716
3700 3717
3701 uc32 RegExpParser::Next() { 3718 uc32 RegExpParser::Next() {
3702 if (has_next()) { 3719 if (has_next()) {
3703 return in()->Get(next_pos_); 3720 return in()->Get(next_pos_);
3704 } else { 3721 } else {
3705 return kEndMarker; 3722 return kEndMarker;
3706 } 3723 }
3707 } 3724 }
3708 3725
3709 3726
3710 void RegExpParser::Advance() { 3727 void RegExpParser::Advance() {
3711 if (next_pos_ < in()->length()) { 3728 if (next_pos_ < in()->length()) {
3712 Isolate* isolate = Isolate::Current(); 3729 StackLimitCheck check(isolate());
3713 StackLimitCheck check(isolate);
3714 if (check.HasOverflowed()) { 3730 if (check.HasOverflowed()) {
3715 ReportError(CStrVector(Isolate::kStackOverflowMessage)); 3731 ReportError(CStrVector(Isolate::kStackOverflowMessage));
3716 } else if (isolate->zone()->excess_allocation()) { 3732 } else if (isolate()->zone()->excess_allocation()) {
3717 ReportError(CStrVector("Regular expression too large")); 3733 ReportError(CStrVector("Regular expression too large"));
3718 } else { 3734 } else {
3719 current_ = in()->Get(next_pos_); 3735 current_ = in()->Get(next_pos_);
3720 next_pos_++; 3736 next_pos_++;
3721 } 3737 }
3722 } else { 3738 } else {
3723 current_ = kEndMarker; 3739 current_ = kEndMarker;
3724 has_more_ = false; 3740 has_more_ = false;
3725 } 3741 }
3726 } 3742 }
(...skipping 10 matching lines...) Expand all
3737 Advance(); 3753 Advance();
3738 } 3754 }
3739 3755
3740 3756
3741 bool RegExpParser::simple() { 3757 bool RegExpParser::simple() {
3742 return simple_; 3758 return simple_;
3743 } 3759 }
3744 3760
3745 RegExpTree* RegExpParser::ReportError(Vector<const char> message) { 3761 RegExpTree* RegExpParser::ReportError(Vector<const char> message) {
3746 failed_ = true; 3762 failed_ = true;
3747 *error_ = FACTORY->NewStringFromAscii(message, NOT_TENURED); 3763 *error_ = isolate()->factory()->NewStringFromAscii(message, NOT_TENURED);
3748 // Zip to the end to make sure the no more input is read. 3764 // Zip to the end to make sure the no more input is read.
3749 current_ = kEndMarker; 3765 current_ = kEndMarker;
3750 next_pos_ = in()->length(); 3766 next_pos_ = in()->length();
3751 return NULL; 3767 return NULL;
3752 } 3768 }
3753 3769
3754 3770
3755 // Pattern :: 3771 // Pattern ::
3756 // Disjunction 3772 // Disjunction
3757 RegExpTree* RegExpParser::ParsePattern() { 3773 RegExpTree* RegExpParser::ParsePattern() {
(...skipping 883 matching lines...) Expand 10 before | Expand all | Expand 10 after
4641 Handle<String> source = Handle<String>(String::cast(script->source())); 4657 Handle<String> source = Handle<String>(String::cast(script->source()));
4642 result = parser.ParseProgram(source, info->is_global()); 4658 result = parser.ParseProgram(source, info->is_global());
4643 } 4659 }
4644 } 4660 }
4645 4661
4646 info->SetFunction(result); 4662 info->SetFunction(result);
4647 return (result != NULL); 4663 return (result != NULL);
4648 } 4664 }
4649 4665
4650 } } // namespace v8::internal 4666 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/parser.h ('k') | src/x64/full-codegen-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698