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

Side by Side Diff: src/parser.cc

Issue 7399023: Pass isolate to AST ID functions. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: A bit less ugly Created 9 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « src/parser.h ('k') | src/rewriter.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 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 630 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 } 641 }
642 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16); 642 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16);
643 bool ok = true; 643 bool ok = true;
644 int beg_loc = scanner().location().beg_pos; 644 int beg_loc = scanner().location().beg_pos;
645 ParseSourceElements(body, Token::EOS, &ok); 645 ParseSourceElements(body, Token::EOS, &ok);
646 if (ok && top_scope_->is_strict_mode()) { 646 if (ok && top_scope_->is_strict_mode()) {
647 CheckOctalLiteral(beg_loc, scanner().location().end_pos, &ok); 647 CheckOctalLiteral(beg_loc, scanner().location().end_pos, &ok);
648 } 648 }
649 if (ok) { 649 if (ok) {
650 result = new(zone()) FunctionLiteral( 650 result = new(zone()) FunctionLiteral(
651 isolate(),
651 no_name, 652 no_name,
652 top_scope_, 653 top_scope_,
653 body, 654 body,
654 lexical_scope.materialized_literal_count(), 655 lexical_scope.materialized_literal_count(),
655 lexical_scope.expected_property_count(), 656 lexical_scope.expected_property_count(),
656 lexical_scope.only_simple_this_property_assignments(), 657 lexical_scope.only_simple_this_property_assignments(),
657 lexical_scope.this_property_assignments(), 658 lexical_scope.this_property_assignments(),
658 0, 659 0,
659 0, 660 0,
660 source->length(), 661 source->length(),
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after
1255 case Token::THROW: 1256 case Token::THROW:
1256 stmt = ParseThrowStatement(ok); 1257 stmt = ParseThrowStatement(ok);
1257 break; 1258 break;
1258 1259
1259 case Token::TRY: { 1260 case Token::TRY: {
1260 // NOTE: It is somewhat complicated to have labels on 1261 // NOTE: It is somewhat complicated to have labels on
1261 // try-statements. When breaking out of a try-finally statement, 1262 // try-statements. When breaking out of a try-finally statement,
1262 // one must take great care not to treat it as a 1263 // one must take great care not to treat it as a
1263 // fall-through. It is much easier just to wrap the entire 1264 // fall-through. It is much easier just to wrap the entire
1264 // try-statement in a statement block and put the labels there 1265 // try-statement in a statement block and put the labels there
1265 Block* result = new(zone()) Block(labels, 1, false); 1266 Block* result = new(zone()) Block(isolate(), labels, 1, false);
1266 Target target(&this->target_stack_, result); 1267 Target target(&this->target_stack_, result);
1267 TryStatement* statement = ParseTryStatement(CHECK_OK); 1268 TryStatement* statement = ParseTryStatement(CHECK_OK);
1268 if (statement) { 1269 if (statement) {
1269 statement->set_statement_pos(statement_pos); 1270 statement->set_statement_pos(statement_pos);
1270 } 1271 }
1271 if (result) result->AddStatement(statement); 1272 if (result) result->AddStatement(statement);
1272 return result; 1273 return result;
1273 } 1274 }
1274 1275
1275 case Token::FUNCTION: { 1276 case Token::FUNCTION: {
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
1446 1447
1447 // Copy the function data to the shared function info. 1448 // Copy the function data to the shared function info.
1448 shared->set_function_data(fun->shared()->function_data()); 1449 shared->set_function_data(fun->shared()->function_data());
1449 int parameters = fun->shared()->formal_parameter_count(); 1450 int parameters = fun->shared()->formal_parameter_count();
1450 shared->set_formal_parameter_count(parameters); 1451 shared->set_formal_parameter_count(parameters);
1451 1452
1452 // TODO(1240846): It's weird that native function declarations are 1453 // TODO(1240846): It's weird that native function declarations are
1453 // introduced dynamically when we meet their declarations, whereas 1454 // introduced dynamically when we meet their declarations, whereas
1454 // other functions are setup when entering the surrounding scope. 1455 // other functions are setup when entering the surrounding scope.
1455 SharedFunctionInfoLiteral* lit = 1456 SharedFunctionInfoLiteral* lit =
1456 new(zone()) SharedFunctionInfoLiteral(shared); 1457 new(zone()) SharedFunctionInfoLiteral(isolate(), shared);
1457 VariableProxy* var = Declare(name, Variable::VAR, NULL, true, CHECK_OK); 1458 VariableProxy* var = Declare(name, Variable::VAR, NULL, true, CHECK_OK);
1458 return new(zone()) ExpressionStatement(new(zone()) Assignment( 1459 return new(zone()) ExpressionStatement(new(zone()) Assignment(
1459 Token::INIT_VAR, var, lit, RelocInfo::kNoPosition)); 1460 isolate(), Token::INIT_VAR, var, lit, RelocInfo::kNoPosition));
1460 } 1461 }
1461 1462
1462 1463
1463 Statement* Parser::ParseFunctionDeclaration(bool* ok) { 1464 Statement* Parser::ParseFunctionDeclaration(bool* ok) {
1464 // FunctionDeclaration :: 1465 // FunctionDeclaration ::
1465 // 'function' Identifier '(' FormalParameterListopt ')' '{' FunctionBody '}' 1466 // 'function' Identifier '(' FormalParameterListopt ')' '{' FunctionBody '}'
1466 Expect(Token::FUNCTION, CHECK_OK); 1467 Expect(Token::FUNCTION, CHECK_OK);
1467 int function_token_position = scanner().location().beg_pos; 1468 int function_token_position = scanner().location().beg_pos;
1468 bool is_strict_reserved = false; 1469 bool is_strict_reserved = false;
1469 Handle<String> name = ParseIdentifierOrStrictReservedWord( 1470 Handle<String> name = ParseIdentifierOrStrictReservedWord(
(...skipping 12 matching lines...) Expand all
1482 1483
1483 1484
1484 Block* Parser::ParseBlock(ZoneStringList* labels, bool* ok) { 1485 Block* Parser::ParseBlock(ZoneStringList* labels, bool* ok) {
1485 // Block :: 1486 // Block ::
1486 // '{' Statement* '}' 1487 // '{' Statement* '}'
1487 1488
1488 // Note that a Block does not introduce a new execution scope! 1489 // Note that a Block does not introduce a new execution scope!
1489 // (ECMA-262, 3rd, 12.2) 1490 // (ECMA-262, 3rd, 12.2)
1490 // 1491 //
1491 // Construct block expecting 16 statements. 1492 // Construct block expecting 16 statements.
1492 Block* result = new(zone()) Block(labels, 16, false); 1493 Block* result = new(zone()) Block(isolate(), labels, 16, false);
1493 Target target(&this->target_stack_, result); 1494 Target target(&this->target_stack_, result);
1494 Expect(Token::LBRACE, CHECK_OK); 1495 Expect(Token::LBRACE, CHECK_OK);
1495 InitializationBlockFinder block_finder(top_scope_, target_stack_); 1496 InitializationBlockFinder block_finder(top_scope_, target_stack_);
1496 while (peek() != Token::RBRACE) { 1497 while (peek() != Token::RBRACE) {
1497 Statement* stat = ParseStatement(NULL, CHECK_OK); 1498 Statement* stat = ParseStatement(NULL, CHECK_OK);
1498 if (stat && !stat->IsEmpty()) { 1499 if (stat && !stat->IsEmpty()) {
1499 result->AddStatement(stat); 1500 result->AddStatement(stat);
1500 block_finder.Update(stat); 1501 block_finder.Update(stat);
1501 } 1502 }
1502 } 1503 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1557 // Scope declaration, and rewrite the source-level initialization into an 1558 // Scope declaration, and rewrite the source-level initialization into an
1558 // assignment statement. We use a block to collect multiple assignments. 1559 // assignment statement. We use a block to collect multiple assignments.
1559 // 1560 //
1560 // We mark the block as initializer block because we don't want the 1561 // We mark the block as initializer block because we don't want the
1561 // rewriter to add a '.result' assignment to such a block (to get compliant 1562 // rewriter to add a '.result' assignment to such a block (to get compliant
1562 // behavior for code such as print(eval('var x = 7')), and for cosmetic 1563 // behavior for code such as print(eval('var x = 7')), and for cosmetic
1563 // reasons when pretty-printing. Also, unless an assignment (initialization) 1564 // reasons when pretty-printing. Also, unless an assignment (initialization)
1564 // is inside an initializer block, it is ignored. 1565 // is inside an initializer block, it is ignored.
1565 // 1566 //
1566 // Create new block with one expected declaration. 1567 // Create new block with one expected declaration.
1567 Block* block = new(zone()) Block(NULL, 1, true); 1568 Block* block = new(zone()) Block(isolate(), NULL, 1, true);
1568 int nvars = 0; // the number of variables declared 1569 int nvars = 0; // the number of variables declared
1569 Handle<String> name; 1570 Handle<String> name;
1570 do { 1571 do {
1571 if (fni_ != NULL) fni_->Enter(); 1572 if (fni_ != NULL) fni_->Enter();
1572 1573
1573 // Parse variable name. 1574 // Parse variable name.
1574 if (nvars > 0) Consume(Token::COMMA); 1575 if (nvars > 0) Consume(Token::COMMA);
1575 name = ParseIdentifier(CHECK_OK); 1576 name = ParseIdentifier(CHECK_OK);
1576 if (fni_ != NULL) fni_->PushVariableName(name); 1577 if (fni_ != NULL) fni_->PushVariableName(name);
1577 1578
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1669 // prototype. This way, global variable declarations can shadow 1670 // prototype. This way, global variable declarations can shadow
1670 // properties in the prototype chain, but only after the variable 1671 // properties in the prototype chain, but only after the variable
1671 // declaration statement has been executed. This is important in 1672 // declaration statement has been executed. This is important in
1672 // browsers where the global object (window) has lots of 1673 // browsers where the global object (window) has lots of
1673 // properties defined in prototype objects. 1674 // properties defined in prototype objects.
1674 1675
1675 if (initialization_scope->is_global_scope()) { 1676 if (initialization_scope->is_global_scope()) {
1676 // Compute the arguments for the runtime call. 1677 // Compute the arguments for the runtime call.
1677 ZoneList<Expression*>* arguments = new(zone()) ZoneList<Expression*>(3); 1678 ZoneList<Expression*>* arguments = new(zone()) ZoneList<Expression*>(3);
1678 // We have at least 1 parameter. 1679 // We have at least 1 parameter.
1679 arguments->Add(new(zone()) Literal(name)); 1680 arguments->Add(NewLiteral(name));
1680 CallRuntime* initialize; 1681 CallRuntime* initialize;
1681 1682
1682 if (is_const) { 1683 if (is_const) {
1683 arguments->Add(value); 1684 arguments->Add(value);
1684 value = NULL; // zap the value to avoid the unnecessary assignment 1685 value = NULL; // zap the value to avoid the unnecessary assignment
1685 1686
1686 // Construct the call to Runtime_InitializeConstGlobal 1687 // Construct the call to Runtime_InitializeConstGlobal
1687 // and add it to the initialization statement block. 1688 // and add it to the initialization statement block.
1688 // Note that the function does different things depending on 1689 // Note that the function does different things depending on
1689 // the number of arguments (1 or 2). 1690 // the number of arguments (1 or 2).
1690 initialize = 1691 initialize =
1691 new(zone()) CallRuntime( 1692 new(zone()) CallRuntime(
1692 isolate()->factory()->InitializeConstGlobal_symbol(), 1693 isolate(),
1693 Runtime::FunctionForId(Runtime::kInitializeConstGlobal), 1694 isolate()->factory()->InitializeConstGlobal_symbol(),
1694 arguments); 1695 Runtime::FunctionForId(Runtime::kInitializeConstGlobal),
1696 arguments);
1695 } else { 1697 } else {
1696 // Add strict mode. 1698 // Add strict mode.
1697 // We may want to pass singleton to avoid Literal allocations. 1699 // We may want to pass singleton to avoid Literal allocations.
1698 StrictModeFlag flag = initialization_scope->is_strict_mode() 1700 StrictModeFlag flag = initialization_scope->is_strict_mode()
1699 ? kStrictMode 1701 ? kStrictMode
1700 : kNonStrictMode; 1702 : kNonStrictMode;
1701 arguments->Add(NewNumberLiteral(flag)); 1703 arguments->Add(NewNumberLiteral(flag));
1702 1704
1703 // Be careful not to assign a value to the global variable if 1705 // Be careful not to assign a value to the global variable if
1704 // we're in a with. The initialization value should not 1706 // we're in a with. The initialization value should not
1705 // necessarily be stored in the global object in that case, 1707 // necessarily be stored in the global object in that case,
1706 // which is why we need to generate a separate assignment node. 1708 // which is why we need to generate a separate assignment node.
1707 if (value != NULL && !inside_with()) { 1709 if (value != NULL && !inside_with()) {
1708 arguments->Add(value); 1710 arguments->Add(value);
1709 value = NULL; // zap the value to avoid the unnecessary assignment 1711 value = NULL; // zap the value to avoid the unnecessary assignment
1710 } 1712 }
1711 1713
1712 // Construct the call to Runtime_InitializeVarGlobal 1714 // Construct the call to Runtime_InitializeVarGlobal
1713 // and add it to the initialization statement block. 1715 // and add it to the initialization statement block.
1714 // Note that the function does different things depending on 1716 // Note that the function does different things depending on
1715 // the number of arguments (2 or 3). 1717 // the number of arguments (2 or 3).
1716 initialize = 1718 initialize =
1717 new(zone()) CallRuntime( 1719 new(zone()) CallRuntime(
1718 isolate()->factory()->InitializeVarGlobal_symbol(), 1720 isolate(),
1719 Runtime::FunctionForId(Runtime::kInitializeVarGlobal), 1721 isolate()->factory()->InitializeVarGlobal_symbol(),
1720 arguments); 1722 Runtime::FunctionForId(Runtime::kInitializeVarGlobal),
1723 arguments);
1721 } 1724 }
1722 1725
1723 block->AddStatement(new(zone()) ExpressionStatement(initialize)); 1726 block->AddStatement(new(zone()) ExpressionStatement(initialize));
1724 } 1727 }
1725 1728
1726 // Add an assignment node to the initialization statement block if 1729 // Add an assignment node to the initialization statement block if
1727 // we still have a pending initialization value. We must distinguish 1730 // we still have a pending initialization value. We must distinguish
1728 // between variables and constants: Variable initializations are simply 1731 // between variables and constants: Variable initializations are simply
1729 // assignments (with all the consequences if they are inside a 'with' 1732 // assignments (with all the consequences if they are inside a 'with'
1730 // statement - they may change a 'with' object property). Constant 1733 // statement - they may change a 'with' object property). Constant
1731 // initializations always assign to the declared constant which is 1734 // initializations always assign to the declared constant which is
1732 // always at the function scope level. This is only relevant for 1735 // always at the function scope level. This is only relevant for
1733 // dynamically looked-up variables and constants (the start context 1736 // dynamically looked-up variables and constants (the start context
1734 // for constant lookups is always the function context, while it is 1737 // for constant lookups is always the function context, while it is
1735 // the top context for variables). Sigh... 1738 // the top context for variables). Sigh...
1736 if (value != NULL) { 1739 if (value != NULL) {
1737 Token::Value op = (is_const ? Token::INIT_CONST : Token::INIT_VAR); 1740 Token::Value op = (is_const ? Token::INIT_CONST : Token::INIT_VAR);
1738 bool in_with = is_const ? false : inside_with(); 1741 bool in_with = is_const ? false : inside_with();
1739 VariableProxy* proxy = 1742 VariableProxy* proxy =
1740 initialization_scope->NewUnresolved(name, in_with); 1743 initialization_scope->NewUnresolved(name, in_with);
1741 Assignment* assignment = 1744 Assignment* assignment =
1742 new(zone()) Assignment(op, proxy, value, position); 1745 new(zone()) Assignment(isolate(), op, proxy, value, position);
1743 if (block) { 1746 if (block) {
1744 block->AddStatement(new(zone()) ExpressionStatement(assignment)); 1747 block->AddStatement(new(zone()) ExpressionStatement(assignment));
1745 } 1748 }
1746 } 1749 }
1747 1750
1748 if (fni_ != NULL) fni_->Leave(); 1751 if (fni_ != NULL) fni_->Leave();
1749 } while (peek() == Token::COMMA); 1752 } while (peek() == Token::COMMA);
1750 1753
1751 // If there was a single non-const declaration, return it in the output 1754 // If there was a single non-const declaration, return it in the output
1752 // parameter for possible use by for/in. 1755 // parameter for possible use by for/in.
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1835 Expression* condition = ParseExpression(true, CHECK_OK); 1838 Expression* condition = ParseExpression(true, CHECK_OK);
1836 Expect(Token::RPAREN, CHECK_OK); 1839 Expect(Token::RPAREN, CHECK_OK);
1837 Statement* then_statement = ParseStatement(labels, CHECK_OK); 1840 Statement* then_statement = ParseStatement(labels, CHECK_OK);
1838 Statement* else_statement = NULL; 1841 Statement* else_statement = NULL;
1839 if (peek() == Token::ELSE) { 1842 if (peek() == Token::ELSE) {
1840 Next(); 1843 Next();
1841 else_statement = ParseStatement(labels, CHECK_OK); 1844 else_statement = ParseStatement(labels, CHECK_OK);
1842 } else { 1845 } else {
1843 else_statement = EmptyStatement(); 1846 else_statement = EmptyStatement();
1844 } 1847 }
1845 return new(zone()) IfStatement(condition, then_statement, else_statement); 1848 return new(zone()) IfStatement(
1849 isolate(), condition, then_statement, else_statement);
1846 } 1850 }
1847 1851
1848 1852
1849 Statement* Parser::ParseContinueStatement(bool* ok) { 1853 Statement* Parser::ParseContinueStatement(bool* ok) {
1850 // ContinueStatement :: 1854 // ContinueStatement ::
1851 // 'continue' Identifier? ';' 1855 // 'continue' Identifier? ';'
1852 1856
1853 Expect(Token::CONTINUE, CHECK_OK); 1857 Expect(Token::CONTINUE, CHECK_OK);
1854 Handle<String> label = Handle<String>::null(); 1858 Handle<String> label = Handle<String>::null();
1855 Token::Value tok = peek(); 1859 Token::Value tok = peek();
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
1954 Statement* stat; 1958 Statement* stat;
1955 { Target target(&this->target_stack_, &collector); 1959 { Target target(&this->target_stack_, &collector);
1956 with_nesting_level_++; 1960 with_nesting_level_++;
1957 top_scope_->DeclarationScope()->RecordWithStatement(); 1961 top_scope_->DeclarationScope()->RecordWithStatement();
1958 stat = ParseStatement(labels, CHECK_OK); 1962 stat = ParseStatement(labels, CHECK_OK);
1959 with_nesting_level_--; 1963 with_nesting_level_--;
1960 } 1964 }
1961 // Create resulting block with two statements. 1965 // Create resulting block with two statements.
1962 // 1: Evaluate the with expression. 1966 // 1: Evaluate the with expression.
1963 // 2: The try-finally block evaluating the body. 1967 // 2: The try-finally block evaluating the body.
1964 Block* result = new(zone()) Block(NULL, 2, false); 1968 Block* result = new(zone()) Block(isolate(), NULL, 2, false);
1965 1969
1966 if (result != NULL) { 1970 if (result != NULL) {
1967 result->AddStatement(new(zone()) EnterWithContextStatement(obj)); 1971 result->AddStatement(new(zone()) EnterWithContextStatement(obj));
1968 1972
1969 // Create body block. 1973 // Create body block.
1970 Block* body = new(zone()) Block(NULL, 1, false); 1974 Block* body = new(zone()) Block(isolate(), NULL, 1, false);
1971 body->AddStatement(stat); 1975 body->AddStatement(stat);
1972 1976
1973 // Create exit block. 1977 // Create exit block.
1974 Block* exit = new(zone()) Block(NULL, 1, false); 1978 Block* exit = new(zone()) Block(isolate(), NULL, 1, false);
1975 exit->AddStatement(new(zone()) ExitContextStatement()); 1979 exit->AddStatement(new(zone()) ExitContextStatement());
1976 1980
1977 // Return a try-finally statement. 1981 // Return a try-finally statement.
1978 TryFinallyStatement* wrapper = new(zone()) TryFinallyStatement(body, exit); 1982 TryFinallyStatement* wrapper = new(zone()) TryFinallyStatement(body, exit);
1979 wrapper->set_escaping_targets(collector.targets()); 1983 wrapper->set_escaping_targets(collector.targets());
1980 result->AddStatement(wrapper); 1984 result->AddStatement(wrapper);
1981 } 1985 }
1982 return result; 1986 return result;
1983 } 1987 }
1984 1988
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
2025 Expect(Token::COLON, CHECK_OK); 2029 Expect(Token::COLON, CHECK_OK);
2026 int pos = scanner().location().beg_pos; 2030 int pos = scanner().location().beg_pos;
2027 ZoneList<Statement*>* statements = new(zone()) ZoneList<Statement*>(5); 2031 ZoneList<Statement*>* statements = new(zone()) ZoneList<Statement*>(5);
2028 while (peek() != Token::CASE && 2032 while (peek() != Token::CASE &&
2029 peek() != Token::DEFAULT && 2033 peek() != Token::DEFAULT &&
2030 peek() != Token::RBRACE) { 2034 peek() != Token::RBRACE) {
2031 Statement* stat = ParseStatement(NULL, CHECK_OK); 2035 Statement* stat = ParseStatement(NULL, CHECK_OK);
2032 statements->Add(stat); 2036 statements->Add(stat);
2033 } 2037 }
2034 2038
2035 return new(zone()) CaseClause(label, statements, pos); 2039 return new(zone()) CaseClause(isolate(), label, statements, pos);
2036 } 2040 }
2037 2041
2038 2042
2039 SwitchStatement* Parser::ParseSwitchStatement(ZoneStringList* labels, 2043 SwitchStatement* Parser::ParseSwitchStatement(ZoneStringList* labels,
2040 bool* ok) { 2044 bool* ok) {
2041 // SwitchStatement :: 2045 // SwitchStatement ::
2042 // 'switch' '(' Expression ')' '{' CaseClause* '}' 2046 // 'switch' '(' Expression ')' '{' CaseClause* '}'
2043 2047
2044 SwitchStatement* statement = new(zone()) SwitchStatement(labels); 2048 SwitchStatement* statement = new(zone()) SwitchStatement(isolate(), labels);
2045 Target target(&this->target_stack_, statement); 2049 Target target(&this->target_stack_, statement);
2046 2050
2047 Expect(Token::SWITCH, CHECK_OK); 2051 Expect(Token::SWITCH, CHECK_OK);
2048 Expect(Token::LPAREN, CHECK_OK); 2052 Expect(Token::LPAREN, CHECK_OK);
2049 Expression* tag = ParseExpression(true, CHECK_OK); 2053 Expression* tag = ParseExpression(true, CHECK_OK);
2050 Expect(Token::RPAREN, CHECK_OK); 2054 Expect(Token::RPAREN, CHECK_OK);
2051 2055
2052 bool default_seen = false; 2056 bool default_seen = false;
2053 ZoneList<CaseClause*>* cases = new(zone()) ZoneList<CaseClause*>(4); 2057 ZoneList<CaseClause*>* cases = new(zone()) ZoneList<CaseClause*>(4);
2054 Expect(Token::LBRACE, CHECK_OK); 2058 Expect(Token::LBRACE, CHECK_OK);
(...skipping 15 matching lines...) Expand all
2070 Expect(Token::THROW, CHECK_OK); 2074 Expect(Token::THROW, CHECK_OK);
2071 int pos = scanner().location().beg_pos; 2075 int pos = scanner().location().beg_pos;
2072 if (scanner().HasAnyLineTerminatorBeforeNext()) { 2076 if (scanner().HasAnyLineTerminatorBeforeNext()) {
2073 ReportMessage("newline_after_throw", Vector<const char*>::empty()); 2077 ReportMessage("newline_after_throw", Vector<const char*>::empty());
2074 *ok = false; 2078 *ok = false;
2075 return NULL; 2079 return NULL;
2076 } 2080 }
2077 Expression* exception = ParseExpression(true, CHECK_OK); 2081 Expression* exception = ParseExpression(true, CHECK_OK);
2078 ExpectSemicolon(CHECK_OK); 2082 ExpectSemicolon(CHECK_OK);
2079 2083
2080 return new(zone()) ExpressionStatement(new(zone()) Throw(exception, pos)); 2084 return new(zone()) ExpressionStatement(
2085 new(zone()) Throw(isolate(), exception, pos));
2081 } 2086 }
2082 2087
2083 2088
2084 TryStatement* Parser::ParseTryStatement(bool* ok) { 2089 TryStatement* Parser::ParseTryStatement(bool* ok) {
2085 // TryStatement :: 2090 // TryStatement ::
2086 // 'try' Block Catch 2091 // 'try' Block Catch
2087 // 'try' Block Finally 2092 // 'try' Block Finally
2088 // 'try' Block Catch Finally 2093 // 'try' Block Catch Finally
2089 // 2094 //
2090 // Catch :: 2095 // Catch ::
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
2149 catch_variable = catch_scope->DeclareLocal(name, Variable::VAR); 2154 catch_variable = catch_scope->DeclareLocal(name, Variable::VAR);
2150 2155
2151 Scope* saved_scope = top_scope_; 2156 Scope* saved_scope = top_scope_;
2152 top_scope_ = catch_scope; 2157 top_scope_ = catch_scope;
2153 inner_body = ParseBlock(NULL, CHECK_OK); 2158 inner_body = ParseBlock(NULL, CHECK_OK);
2154 top_scope_ = saved_scope; 2159 top_scope_ = saved_scope;
2155 } 2160 }
2156 } 2161 }
2157 2162
2158 // Create exit block. 2163 // Create exit block.
2159 Block* inner_finally = new(zone()) Block(NULL, 1, false); 2164 Block* inner_finally = new(zone()) Block(isolate(), NULL, 1, false);
2160 inner_finally->AddStatement(new(zone()) ExitContextStatement()); 2165 inner_finally->AddStatement(new(zone()) ExitContextStatement());
2161 2166
2162 // Create a try/finally statement. 2167 // Create a try/finally statement.
2163 TryFinallyStatement* inner_try_finally = 2168 TryFinallyStatement* inner_try_finally =
2164 new(zone()) TryFinallyStatement(inner_body, inner_finally); 2169 new(zone()) TryFinallyStatement(inner_body, inner_finally);
2165 inner_try_finally->set_escaping_targets(inner_collector.targets()); 2170 inner_try_finally->set_escaping_targets(inner_collector.targets());
2166 2171
2167 catch_block = new(zone()) Block(NULL, 1, false); 2172 catch_block = new(zone()) Block(isolate(), NULL, 1, false);
2168 catch_block->AddStatement(inner_try_finally); 2173 catch_block->AddStatement(inner_try_finally);
2169 } else { 2174 } else {
2170 Expect(Token::LBRACE, CHECK_OK); 2175 Expect(Token::LBRACE, CHECK_OK);
2171 } 2176 }
2172 2177
2173 tok = peek(); 2178 tok = peek();
2174 } 2179 }
2175 2180
2176 Block* finally_block = NULL; 2181 Block* finally_block = NULL;
2177 if (tok == Token::FINALLY || catch_block == NULL) { 2182 if (tok == Token::FINALLY || catch_block == NULL) {
2178 Consume(Token::FINALLY); 2183 Consume(Token::FINALLY);
2179 finally_block = ParseBlock(NULL, CHECK_OK); 2184 finally_block = ParseBlock(NULL, CHECK_OK);
2180 } 2185 }
2181 2186
2182 // Simplify the AST nodes by converting: 2187 // Simplify the AST nodes by converting:
2183 // 'try B0 catch B1 finally B2' 2188 // 'try B0 catch B1 finally B2'
2184 // to: 2189 // to:
2185 // 'try { try B0 catch B1 } finally B2' 2190 // 'try { try B0 catch B1 } finally B2'
2186 2191
2187 if (catch_block != NULL && finally_block != NULL) { 2192 if (catch_block != NULL && finally_block != NULL) {
2188 // If we have both, create an inner try/catch. 2193 // If we have both, create an inner try/catch.
2189 ASSERT(catch_scope != NULL && catch_variable != NULL); 2194 ASSERT(catch_scope != NULL && catch_variable != NULL);
2190 TryCatchStatement* statement = 2195 TryCatchStatement* statement =
2191 new(zone()) TryCatchStatement(try_block, 2196 new(zone()) TryCatchStatement(try_block,
2192 catch_scope, 2197 catch_scope,
2193 catch_variable, 2198 catch_variable,
2194 catch_block); 2199 catch_block);
2195 statement->set_escaping_targets(try_collector.targets()); 2200 statement->set_escaping_targets(try_collector.targets());
2196 try_block = new(zone()) Block(NULL, 1, false); 2201 try_block = new(zone()) Block(isolate(), NULL, 1, false);
2197 try_block->AddStatement(statement); 2202 try_block->AddStatement(statement);
2198 catch_block = NULL; // Clear to indicate it's been handled. 2203 catch_block = NULL; // Clear to indicate it's been handled.
2199 } 2204 }
2200 2205
2201 TryStatement* result = NULL; 2206 TryStatement* result = NULL;
2202 if (catch_block != NULL) { 2207 if (catch_block != NULL) {
2203 ASSERT(finally_block == NULL); 2208 ASSERT(finally_block == NULL);
2204 ASSERT(catch_scope != NULL && catch_variable != NULL); 2209 ASSERT(catch_scope != NULL && catch_variable != NULL);
2205 result = 2210 result =
2206 new(zone()) TryCatchStatement(try_block, 2211 new(zone()) TryCatchStatement(try_block,
(...skipping 10 matching lines...) Expand all
2217 result->set_escaping_targets(try_collector.targets()); 2222 result->set_escaping_targets(try_collector.targets());
2218 return result; 2223 return result;
2219 } 2224 }
2220 2225
2221 2226
2222 DoWhileStatement* Parser::ParseDoWhileStatement(ZoneStringList* labels, 2227 DoWhileStatement* Parser::ParseDoWhileStatement(ZoneStringList* labels,
2223 bool* ok) { 2228 bool* ok) {
2224 // DoStatement :: 2229 // DoStatement ::
2225 // 'do' Statement 'while' '(' Expression ')' ';' 2230 // 'do' Statement 'while' '(' Expression ')' ';'
2226 2231
2227 DoWhileStatement* loop = new(zone()) DoWhileStatement(labels); 2232 DoWhileStatement* loop = new(zone()) DoWhileStatement(isolate(), labels);
2228 Target target(&this->target_stack_, loop); 2233 Target target(&this->target_stack_, loop);
2229 2234
2230 Expect(Token::DO, CHECK_OK); 2235 Expect(Token::DO, CHECK_OK);
2231 Statement* body = ParseStatement(NULL, CHECK_OK); 2236 Statement* body = ParseStatement(NULL, CHECK_OK);
2232 Expect(Token::WHILE, CHECK_OK); 2237 Expect(Token::WHILE, CHECK_OK);
2233 Expect(Token::LPAREN, CHECK_OK); 2238 Expect(Token::LPAREN, CHECK_OK);
2234 2239
2235 if (loop != NULL) { 2240 if (loop != NULL) {
2236 int position = scanner().location().beg_pos; 2241 int position = scanner().location().beg_pos;
2237 loop->set_condition_position(position); 2242 loop->set_condition_position(position);
(...skipping 10 matching lines...) Expand all
2248 2253
2249 if (loop != NULL) loop->Initialize(cond, body); 2254 if (loop != NULL) loop->Initialize(cond, body);
2250 return loop; 2255 return loop;
2251 } 2256 }
2252 2257
2253 2258
2254 WhileStatement* Parser::ParseWhileStatement(ZoneStringList* labels, bool* ok) { 2259 WhileStatement* Parser::ParseWhileStatement(ZoneStringList* labels, bool* ok) {
2255 // WhileStatement :: 2260 // WhileStatement ::
2256 // 'while' '(' Expression ')' Statement 2261 // 'while' '(' Expression ')' Statement
2257 2262
2258 WhileStatement* loop = new(zone()) WhileStatement(labels); 2263 WhileStatement* loop = new(zone()) WhileStatement(isolate(), labels);
2259 Target target(&this->target_stack_, loop); 2264 Target target(&this->target_stack_, loop);
2260 2265
2261 Expect(Token::WHILE, CHECK_OK); 2266 Expect(Token::WHILE, CHECK_OK);
2262 Expect(Token::LPAREN, CHECK_OK); 2267 Expect(Token::LPAREN, CHECK_OK);
2263 Expression* cond = ParseExpression(true, CHECK_OK); 2268 Expression* cond = ParseExpression(true, CHECK_OK);
2264 Expect(Token::RPAREN, CHECK_OK); 2269 Expect(Token::RPAREN, CHECK_OK);
2265 Statement* body = ParseStatement(NULL, CHECK_OK); 2270 Statement* body = ParseStatement(NULL, CHECK_OK);
2266 2271
2267 if (loop != NULL) loop->Initialize(cond, body); 2272 if (loop != NULL) loop->Initialize(cond, body);
2268 return loop; 2273 return loop;
2269 } 2274 }
2270 2275
2271 2276
2272 Statement* Parser::ParseForStatement(ZoneStringList* labels, bool* ok) { 2277 Statement* Parser::ParseForStatement(ZoneStringList* labels, bool* ok) {
2273 // ForStatement :: 2278 // ForStatement ::
2274 // 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement 2279 // 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement
2275 2280
2276 Statement* init = NULL; 2281 Statement* init = NULL;
2277 2282
2278 Expect(Token::FOR, CHECK_OK); 2283 Expect(Token::FOR, CHECK_OK);
2279 Expect(Token::LPAREN, CHECK_OK); 2284 Expect(Token::LPAREN, CHECK_OK);
2280 if (peek() != Token::SEMICOLON) { 2285 if (peek() != Token::SEMICOLON) {
2281 if (peek() == Token::VAR || peek() == Token::CONST) { 2286 if (peek() == Token::VAR || peek() == Token::CONST) {
2282 Handle<String> name; 2287 Handle<String> name;
2283 Block* variable_statement = 2288 Block* variable_statement =
2284 ParseVariableDeclarations(false, &name, CHECK_OK); 2289 ParseVariableDeclarations(false, &name, CHECK_OK);
2285 2290
2286 if (peek() == Token::IN && !name.is_null()) { 2291 if (peek() == Token::IN && !name.is_null()) {
2287 VariableProxy* each = top_scope_->NewUnresolved(name, inside_with()); 2292 VariableProxy* each = top_scope_->NewUnresolved(name, inside_with());
2288 ForInStatement* loop = new(zone()) ForInStatement(labels); 2293 ForInStatement* loop = new(zone()) ForInStatement(isolate(), labels);
2289 Target target(&this->target_stack_, loop); 2294 Target target(&this->target_stack_, loop);
2290 2295
2291 Expect(Token::IN, CHECK_OK); 2296 Expect(Token::IN, CHECK_OK);
2292 Expression* enumerable = ParseExpression(true, CHECK_OK); 2297 Expression* enumerable = ParseExpression(true, CHECK_OK);
2293 Expect(Token::RPAREN, CHECK_OK); 2298 Expect(Token::RPAREN, CHECK_OK);
2294 2299
2295 Statement* body = ParseStatement(NULL, CHECK_OK); 2300 Statement* body = ParseStatement(NULL, CHECK_OK);
2296 loop->Initialize(each, enumerable, body); 2301 loop->Initialize(each, enumerable, body);
2297 Block* result = new(zone()) Block(NULL, 2, false); 2302 Block* result = new(zone()) Block(isolate(), NULL, 2, false);
2298 result->AddStatement(variable_statement); 2303 result->AddStatement(variable_statement);
2299 result->AddStatement(loop); 2304 result->AddStatement(loop);
2300 // Parsed for-in loop w/ variable/const declaration. 2305 // Parsed for-in loop w/ variable/const declaration.
2301 return result; 2306 return result;
2302 } else { 2307 } else {
2303 init = variable_statement; 2308 init = variable_statement;
2304 } 2309 }
2305 2310
2306 } else { 2311 } else {
2307 Expression* expression = ParseExpression(false, CHECK_OK); 2312 Expression* expression = ParseExpression(false, CHECK_OK);
2308 if (peek() == Token::IN) { 2313 if (peek() == Token::IN) {
2309 // Signal a reference error if the expression is an invalid 2314 // Signal a reference error if the expression is an invalid
2310 // left-hand side expression. We could report this as a syntax 2315 // left-hand side expression. We could report this as a syntax
2311 // error here but for compatibility with JSC we choose to report 2316 // error here but for compatibility with JSC we choose to report
2312 // the error at runtime. 2317 // the error at runtime.
2313 if (expression == NULL || !expression->IsValidLeftHandSide()) { 2318 if (expression == NULL || !expression->IsValidLeftHandSide()) {
2314 Handle<String> type = 2319 Handle<String> type =
2315 isolate()->factory()->invalid_lhs_in_for_in_symbol(); 2320 isolate()->factory()->invalid_lhs_in_for_in_symbol();
2316 expression = NewThrowReferenceError(type); 2321 expression = NewThrowReferenceError(type);
2317 } 2322 }
2318 ForInStatement* loop = new(zone()) ForInStatement(labels); 2323 ForInStatement* loop = new(zone()) ForInStatement(isolate(), labels);
2319 Target target(&this->target_stack_, loop); 2324 Target target(&this->target_stack_, loop);
2320 2325
2321 Expect(Token::IN, CHECK_OK); 2326 Expect(Token::IN, CHECK_OK);
2322 Expression* enumerable = ParseExpression(true, CHECK_OK); 2327 Expression* enumerable = ParseExpression(true, CHECK_OK);
2323 Expect(Token::RPAREN, CHECK_OK); 2328 Expect(Token::RPAREN, CHECK_OK);
2324 2329
2325 Statement* body = ParseStatement(NULL, CHECK_OK); 2330 Statement* body = ParseStatement(NULL, CHECK_OK);
2326 if (loop) loop->Initialize(expression, enumerable, body); 2331 if (loop) loop->Initialize(expression, enumerable, body);
2327 // Parsed for-in loop. 2332 // Parsed for-in loop.
2328 return loop; 2333 return loop;
2329 2334
2330 } else { 2335 } else {
2331 init = new(zone()) ExpressionStatement(expression); 2336 init = new(zone()) ExpressionStatement(expression);
2332 } 2337 }
2333 } 2338 }
2334 } 2339 }
2335 2340
2336 // Standard 'for' loop 2341 // Standard 'for' loop
2337 ForStatement* loop = new(zone()) ForStatement(labels); 2342 ForStatement* loop = new(zone()) ForStatement(isolate(), labels);
2338 Target target(&this->target_stack_, loop); 2343 Target target(&this->target_stack_, loop);
2339 2344
2340 // Parsed initializer at this point. 2345 // Parsed initializer at this point.
2341 Expect(Token::SEMICOLON, CHECK_OK); 2346 Expect(Token::SEMICOLON, CHECK_OK);
2342 2347
2343 Expression* cond = NULL; 2348 Expression* cond = NULL;
2344 if (peek() != Token::SEMICOLON) { 2349 if (peek() != Token::SEMICOLON) {
2345 cond = ParseExpression(true, CHECK_OK); 2350 cond = ParseExpression(true, CHECK_OK);
2346 } 2351 }
2347 Expect(Token::SEMICOLON, CHECK_OK); 2352 Expect(Token::SEMICOLON, CHECK_OK);
(...skipping 15 matching lines...) Expand all
2363 Expression* Parser::ParseExpression(bool accept_IN, bool* ok) { 2368 Expression* Parser::ParseExpression(bool accept_IN, bool* ok) {
2364 // Expression :: 2369 // Expression ::
2365 // AssignmentExpression 2370 // AssignmentExpression
2366 // Expression ',' AssignmentExpression 2371 // Expression ',' AssignmentExpression
2367 2372
2368 Expression* result = ParseAssignmentExpression(accept_IN, CHECK_OK); 2373 Expression* result = ParseAssignmentExpression(accept_IN, CHECK_OK);
2369 while (peek() == Token::COMMA) { 2374 while (peek() == Token::COMMA) {
2370 Expect(Token::COMMA, CHECK_OK); 2375 Expect(Token::COMMA, CHECK_OK);
2371 int position = scanner().location().beg_pos; 2376 int position = scanner().location().beg_pos;
2372 Expression* right = ParseAssignmentExpression(accept_IN, CHECK_OK); 2377 Expression* right = ParseAssignmentExpression(accept_IN, CHECK_OK);
2373 result = new(zone()) BinaryOperation(Token::COMMA, result, right, position); 2378 result = new(zone()) BinaryOperation(
2379 isolate(), Token::COMMA, result, right, position);
2374 } 2380 }
2375 return result; 2381 return result;
2376 } 2382 }
2377 2383
2378 2384
2379 // Precedence = 2 2385 // Precedence = 2
2380 Expression* Parser::ParseAssignmentExpression(bool accept_IN, bool* ok) { 2386 Expression* Parser::ParseAssignmentExpression(bool accept_IN, bool* ok) {
2381 // AssignmentExpression :: 2387 // AssignmentExpression ::
2382 // ConditionalExpression 2388 // ConditionalExpression
2383 // LeftHandSideExpression AssignmentOperator AssignmentExpression 2389 // LeftHandSideExpression AssignmentOperator AssignmentExpression
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
2435 // expression. 2441 // expression.
2436 if ((op == Token::INIT_VAR 2442 if ((op == Token::INIT_VAR
2437 || op == Token::INIT_CONST 2443 || op == Token::INIT_CONST
2438 || op == Token::ASSIGN) 2444 || op == Token::ASSIGN)
2439 && (right->AsCall() == NULL && right->AsCallNew() == NULL)) { 2445 && (right->AsCall() == NULL && right->AsCallNew() == NULL)) {
2440 fni_->Infer(); 2446 fni_->Infer();
2441 } 2447 }
2442 fni_->Leave(); 2448 fni_->Leave();
2443 } 2449 }
2444 2450
2445 return new(zone()) Assignment(op, expression, right, pos); 2451 return new(zone()) Assignment(isolate(), op, expression, right, pos);
2446 } 2452 }
2447 2453
2448 2454
2449 // Precedence = 3 2455 // Precedence = 3
2450 Expression* Parser::ParseConditionalExpression(bool accept_IN, bool* ok) { 2456 Expression* Parser::ParseConditionalExpression(bool accept_IN, bool* ok) {
2451 // ConditionalExpression :: 2457 // ConditionalExpression ::
2452 // LogicalOrExpression 2458 // LogicalOrExpression
2453 // LogicalOrExpression '?' AssignmentExpression ':' AssignmentExpression 2459 // LogicalOrExpression '?' AssignmentExpression ':' AssignmentExpression
2454 2460
2455 // We start using the binary expression parser for prec >= 4 only! 2461 // We start using the binary expression parser for prec >= 4 only!
2456 Expression* expression = ParseBinaryExpression(4, accept_IN, CHECK_OK); 2462 Expression* expression = ParseBinaryExpression(4, accept_IN, CHECK_OK);
2457 if (peek() != Token::CONDITIONAL) return expression; 2463 if (peek() != Token::CONDITIONAL) return expression;
2458 Consume(Token::CONDITIONAL); 2464 Consume(Token::CONDITIONAL);
2459 // In parsing the first assignment expression in conditional 2465 // In parsing the first assignment expression in conditional
2460 // expressions we always accept the 'in' keyword; see ECMA-262, 2466 // expressions we always accept the 'in' keyword; see ECMA-262,
2461 // section 11.12, page 58. 2467 // section 11.12, page 58.
2462 int left_position = scanner().peek_location().beg_pos; 2468 int left_position = scanner().peek_location().beg_pos;
2463 Expression* left = ParseAssignmentExpression(true, CHECK_OK); 2469 Expression* left = ParseAssignmentExpression(true, CHECK_OK);
2464 Expect(Token::COLON, CHECK_OK); 2470 Expect(Token::COLON, CHECK_OK);
2465 int right_position = scanner().peek_location().beg_pos; 2471 int right_position = scanner().peek_location().beg_pos;
2466 Expression* right = ParseAssignmentExpression(accept_IN, CHECK_OK); 2472 Expression* right = ParseAssignmentExpression(accept_IN, CHECK_OK);
2467 return new(zone()) Conditional(expression, left, right, 2473 return new(zone()) Conditional(
2468 left_position, right_position); 2474 isolate(), expression, left, right, left_position, right_position);
2469 } 2475 }
2470 2476
2471 2477
2472 static int Precedence(Token::Value tok, bool accept_IN) { 2478 static int Precedence(Token::Value tok, bool accept_IN) {
2473 if (tok == Token::IN && !accept_IN) 2479 if (tok == Token::IN && !accept_IN)
2474 return 0; // 0 precedence will terminate binary expression parsing 2480 return 0; // 0 precedence will terminate binary expression parsing
2475 2481
2476 return Token::Precedence(tok); 2482 return Token::Precedence(tok);
2477 } 2483 }
2478 2484
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
2545 // We have a comparison. 2551 // We have a comparison.
2546 Token::Value cmp = op; 2552 Token::Value cmp = op;
2547 switch (op) { 2553 switch (op) {
2548 case Token::NE: cmp = Token::EQ; break; 2554 case Token::NE: cmp = Token::EQ; break;
2549 case Token::NE_STRICT: cmp = Token::EQ_STRICT; break; 2555 case Token::NE_STRICT: cmp = Token::EQ_STRICT; break;
2550 default: break; 2556 default: break;
2551 } 2557 }
2552 x = NewCompareNode(cmp, x, y, position); 2558 x = NewCompareNode(cmp, x, y, position);
2553 if (cmp != op) { 2559 if (cmp != op) {
2554 // The comparison was negated - add a NOT. 2560 // The comparison was negated - add a NOT.
2555 x = new(zone()) UnaryOperation(Token::NOT, x, position); 2561 x = new(zone()) UnaryOperation(isolate(), Token::NOT, x, position);
2556 } 2562 }
2557 2563
2558 } else { 2564 } else {
2559 // We have a "normal" binary operation. 2565 // We have a "normal" binary operation.
2560 x = new(zone()) BinaryOperation(op, x, y, position); 2566 x = new(zone()) BinaryOperation(isolate(), op, x, y, position);
2561 } 2567 }
2562 } 2568 }
2563 } 2569 }
2564 return x; 2570 return x;
2565 } 2571 }
2566 2572
2567 2573
2568 Expression* Parser::NewCompareNode(Token::Value op, 2574 Expression* Parser::NewCompareNode(Token::Value op,
2569 Expression* x, 2575 Expression* x,
2570 Expression* y, 2576 Expression* y,
2571 int position) { 2577 int position) {
2572 ASSERT(op != Token::NE && op != Token::NE_STRICT); 2578 ASSERT(op != Token::NE && op != Token::NE_STRICT);
2573 if (op == Token::EQ || op == Token::EQ_STRICT) { 2579 if (op == Token::EQ || op == Token::EQ_STRICT) {
2574 bool is_strict = (op == Token::EQ_STRICT); 2580 bool is_strict = (op == Token::EQ_STRICT);
2575 Literal* x_literal = x->AsLiteral(); 2581 Literal* x_literal = x->AsLiteral();
2576 if (x_literal != NULL && x_literal->IsNull()) { 2582 if (x_literal != NULL && x_literal->IsNull()) {
2577 return new(zone()) CompareToNull(is_strict, y); 2583 return new(zone()) CompareToNull(isolate(), is_strict, y);
2578 } 2584 }
2579 2585
2580 Literal* y_literal = y->AsLiteral(); 2586 Literal* y_literal = y->AsLiteral();
2581 if (y_literal != NULL && y_literal->IsNull()) { 2587 if (y_literal != NULL && y_literal->IsNull()) {
2582 return new(zone()) CompareToNull(is_strict, x); 2588 return new(zone()) CompareToNull(isolate(), is_strict, x);
2583 } 2589 }
2584 } 2590 }
2585 return new(zone()) CompareOperation(op, x, y, position); 2591 return new(zone()) CompareOperation(isolate(), op, x, y, position);
2586 } 2592 }
2587 2593
2588 2594
2589 Expression* Parser::ParseUnaryExpression(bool* ok) { 2595 Expression* Parser::ParseUnaryExpression(bool* ok) {
2590 // UnaryExpression :: 2596 // UnaryExpression ::
2591 // PostfixExpression 2597 // PostfixExpression
2592 // 'delete' UnaryExpression 2598 // 'delete' UnaryExpression
2593 // 'void' UnaryExpression 2599 // 'void' UnaryExpression
2594 // 'typeof' UnaryExpression 2600 // 'typeof' UnaryExpression
2595 // '++' UnaryExpression 2601 // '++' UnaryExpression
2596 // '--' UnaryExpression 2602 // '--' UnaryExpression
2597 // '+' UnaryExpression 2603 // '+' UnaryExpression
2598 // '-' UnaryExpression 2604 // '-' UnaryExpression
2599 // '~' UnaryExpression 2605 // '~' UnaryExpression
2600 // '!' UnaryExpression 2606 // '!' UnaryExpression
2601 2607
2602 Token::Value op = peek(); 2608 Token::Value op = peek();
2603 if (Token::IsUnaryOp(op)) { 2609 if (Token::IsUnaryOp(op)) {
2604 op = Next(); 2610 op = Next();
2605 int position = scanner().location().beg_pos; 2611 int position = scanner().location().beg_pos;
2606 Expression* expression = ParseUnaryExpression(CHECK_OK); 2612 Expression* expression = ParseUnaryExpression(CHECK_OK);
2607 2613
2608 if (expression != NULL && (expression->AsLiteral() != NULL)) { 2614 if (expression != NULL && (expression->AsLiteral() != NULL)) {
2609 Handle<Object> literal = expression->AsLiteral()->handle(); 2615 Handle<Object> literal = expression->AsLiteral()->handle();
2610 if (op == Token::NOT) { 2616 if (op == Token::NOT) {
2611 // Convert the literal to a boolean condition and negate it. 2617 // Convert the literal to a boolean condition and negate it.
2612 bool condition = literal->ToBoolean()->IsTrue(); 2618 bool condition = literal->ToBoolean()->IsTrue();
2613 Handle<Object> result(isolate()->heap()->ToBoolean(!condition)); 2619 Handle<Object> result(isolate()->heap()->ToBoolean(!condition));
2614 return new(zone()) Literal(result); 2620 return NewLiteral(result);
2615 } else if (literal->IsNumber()) { 2621 } else if (literal->IsNumber()) {
2616 // Compute some expressions involving only number literals. 2622 // Compute some expressions involving only number literals.
2617 double value = literal->Number(); 2623 double value = literal->Number();
2618 switch (op) { 2624 switch (op) {
2619 case Token::ADD: 2625 case Token::ADD:
2620 return expression; 2626 return expression;
2621 case Token::SUB: 2627 case Token::SUB:
2622 return NewNumberLiteral(-value); 2628 return NewNumberLiteral(-value);
2623 case Token::BIT_NOT: 2629 case Token::BIT_NOT:
2624 return NewNumberLiteral(~DoubleToInt32(value)); 2630 return NewNumberLiteral(~DoubleToInt32(value));
2625 default: 2631 default:
2626 break; 2632 break;
2627 } 2633 }
2628 } 2634 }
2629 } 2635 }
2630 2636
2631 // "delete identifier" is a syntax error in strict mode. 2637 // "delete identifier" is a syntax error in strict mode.
2632 if (op == Token::DELETE && top_scope_->is_strict_mode()) { 2638 if (op == Token::DELETE && top_scope_->is_strict_mode()) {
2633 VariableProxy* operand = expression->AsVariableProxy(); 2639 VariableProxy* operand = expression->AsVariableProxy();
2634 if (operand != NULL && !operand->is_this()) { 2640 if (operand != NULL && !operand->is_this()) {
2635 ReportMessage("strict_delete", Vector<const char*>::empty()); 2641 ReportMessage("strict_delete", Vector<const char*>::empty());
2636 *ok = false; 2642 *ok = false;
2637 return NULL; 2643 return NULL;
2638 } 2644 }
2639 } 2645 }
2640 2646
2641 return new(zone()) UnaryOperation(op, expression, position); 2647 return new(zone()) UnaryOperation(isolate(), op, expression, position);
2642 2648
2643 } else if (Token::IsCountOp(op)) { 2649 } else if (Token::IsCountOp(op)) {
2644 op = Next(); 2650 op = Next();
2645 Expression* expression = ParseUnaryExpression(CHECK_OK); 2651 Expression* expression = ParseUnaryExpression(CHECK_OK);
2646 // Signal a reference error if the expression is an invalid 2652 // Signal a reference error if the expression is an invalid
2647 // left-hand side expression. We could report this as a syntax 2653 // left-hand side expression. We could report this as a syntax
2648 // error here but for compatibility with JSC we choose to report the 2654 // error here but for compatibility with JSC we choose to report the
2649 // error at runtime. 2655 // error at runtime.
2650 if (expression == NULL || !expression->IsValidLeftHandSide()) { 2656 if (expression == NULL || !expression->IsValidLeftHandSide()) {
2651 Handle<String> type = 2657 Handle<String> type =
2652 isolate()->factory()->invalid_lhs_in_prefix_op_symbol(); 2658 isolate()->factory()->invalid_lhs_in_prefix_op_symbol();
2653 expression = NewThrowReferenceError(type); 2659 expression = NewThrowReferenceError(type);
2654 } 2660 }
2655 2661
2656 if (top_scope_->is_strict_mode()) { 2662 if (top_scope_->is_strict_mode()) {
2657 // Prefix expression operand in strict mode may not be eval or arguments. 2663 // Prefix expression operand in strict mode may not be eval or arguments.
2658 CheckStrictModeLValue(expression, "strict_lhs_prefix", CHECK_OK); 2664 CheckStrictModeLValue(expression, "strict_lhs_prefix", CHECK_OK);
2659 } 2665 }
2660 2666
2661 int position = scanner().location().beg_pos; 2667 int position = scanner().location().beg_pos;
2662 return new(zone()) CountOperation(op, 2668 return new(zone()) CountOperation(isolate(),
2669 op,
2663 true /* prefix */, 2670 true /* prefix */,
2664 expression, 2671 expression,
2665 position); 2672 position);
2666 2673
2667 } else { 2674 } else {
2668 return ParsePostfixExpression(ok); 2675 return ParsePostfixExpression(ok);
2669 } 2676 }
2670 } 2677 }
2671 2678
2672 2679
(...skipping 15 matching lines...) Expand all
2688 } 2695 }
2689 2696
2690 if (top_scope_->is_strict_mode()) { 2697 if (top_scope_->is_strict_mode()) {
2691 // Postfix expression operand in strict mode may not be eval or arguments. 2698 // Postfix expression operand in strict mode may not be eval or arguments.
2692 CheckStrictModeLValue(expression, "strict_lhs_prefix", CHECK_OK); 2699 CheckStrictModeLValue(expression, "strict_lhs_prefix", CHECK_OK);
2693 } 2700 }
2694 2701
2695 Token::Value next = Next(); 2702 Token::Value next = Next();
2696 int position = scanner().location().beg_pos; 2703 int position = scanner().location().beg_pos;
2697 expression = 2704 expression =
2698 new(zone()) CountOperation(next, 2705 new(zone()) CountOperation(isolate(),
2706 next,
2699 false /* postfix */, 2707 false /* postfix */,
2700 expression, 2708 expression,
2701 position); 2709 position);
2702 } 2710 }
2703 return expression; 2711 return expression;
2704 } 2712 }
2705 2713
2706 2714
2707 Expression* Parser::ParseLeftHandSideExpression(bool* ok) { 2715 Expression* Parser::ParseLeftHandSideExpression(bool* ok) {
2708 // LeftHandSideExpression :: 2716 // LeftHandSideExpression ::
2709 // (NewExpression | MemberExpression) ... 2717 // (NewExpression | MemberExpression) ...
2710 2718
2711 Expression* result; 2719 Expression* result;
2712 if (peek() == Token::NEW) { 2720 if (peek() == Token::NEW) {
2713 result = ParseNewExpression(CHECK_OK); 2721 result = ParseNewExpression(CHECK_OK);
2714 } else { 2722 } else {
2715 result = ParseMemberExpression(CHECK_OK); 2723 result = ParseMemberExpression(CHECK_OK);
2716 } 2724 }
2717 2725
2718 while (true) { 2726 while (true) {
2719 switch (peek()) { 2727 switch (peek()) {
2720 case Token::LBRACK: { 2728 case Token::LBRACK: {
2721 Consume(Token::LBRACK); 2729 Consume(Token::LBRACK);
2722 int pos = scanner().location().beg_pos; 2730 int pos = scanner().location().beg_pos;
2723 Expression* index = ParseExpression(true, CHECK_OK); 2731 Expression* index = ParseExpression(true, CHECK_OK);
2724 result = new(zone()) Property(result, index, pos); 2732 result = new(zone()) Property(isolate(), result, index, pos);
2725 Expect(Token::RBRACK, CHECK_OK); 2733 Expect(Token::RBRACK, CHECK_OK);
2726 break; 2734 break;
2727 } 2735 }
2728 2736
2729 case Token::LPAREN: { 2737 case Token::LPAREN: {
2730 int pos = scanner().location().beg_pos; 2738 int pos = scanner().location().beg_pos;
2731 ZoneList<Expression*>* args = ParseArguments(CHECK_OK); 2739 ZoneList<Expression*>* args = ParseArguments(CHECK_OK);
2732 2740
2733 // Keep track of eval() calls since they disable all local variable 2741 // Keep track of eval() calls since they disable all local variable
2734 // optimizations. 2742 // optimizations.
(...skipping 17 matching lines...) Expand all
2752 } 2760 }
2753 } 2761 }
2754 result = NewCall(result, args, pos); 2762 result = NewCall(result, args, pos);
2755 break; 2763 break;
2756 } 2764 }
2757 2765
2758 case Token::PERIOD: { 2766 case Token::PERIOD: {
2759 Consume(Token::PERIOD); 2767 Consume(Token::PERIOD);
2760 int pos = scanner().location().beg_pos; 2768 int pos = scanner().location().beg_pos;
2761 Handle<String> name = ParseIdentifierName(CHECK_OK); 2769 Handle<String> name = ParseIdentifierName(CHECK_OK);
2762 result = new(zone()) Property(result, new(zone()) Literal(name), pos); 2770 result = new(zone()) Property(isolate(),
2771 result,
2772 NewLiteral(name),
2773 pos);
2763 if (fni_ != NULL) fni_->PushLiteralName(name); 2774 if (fni_ != NULL) fni_->PushLiteralName(name);
2764 break; 2775 break;
2765 } 2776 }
2766 2777
2767 default: 2778 default:
2768 return result; 2779 return result;
2769 } 2780 }
2770 } 2781 }
2771 } 2782 }
2772 2783
(...skipping 15 matching lines...) Expand all
2788 2799
2789 Expression* result; 2800 Expression* result;
2790 if (peek() == Token::NEW) { 2801 if (peek() == Token::NEW) {
2791 result = ParseNewPrefix(stack, CHECK_OK); 2802 result = ParseNewPrefix(stack, CHECK_OK);
2792 } else { 2803 } else {
2793 result = ParseMemberWithNewPrefixesExpression(stack, CHECK_OK); 2804 result = ParseMemberWithNewPrefixesExpression(stack, CHECK_OK);
2794 } 2805 }
2795 2806
2796 if (!stack->is_empty()) { 2807 if (!stack->is_empty()) {
2797 int last = stack->pop(); 2808 int last = stack->pop();
2798 result = new(zone()) CallNew(result, 2809 result = new(zone()) CallNew(isolate(),
2810 result,
2799 new(zone()) ZoneList<Expression*>(0), 2811 new(zone()) ZoneList<Expression*>(0),
2800 last); 2812 last);
2801 } 2813 }
2802 return result; 2814 return result;
2803 } 2815 }
2804 2816
2805 2817
2806 Expression* Parser::ParseNewExpression(bool* ok) { 2818 Expression* Parser::ParseNewExpression(bool* ok) {
2807 PositionStack stack(ok); 2819 PositionStack stack(ok);
2808 return ParseNewPrefix(&stack, ok); 2820 return ParseNewPrefix(&stack, ok);
(...skipping 27 matching lines...) Expand all
2836 } else { 2848 } else {
2837 result = ParsePrimaryExpression(CHECK_OK); 2849 result = ParsePrimaryExpression(CHECK_OK);
2838 } 2850 }
2839 2851
2840 while (true) { 2852 while (true) {
2841 switch (peek()) { 2853 switch (peek()) {
2842 case Token::LBRACK: { 2854 case Token::LBRACK: {
2843 Consume(Token::LBRACK); 2855 Consume(Token::LBRACK);
2844 int pos = scanner().location().beg_pos; 2856 int pos = scanner().location().beg_pos;
2845 Expression* index = ParseExpression(true, CHECK_OK); 2857 Expression* index = ParseExpression(true, CHECK_OK);
2846 result = new(zone()) Property(result, index, pos); 2858 result = new(zone()) Property(isolate(), result, index, pos);
2847 if (fni_ != NULL) { 2859 if (fni_ != NULL) {
2848 if (index->IsPropertyName()) { 2860 if (index->IsPropertyName()) {
2849 fni_->PushLiteralName(index->AsLiteral()->AsPropertyName()); 2861 fni_->PushLiteralName(index->AsLiteral()->AsPropertyName());
2850 } else { 2862 } else {
2851 fni_->PushLiteralName( 2863 fni_->PushLiteralName(
2852 isolate()->factory()->anonymous_function_symbol()); 2864 isolate()->factory()->anonymous_function_symbol());
2853 } 2865 }
2854 } 2866 }
2855 Expect(Token::RBRACK, CHECK_OK); 2867 Expect(Token::RBRACK, CHECK_OK);
2856 break; 2868 break;
2857 } 2869 }
2858 case Token::PERIOD: { 2870 case Token::PERIOD: {
2859 Consume(Token::PERIOD); 2871 Consume(Token::PERIOD);
2860 int pos = scanner().location().beg_pos; 2872 int pos = scanner().location().beg_pos;
2861 Handle<String> name = ParseIdentifierName(CHECK_OK); 2873 Handle<String> name = ParseIdentifierName(CHECK_OK);
2862 result = new(zone()) Property(result, new(zone()) Literal(name), pos); 2874 result = new(zone()) Property(isolate(),
2875 result,
2876 NewLiteral(name),
2877 pos);
2863 if (fni_ != NULL) fni_->PushLiteralName(name); 2878 if (fni_ != NULL) fni_->PushLiteralName(name);
2864 break; 2879 break;
2865 } 2880 }
2866 case Token::LPAREN: { 2881 case Token::LPAREN: {
2867 if ((stack == NULL) || stack->is_empty()) return result; 2882 if ((stack == NULL) || stack->is_empty()) return result;
2868 // Consume one of the new prefixes (already parsed). 2883 // Consume one of the new prefixes (already parsed).
2869 ZoneList<Expression*>* args = ParseArguments(CHECK_OK); 2884 ZoneList<Expression*>* args = ParseArguments(CHECK_OK);
2870 int last = stack->pop(); 2885 int last = stack->pop();
2871 result = new(zone()) CallNew(result, args, last); 2886 result = new(zone()) CallNew(isolate(), result, args, last);
2872 break; 2887 break;
2873 } 2888 }
2874 default: 2889 default:
2875 return result; 2890 return result;
2876 } 2891 }
2877 } 2892 }
2878 } 2893 }
2879 2894
2880 2895
2881 DebuggerStatement* Parser::ParseDebuggerStatement(bool* ok) { 2896 DebuggerStatement* Parser::ParseDebuggerStatement(bool* ok) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
2945 // String 2960 // String
2946 // ArrayLiteral 2961 // ArrayLiteral
2947 // ObjectLiteral 2962 // ObjectLiteral
2948 // RegExpLiteral 2963 // RegExpLiteral
2949 // '(' Expression ')' 2964 // '(' Expression ')'
2950 2965
2951 Expression* result = NULL; 2966 Expression* result = NULL;
2952 switch (peek()) { 2967 switch (peek()) {
2953 case Token::THIS: { 2968 case Token::THIS: {
2954 Consume(Token::THIS); 2969 Consume(Token::THIS);
2955 result = new(zone()) VariableProxy(top_scope_->receiver()); 2970 result = new(zone()) VariableProxy(isolate(), top_scope_->receiver());
2956 break; 2971 break;
2957 } 2972 }
2958 2973
2959 case Token::NULL_LITERAL: 2974 case Token::NULL_LITERAL:
2960 Consume(Token::NULL_LITERAL); 2975 Consume(Token::NULL_LITERAL);
2961 result = new(zone()) Literal(isolate()->factory()->null_value()); 2976 result = new(zone()) Literal(
2977 isolate(), isolate()->factory()->null_value());
2962 break; 2978 break;
2963 2979
2964 case Token::TRUE_LITERAL: 2980 case Token::TRUE_LITERAL:
2965 Consume(Token::TRUE_LITERAL); 2981 Consume(Token::TRUE_LITERAL);
2966 result = new(zone()) Literal(isolate()->factory()->true_value()); 2982 result = new(zone()) Literal(
2983 isolate(), isolate()->factory()->true_value());
2967 break; 2984 break;
2968 2985
2969 case Token::FALSE_LITERAL: 2986 case Token::FALSE_LITERAL:
2970 Consume(Token::FALSE_LITERAL); 2987 Consume(Token::FALSE_LITERAL);
2971 result = new(zone()) Literal(isolate()->factory()->false_value()); 2988 result = new(zone()) Literal(
2989 isolate(), isolate()->factory()->false_value());
2972 break; 2990 break;
2973 2991
2974 case Token::IDENTIFIER: 2992 case Token::IDENTIFIER:
2975 case Token::FUTURE_STRICT_RESERVED_WORD: { 2993 case Token::FUTURE_STRICT_RESERVED_WORD: {
2976 Handle<String> name = ParseIdentifier(CHECK_OK); 2994 Handle<String> name = ParseIdentifier(CHECK_OK);
2977 if (fni_ != NULL) fni_->PushVariableName(name); 2995 if (fni_ != NULL) fni_->PushVariableName(name);
2978 result = top_scope_->NewUnresolved(name, 2996 result = top_scope_->NewUnresolved(name,
2979 inside_with(), 2997 inside_with(),
2980 scanner().location().beg_pos); 2998 scanner().location().beg_pos);
2981 break; 2999 break;
2982 } 3000 }
2983 3001
2984 case Token::NUMBER: { 3002 case Token::NUMBER: {
2985 Consume(Token::NUMBER); 3003 Consume(Token::NUMBER);
2986 ASSERT(scanner().is_literal_ascii()); 3004 ASSERT(scanner().is_literal_ascii());
2987 double value = StringToDouble(isolate()->unicode_cache(), 3005 double value = StringToDouble(isolate()->unicode_cache(),
2988 scanner().literal_ascii_string(), 3006 scanner().literal_ascii_string(),
2989 ALLOW_HEX | ALLOW_OCTALS); 3007 ALLOW_HEX | ALLOW_OCTALS);
2990 result = NewNumberLiteral(value); 3008 result = NewNumberLiteral(value);
2991 break; 3009 break;
2992 } 3010 }
2993 3011
2994 case Token::STRING: { 3012 case Token::STRING: {
2995 Consume(Token::STRING); 3013 Consume(Token::STRING);
2996 Handle<String> symbol = GetSymbol(CHECK_OK); 3014 Handle<String> symbol = GetSymbol(CHECK_OK);
2997 result = new(zone()) Literal(symbol); 3015 result = NewLiteral(symbol);
2998 if (fni_ != NULL) fni_->PushLiteralName(symbol); 3016 if (fni_ != NULL) fni_->PushLiteralName(symbol);
2999 break; 3017 break;
3000 } 3018 }
3001 3019
3002 case Token::ASSIGN_DIV: 3020 case Token::ASSIGN_DIV:
3003 result = ParseRegExpLiteral(true, CHECK_OK); 3021 result = ParseRegExpLiteral(true, CHECK_OK);
3004 break; 3022 break;
3005 3023
3006 case Token::DIV: 3024 case Token::DIV:
3007 result = ParseRegExpLiteral(false, CHECK_OK); 3025 result = ParseRegExpLiteral(false, CHECK_OK);
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
3114 literals->set(i, *boilerplate_value); 3132 literals->set(i, *boilerplate_value);
3115 } 3133 }
3116 } 3134 }
3117 3135
3118 // Simple and shallow arrays can be lazily copied, we transform the 3136 // Simple and shallow arrays can be lazily copied, we transform the
3119 // elements array to a copy-on-write array. 3137 // elements array to a copy-on-write array.
3120 if (is_simple && depth == 1 && values->length() > 0) { 3138 if (is_simple && depth == 1 && values->length() > 0) {
3121 literals->set_map(isolate()->heap()->fixed_cow_array_map()); 3139 literals->set_map(isolate()->heap()->fixed_cow_array_map());
3122 } 3140 }
3123 3141
3124 return new(zone()) ArrayLiteral(literals, values, 3142 return new(zone()) ArrayLiteral(
3125 literal_index, is_simple, depth); 3143 isolate(), literals, values, literal_index, is_simple, depth);
3126 } 3144 }
3127 3145
3128 3146
3129 bool Parser::IsBoilerplateProperty(ObjectLiteral::Property* property) { 3147 bool Parser::IsBoilerplateProperty(ObjectLiteral::Property* property) {
3130 return property != NULL && 3148 return property != NULL &&
3131 property->kind() != ObjectLiteral::Property::PROTOTYPE; 3149 property->kind() != ObjectLiteral::Property::PROTOTYPE;
3132 } 3150 }
3133 3151
3134 3152
3135 bool CompileTimeValue::IsCompileTimeValue(Expression* expression) { 3153 bool CompileTimeValue::IsCompileTimeValue(Expression* expression) {
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
3460 if (peek() != Token::RBRACE) Expect(Token::COMMA, CHECK_OK); 3478 if (peek() != Token::RBRACE) Expect(Token::COMMA, CHECK_OK);
3461 3479
3462 if (fni_ != NULL) { 3480 if (fni_ != NULL) {
3463 fni_->Infer(); 3481 fni_->Infer();
3464 fni_->Leave(); 3482 fni_->Leave();
3465 } 3483 }
3466 continue; // restart the while 3484 continue; // restart the while
3467 } 3485 }
3468 // Failed to parse as get/set property, so it's just a property 3486 // Failed to parse as get/set property, so it's just a property
3469 // called "get" or "set". 3487 // called "get" or "set".
3470 key = new(zone()) Literal(id); 3488 key = NewLiteral(id);
3471 break; 3489 break;
3472 } 3490 }
3473 case Token::STRING: { 3491 case Token::STRING: {
3474 Consume(Token::STRING); 3492 Consume(Token::STRING);
3475 Handle<String> string = GetSymbol(CHECK_OK); 3493 Handle<String> string = GetSymbol(CHECK_OK);
3476 if (fni_ != NULL) fni_->PushLiteralName(string); 3494 if (fni_ != NULL) fni_->PushLiteralName(string);
3477 uint32_t index; 3495 uint32_t index;
3478 if (!string.is_null() && string->AsArrayIndex(&index)) { 3496 if (!string.is_null() && string->AsArrayIndex(&index)) {
3479 key = NewNumberLiteral(index); 3497 key = NewNumberLiteral(index);
3480 break; 3498 break;
3481 } 3499 }
3482 key = new(zone()) Literal(string); 3500 key = NewLiteral(string);
3483 break; 3501 break;
3484 } 3502 }
3485 case Token::NUMBER: { 3503 case Token::NUMBER: {
3486 Consume(Token::NUMBER); 3504 Consume(Token::NUMBER);
3487 ASSERT(scanner().is_literal_ascii()); 3505 ASSERT(scanner().is_literal_ascii());
3488 double value = StringToDouble(isolate()->unicode_cache(), 3506 double value = StringToDouble(isolate()->unicode_cache(),
3489 scanner().literal_ascii_string(), 3507 scanner().literal_ascii_string(),
3490 ALLOW_HEX | ALLOW_OCTALS); 3508 ALLOW_HEX | ALLOW_OCTALS);
3491 key = NewNumberLiteral(value); 3509 key = NewNumberLiteral(value);
3492 break; 3510 break;
3493 } 3511 }
3494 default: 3512 default:
3495 if (Token::IsKeyword(next)) { 3513 if (Token::IsKeyword(next)) {
3496 Consume(next); 3514 Consume(next);
3497 Handle<String> string = GetSymbol(CHECK_OK); 3515 Handle<String> string = GetSymbol(CHECK_OK);
3498 key = new(zone()) Literal(string); 3516 key = NewLiteral(string);
3499 } else { 3517 } else {
3500 // Unexpected token. 3518 // Unexpected token.
3501 Token::Value next = Next(); 3519 Token::Value next = Next();
3502 ReportUnexpectedToken(next); 3520 ReportUnexpectedToken(next);
3503 *ok = false; 3521 *ok = false;
3504 return NULL; 3522 return NULL;
3505 } 3523 }
3506 } 3524 }
3507 3525
3508 Expect(Token::COLON, CHECK_OK); 3526 Expect(Token::COLON, CHECK_OK);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
3541 number_of_boilerplate_properties * 2, TENURED); 3559 number_of_boilerplate_properties * 2, TENURED);
3542 3560
3543 bool is_simple = true; 3561 bool is_simple = true;
3544 bool fast_elements = true; 3562 bool fast_elements = true;
3545 int depth = 1; 3563 int depth = 1;
3546 BuildObjectLiteralConstantProperties(properties, 3564 BuildObjectLiteralConstantProperties(properties,
3547 constant_properties, 3565 constant_properties,
3548 &is_simple, 3566 &is_simple,
3549 &fast_elements, 3567 &fast_elements,
3550 &depth); 3568 &depth);
3551 return new(zone()) ObjectLiteral(constant_properties, 3569 return new(zone()) ObjectLiteral(isolate(),
3552 properties, 3570 constant_properties,
3553 literal_index, 3571 properties,
3554 is_simple, 3572 literal_index,
3555 fast_elements, 3573 is_simple,
3556 depth, 3574 fast_elements,
3557 has_function); 3575 depth,
3576 has_function);
3558 } 3577 }
3559 3578
3560 3579
3561 Expression* Parser::ParseRegExpLiteral(bool seen_equal, bool* ok) { 3580 Expression* Parser::ParseRegExpLiteral(bool seen_equal, bool* ok) {
3562 if (!scanner().ScanRegExpPattern(seen_equal)) { 3581 if (!scanner().ScanRegExpPattern(seen_equal)) {
3563 Next(); 3582 Next();
3564 ReportMessage("unterminated_regexp", Vector<const char*>::empty()); 3583 ReportMessage("unterminated_regexp", Vector<const char*>::empty());
3565 *ok = false; 3584 *ok = false;
3566 return NULL; 3585 return NULL;
3567 } 3586 }
3568 3587
3569 int literal_index = lexical_scope_->NextMaterializedLiteralIndex(); 3588 int literal_index = lexical_scope_->NextMaterializedLiteralIndex();
3570 3589
3571 Handle<String> js_pattern = NextLiteralString(TENURED); 3590 Handle<String> js_pattern = NextLiteralString(TENURED);
3572 scanner().ScanRegExpFlags(); 3591 scanner().ScanRegExpFlags();
3573 Handle<String> js_flags = NextLiteralString(TENURED); 3592 Handle<String> js_flags = NextLiteralString(TENURED);
3574 Next(); 3593 Next();
3575 3594
3576 return new(zone()) RegExpLiteral(js_pattern, js_flags, literal_index); 3595 return new(zone()) RegExpLiteral(
3596 isolate(), js_pattern, js_flags, literal_index);
3577 } 3597 }
3578 3598
3579 3599
3580 ZoneList<Expression*>* Parser::ParseArguments(bool* ok) { 3600 ZoneList<Expression*>* Parser::ParseArguments(bool* ok) {
3581 // Arguments :: 3601 // Arguments ::
3582 // '(' (AssignmentExpression)*[','] ')' 3602 // '(' (AssignmentExpression)*[','] ')'
3583 3603
3584 ZoneList<Expression*>* result = new(zone()) ZoneList<Expression*>(4); 3604 ZoneList<Expression*>* result = new(zone()) ZoneList<Expression*>(4);
3585 Expect(Token::LPAREN, CHECK_OK); 3605 Expect(Token::LPAREN, CHECK_OK);
3586 bool done = (peek() == Token::RPAREN); 3606 bool done = (peek() == Token::RPAREN);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
3683 // function and let it refer to the function itself (closure). 3703 // function and let it refer to the function itself (closure).
3684 // NOTE: We create a proxy and resolve it here so that in the 3704 // NOTE: We create a proxy and resolve it here so that in the
3685 // future we can change the AST to only refer to VariableProxies 3705 // future we can change the AST to only refer to VariableProxies
3686 // instead of Variables and Proxis as is the case now. 3706 // instead of Variables and Proxis as is the case now.
3687 if (!function_name.is_null() && function_name->length() > 0) { 3707 if (!function_name.is_null() && function_name->length() > 0) {
3688 Variable* fvar = top_scope_->DeclareFunctionVar(function_name); 3708 Variable* fvar = top_scope_->DeclareFunctionVar(function_name);
3689 VariableProxy* fproxy = 3709 VariableProxy* fproxy =
3690 top_scope_->NewUnresolved(function_name, inside_with()); 3710 top_scope_->NewUnresolved(function_name, inside_with());
3691 fproxy->BindTo(fvar); 3711 fproxy->BindTo(fvar);
3692 body->Add(new(zone()) ExpressionStatement( 3712 body->Add(new(zone()) ExpressionStatement(
3693 new(zone()) Assignment(Token::INIT_CONST, fproxy, 3713 new(zone()) Assignment(isolate(),
3694 new(zone()) ThisFunction(), 3714 Token::INIT_CONST,
3695 RelocInfo::kNoPosition))); 3715 fproxy,
3716 new(zone()) ThisFunction(isolate()),
3717 RelocInfo::kNoPosition)));
3696 } 3718 }
3697 3719
3698 // Determine if the function will be lazily compiled. The mode can 3720 // Determine if the function will be lazily compiled. The mode can
3699 // only be PARSE_LAZILY if the --lazy flag is true. 3721 // only be PARSE_LAZILY if the --lazy flag is true.
3700 bool is_lazily_compiled = (mode() == PARSE_LAZILY && 3722 bool is_lazily_compiled = (mode() == PARSE_LAZILY &&
3701 top_scope_->outer_scope()->is_global_scope() && 3723 top_scope_->outer_scope()->is_global_scope() &&
3702 top_scope_->HasTrivialOuterContext() && 3724 top_scope_->HasTrivialOuterContext() &&
3703 !parenthesized_function_); 3725 !parenthesized_function_);
3704 parenthesized_function_ = false; // The bit was set for this function only. 3726 parenthesized_function_ = false; // The bit was set for this function only.
3705 3727
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
3775 ReportMessageAt(reserved_loc, "strict_reserved_word", 3797 ReportMessageAt(reserved_loc, "strict_reserved_word",
3776 Vector<const char*>::empty()); 3798 Vector<const char*>::empty());
3777 *ok = false; 3799 *ok = false;
3778 return NULL; 3800 return NULL;
3779 } 3801 }
3780 CheckOctalLiteral(start_pos, end_pos, CHECK_OK); 3802 CheckOctalLiteral(start_pos, end_pos, CHECK_OK);
3781 } 3803 }
3782 } 3804 }
3783 3805
3784 FunctionLiteral* function_literal = 3806 FunctionLiteral* function_literal =
3785 new(zone()) FunctionLiteral(name, 3807 new(zone()) FunctionLiteral(isolate(),
3808 name,
3786 scope, 3809 scope,
3787 body, 3810 body,
3788 materialized_literal_count, 3811 materialized_literal_count,
3789 expected_property_count, 3812 expected_property_count,
3790 only_simple_this_property_assignments, 3813 only_simple_this_property_assignments,
3791 this_property_assignments, 3814 this_property_assignments,
3792 num_parameters, 3815 num_parameters,
3793 start_pos, 3816 start_pos,
3794 end_pos, 3817 end_pos,
3795 (function_name->length() > 0), 3818 (function_name->length() > 0),
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
3836 // Check that the expected number of arguments are being passed. 3859 // Check that the expected number of arguments are being passed.
3837 if (function != NULL && 3860 if (function != NULL &&
3838 function->nargs != -1 && 3861 function->nargs != -1 &&
3839 function->nargs != args->length()) { 3862 function->nargs != args->length()) {
3840 ReportMessage("illegal_access", Vector<const char*>::empty()); 3863 ReportMessage("illegal_access", Vector<const char*>::empty());
3841 *ok = false; 3864 *ok = false;
3842 return NULL; 3865 return NULL;
3843 } 3866 }
3844 3867
3845 // We have a valid intrinsics call or a call to a builtin. 3868 // We have a valid intrinsics call or a call to a builtin.
3846 return new(zone()) CallRuntime(name, function, args); 3869 return new(zone()) CallRuntime(isolate(), name, function, args);
3847 } 3870 }
3848 3871
3849 3872
3850 bool Parser::peek_any_identifier() { 3873 bool Parser::peek_any_identifier() {
3851 Token::Value next = peek(); 3874 Token::Value next = peek();
3852 return next == Token::IDENTIFIER || 3875 return next == Token::IDENTIFIER ||
3853 next == Token::FUTURE_RESERVED_WORD || 3876 next == Token::FUTURE_RESERVED_WORD ||
3854 next == Token::FUTURE_STRICT_RESERVED_WORD; 3877 next == Token::FUTURE_STRICT_RESERVED_WORD;
3855 } 3878 }
3856 3879
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
3892 if (scanner().HasAnyLineTerminatorBeforeNext() || 3915 if (scanner().HasAnyLineTerminatorBeforeNext() ||
3893 tok == Token::RBRACE || 3916 tok == Token::RBRACE ||
3894 tok == Token::EOS) { 3917 tok == Token::EOS) {
3895 return; 3918 return;
3896 } 3919 }
3897 Expect(Token::SEMICOLON, ok); 3920 Expect(Token::SEMICOLON, ok);
3898 } 3921 }
3899 3922
3900 3923
3901 Literal* Parser::GetLiteralUndefined() { 3924 Literal* Parser::GetLiteralUndefined() {
3902 return new(zone()) Literal(isolate()->factory()->undefined_value()); 3925 return NewLiteral(isolate()->factory()->undefined_value());
3903 } 3926 }
3904 3927
3905 3928
3906 Literal* Parser::GetLiteralTheHole() { 3929 Literal* Parser::GetLiteralTheHole() {
3907 return new(zone()) Literal(isolate()->factory()->the_hole_value()); 3930 return NewLiteral(isolate()->factory()->the_hole_value());
3908 } 3931 }
3909 3932
3910 3933
3911 Literal* Parser::GetLiteralNumber(double value) { 3934 Literal* Parser::GetLiteralNumber(double value) {
3912 return NewNumberLiteral(value); 3935 return NewNumberLiteral(value);
3913 } 3936 }
3914 3937
3915 3938
3916 // Parses and identifier that is valid for the current scope, in particular it 3939 // Parses and identifier that is valid for the current scope, in particular it
3917 // fails on strict mode future reserved keywords in a strict scope. 3940 // fails on strict mode future reserved keywords in a strict scope.
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
4053 // target stack has been used from the top of the target stack. Add 4076 // target stack has been used from the top of the target stack. Add
4054 // the break target to any TargetCollectors passed on the stack. 4077 // the break target to any TargetCollectors passed on the stack.
4055 for (Target* t = target_stack_; t != stop; t = t->previous()) { 4078 for (Target* t = target_stack_; t != stop; t = t->previous()) {
4056 TargetCollector* collector = t->node()->AsTargetCollector(); 4079 TargetCollector* collector = t->node()->AsTargetCollector();
4057 if (collector != NULL) collector->AddTarget(target); 4080 if (collector != NULL) collector->AddTarget(target);
4058 } 4081 }
4059 } 4082 }
4060 4083
4061 4084
4062 Literal* Parser::NewNumberLiteral(double number) { 4085 Literal* Parser::NewNumberLiteral(double number) {
4063 return new(zone()) Literal(isolate()->factory()->NewNumber(number, TENURED)); 4086 return NewLiteral(isolate()->factory()->NewNumber(number, TENURED));
4064 } 4087 }
4065 4088
4066 4089
4067 Expression* Parser::NewThrowReferenceError(Handle<String> type) { 4090 Expression* Parser::NewThrowReferenceError(Handle<String> type) {
4068 return NewThrowError(isolate()->factory()->MakeReferenceError_symbol(), 4091 return NewThrowError(isolate()->factory()->MakeReferenceError_symbol(),
4069 type, HandleVector<Object>(NULL, 0)); 4092 type, HandleVector<Object>(NULL, 0));
4070 } 4093 }
4071 4094
4072 4095
4073 Expression* Parser::NewThrowSyntaxError(Handle<String> type, 4096 Expression* Parser::NewThrowSyntaxError(Handle<String> type,
(...skipping 26 matching lines...) Expand all
4100 for (int i = 0; i < argc; i++) { 4123 for (int i = 0; i < argc; i++) {
4101 Handle<Object> element = arguments[i]; 4124 Handle<Object> element = arguments[i];
4102 if (!element.is_null()) { 4125 if (!element.is_null()) {
4103 elements->set(i, *element); 4126 elements->set(i, *element);
4104 } 4127 }
4105 } 4128 }
4106 Handle<JSArray> array = isolate()->factory()->NewJSArrayWithElements(elements, 4129 Handle<JSArray> array = isolate()->factory()->NewJSArrayWithElements(elements,
4107 TENURED); 4130 TENURED);
4108 4131
4109 ZoneList<Expression*>* args = new(zone()) ZoneList<Expression*>(2); 4132 ZoneList<Expression*>* args = new(zone()) ZoneList<Expression*>(2);
4110 args->Add(new(zone()) Literal(type)); 4133 args->Add(NewLiteral(type));
4111 args->Add(new(zone()) Literal(array)); 4134 args->Add(NewLiteral(array));
4112 return new(zone()) Throw(new(zone()) CallRuntime(constructor, NULL, args), 4135 CallRuntime* call_constructor = new(zone()) CallRuntime(isolate(),
4113 scanner().location().beg_pos); 4136 constructor,
4137 NULL,
4138 args);
4139 return new(zone()) Throw(isolate(),
4140 call_constructor,
4141 scanner().location().beg_pos);
4114 } 4142 }
4115 4143
4116 // ---------------------------------------------------------------------------- 4144 // ----------------------------------------------------------------------------
4117 // Regular expressions 4145 // Regular expressions
4118 4146
4119 4147
4120 RegExpParser::RegExpParser(FlatStringReader* in, 4148 RegExpParser::RegExpParser(FlatStringReader* in,
4121 Handle<String>* error, 4149 Handle<String>* error,
4122 bool multiline) 4150 bool multiline)
4123 : isolate_(Isolate::Current()), 4151 : isolate_(Isolate::Current()),
(...skipping 961 matching lines...) Expand 10 before | Expand all | Expand 10 after
5085 info->is_global(), 5113 info->is_global(),
5086 info->StrictMode()); 5114 info->StrictMode());
5087 } 5115 }
5088 } 5116 }
5089 5117
5090 info->SetFunction(result); 5118 info->SetFunction(result);
5091 return (result != NULL); 5119 return (result != NULL);
5092 } 5120 }
5093 5121
5094 } } // namespace v8::internal 5122 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/parser.h ('k') | src/rewriter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698