| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 } | 249 } |
| 250 | 250 |
| 251 | 251 |
| 252 Handle<String> Parser::LookupSymbol(int symbol_id) { | 252 Handle<String> Parser::LookupSymbol(int symbol_id) { |
| 253 // Length of symbol cache is the number of identified symbols. | 253 // Length of symbol cache is the number of identified symbols. |
| 254 // If we are larger than that, or negative, it's not a cached symbol. | 254 // If we are larger than that, or negative, it's not a cached symbol. |
| 255 // This might also happen if there is no preparser symbol data, even | 255 // This might also happen if there is no preparser symbol data, even |
| 256 // if there is some preparser data. | 256 // if there is some preparser data. |
| 257 if (static_cast<unsigned>(symbol_id) | 257 if (static_cast<unsigned>(symbol_id) |
| 258 >= static_cast<unsigned>(symbol_cache_.length())) { | 258 >= static_cast<unsigned>(symbol_cache_.length())) { |
| 259 if (scanner().is_literal_ascii()) { | 259 if (scanner()->is_literal_ascii()) { |
| 260 return isolate()->factory()->InternalizeOneByteString( | 260 return isolate()->factory()->InternalizeOneByteString( |
| 261 Vector<const uint8_t>::cast(scanner().literal_ascii_string())); | 261 Vector<const uint8_t>::cast(scanner()->literal_ascii_string())); |
| 262 } else { | 262 } else { |
| 263 return isolate()->factory()->InternalizeTwoByteString( | 263 return isolate()->factory()->InternalizeTwoByteString( |
| 264 scanner().literal_utf16_string()); | 264 scanner()->literal_utf16_string()); |
| 265 } | 265 } |
| 266 } | 266 } |
| 267 return LookupCachedSymbol(symbol_id); | 267 return LookupCachedSymbol(symbol_id); |
| 268 } | 268 } |
| 269 | 269 |
| 270 | 270 |
| 271 Handle<String> Parser::LookupCachedSymbol(int symbol_id) { | 271 Handle<String> Parser::LookupCachedSymbol(int symbol_id) { |
| 272 // Make sure the cache is large enough to hold the symbol identifier. | 272 // Make sure the cache is large enough to hold the symbol identifier. |
| 273 if (symbol_cache_.length() <= symbol_id) { | 273 if (symbol_cache_.length() <= symbol_id) { |
| 274 // Increase length to index + 1. | 274 // Increase length to index + 1. |
| 275 symbol_cache_.AddBlock(Handle<String>::null(), | 275 symbol_cache_.AddBlock(Handle<String>::null(), |
| 276 symbol_id + 1 - symbol_cache_.length(), zone()); | 276 symbol_id + 1 - symbol_cache_.length(), zone()); |
| 277 } | 277 } |
| 278 Handle<String> result = symbol_cache_.at(symbol_id); | 278 Handle<String> result = symbol_cache_.at(symbol_id); |
| 279 if (result.is_null()) { | 279 if (result.is_null()) { |
| 280 if (scanner().is_literal_ascii()) { | 280 if (scanner()->is_literal_ascii()) { |
| 281 result = isolate()->factory()->InternalizeOneByteString( | 281 result = isolate()->factory()->InternalizeOneByteString( |
| 282 Vector<const uint8_t>::cast(scanner().literal_ascii_string())); | 282 Vector<const uint8_t>::cast(scanner()->literal_ascii_string())); |
| 283 } else { | 283 } else { |
| 284 result = isolate()->factory()->InternalizeTwoByteString( | 284 result = isolate()->factory()->InternalizeTwoByteString( |
| 285 scanner().literal_utf16_string()); | 285 scanner()->literal_utf16_string()); |
| 286 } | 286 } |
| 287 symbol_cache_.at(symbol_id) = result; | 287 symbol_cache_.at(symbol_id) = result; |
| 288 return result; | 288 return result; |
| 289 } | 289 } |
| 290 isolate()->counters()->total_preparse_symbols_skipped()->Increment(); | 290 isolate()->counters()->total_preparse_symbols_skipped()->Increment(); |
| 291 return result; | 291 return result; |
| 292 } | 292 } |
| 293 | 293 |
| 294 | 294 |
| 295 FunctionEntry ScriptDataImpl::GetFunctionEntry(int start) { | 295 FunctionEntry ScriptDataImpl::GetFunctionEntry(int start) { |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 elements->set(i, *arg_string); | 506 elements->set(i, *arg_string); |
| 507 } | 507 } |
| 508 Handle<JSArray> array = factory->NewJSArrayWithElements(elements); | 508 Handle<JSArray> array = factory->NewJSArrayWithElements(elements); |
| 509 Handle<Object> result = factory->NewSyntaxError(message, array); | 509 Handle<Object> result = factory->NewSyntaxError(message, array); |
| 510 parser_->isolate()->Throw(*result, &location); | 510 parser_->isolate()->Throw(*result, &location); |
| 511 } | 511 } |
| 512 | 512 |
| 513 | 513 |
| 514 void ParserTraits::ReportMessage(const char* message, | 514 void ParserTraits::ReportMessage(const char* message, |
| 515 Vector<Handle<String> > args) { | 515 Vector<Handle<String> > args) { |
| 516 Scanner::Location source_location = parser_->scanner().location(); | 516 Scanner::Location source_location = parser_->scanner()->location(); |
| 517 ReportMessageAt(source_location, message, args); | 517 ReportMessageAt(source_location, message, args); |
| 518 } | 518 } |
| 519 | 519 |
| 520 | 520 |
| 521 void ParserTraits::ReportMessageAt(Scanner::Location source_location, | 521 void ParserTraits::ReportMessageAt(Scanner::Location source_location, |
| 522 const char* message, | 522 const char* message, |
| 523 Vector<Handle<String> > args) { | 523 Vector<Handle<String> > args) { |
| 524 MessageLocation location(parser_->script_, | 524 MessageLocation location(parser_->script_, |
| 525 source_location.beg_pos, | 525 source_location.beg_pos, |
| 526 source_location.end_pos); | 526 source_location.end_pos); |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 740 mode = PARSE_EAGERLY; | 740 mode = PARSE_EAGERLY; |
| 741 } | 741 } |
| 742 ParsingModeScope parsing_mode(this, mode); | 742 ParsingModeScope parsing_mode(this, mode); |
| 743 | 743 |
| 744 // Enters 'scope'. | 744 // Enters 'scope'. |
| 745 FunctionState function_state(&function_state_, &scope_, scope, zone()); | 745 FunctionState function_state(&function_state_, &scope_, scope, zone()); |
| 746 | 746 |
| 747 scope_->SetLanguageMode(info->language_mode()); | 747 scope_->SetLanguageMode(info->language_mode()); |
| 748 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone()); | 748 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone()); |
| 749 bool ok = true; | 749 bool ok = true; |
| 750 int beg_pos = scanner().location().beg_pos; | 750 int beg_pos = scanner()->location().beg_pos; |
| 751 ParseSourceElements(body, Token::EOS, info->is_eval(), true, &ok); | 751 ParseSourceElements(body, Token::EOS, info->is_eval(), true, &ok); |
| 752 if (ok && !scope_->is_classic_mode()) { | 752 if (ok && !scope_->is_classic_mode()) { |
| 753 CheckOctalLiteral(beg_pos, scanner().location().end_pos, &ok); | 753 CheckOctalLiteral(beg_pos, scanner()->location().end_pos, &ok); |
| 754 } | 754 } |
| 755 | 755 |
| 756 if (ok && is_extended_mode()) { | 756 if (ok && is_extended_mode()) { |
| 757 CheckConflictingVarDeclarations(scope_, &ok); | 757 CheckConflictingVarDeclarations(scope_, &ok); |
| 758 } | 758 } |
| 759 | 759 |
| 760 if (ok && info->parse_restriction() == ONLY_SINGLE_FUNCTION_LITERAL) { | 760 if (ok && info->parse_restriction() == ONLY_SINGLE_FUNCTION_LITERAL) { |
| 761 if (body->length() != 1 || | 761 if (body->length() != 1 || |
| 762 !body->at(0)->IsExpressionStatement() || | 762 !body->at(0)->IsExpressionStatement() || |
| 763 !body->at(0)->AsExpressionStatement()-> | 763 !body->at(0)->AsExpressionStatement()-> |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 908 TargetScope scope(&this->target_stack_); | 908 TargetScope scope(&this->target_stack_); |
| 909 | 909 |
| 910 ASSERT(processor != NULL); | 910 ASSERT(processor != NULL); |
| 911 bool directive_prologue = true; // Parsing directive prologue. | 911 bool directive_prologue = true; // Parsing directive prologue. |
| 912 | 912 |
| 913 while (peek() != end_token) { | 913 while (peek() != end_token) { |
| 914 if (directive_prologue && peek() != Token::STRING) { | 914 if (directive_prologue && peek() != Token::STRING) { |
| 915 directive_prologue = false; | 915 directive_prologue = false; |
| 916 } | 916 } |
| 917 | 917 |
| 918 Scanner::Location token_loc = scanner().peek_location(); | 918 Scanner::Location token_loc = scanner()->peek_location(); |
| 919 Statement* stat; | 919 Statement* stat; |
| 920 if (is_global && !is_eval) { | 920 if (is_global && !is_eval) { |
| 921 stat = ParseModuleElement(NULL, CHECK_OK); | 921 stat = ParseModuleElement(NULL, CHECK_OK); |
| 922 } else { | 922 } else { |
| 923 stat = ParseBlockElement(NULL, CHECK_OK); | 923 stat = ParseBlockElement(NULL, CHECK_OK); |
| 924 } | 924 } |
| 925 if (stat == NULL || stat->IsEmpty()) { | 925 if (stat == NULL || stat->IsEmpty()) { |
| 926 directive_prologue = false; // End of directive prologue. | 926 directive_prologue = false; // End of directive prologue. |
| 927 continue; | 927 continue; |
| 928 } | 928 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 998 return ParseVariableStatement(kModuleElement, NULL, ok); | 998 return ParseVariableStatement(kModuleElement, NULL, ok); |
| 999 case Token::IMPORT: | 999 case Token::IMPORT: |
| 1000 return ParseImportDeclaration(ok); | 1000 return ParseImportDeclaration(ok); |
| 1001 case Token::EXPORT: | 1001 case Token::EXPORT: |
| 1002 return ParseExportDeclaration(ok); | 1002 return ParseExportDeclaration(ok); |
| 1003 default: { | 1003 default: { |
| 1004 Statement* stmt = ParseStatement(labels, CHECK_OK); | 1004 Statement* stmt = ParseStatement(labels, CHECK_OK); |
| 1005 // Handle 'module' as a context-sensitive keyword. | 1005 // Handle 'module' as a context-sensitive keyword. |
| 1006 if (FLAG_harmony_modules && | 1006 if (FLAG_harmony_modules && |
| 1007 peek() == Token::IDENTIFIER && | 1007 peek() == Token::IDENTIFIER && |
| 1008 !scanner().HasAnyLineTerminatorBeforeNext() && | 1008 !scanner()->HasAnyLineTerminatorBeforeNext() && |
| 1009 stmt != NULL) { | 1009 stmt != NULL) { |
| 1010 ExpressionStatement* estmt = stmt->AsExpressionStatement(); | 1010 ExpressionStatement* estmt = stmt->AsExpressionStatement(); |
| 1011 if (estmt != NULL && | 1011 if (estmt != NULL && |
| 1012 estmt->expression()->AsVariableProxy() != NULL && | 1012 estmt->expression()->AsVariableProxy() != NULL && |
| 1013 estmt->expression()->AsVariableProxy()->name()->Equals( | 1013 estmt->expression()->AsVariableProxy()->name()->Equals( |
| 1014 isolate()->heap()->module_string()) && | 1014 isolate()->heap()->module_string()) && |
| 1015 !scanner().literal_contains_escapes()) { | 1015 !scanner()->literal_contains_escapes()) { |
| 1016 return ParseModuleDeclaration(NULL, ok); | 1016 return ParseModuleDeclaration(NULL, ok); |
| 1017 } | 1017 } |
| 1018 } | 1018 } |
| 1019 return stmt; | 1019 return stmt; |
| 1020 } | 1020 } |
| 1021 } | 1021 } |
| 1022 } | 1022 } |
| 1023 | 1023 |
| 1024 | 1024 |
| 1025 Statement* Parser::ParseModuleDeclaration(ZoneStringList* names, bool* ok) { | 1025 Statement* Parser::ParseModuleDeclaration(ZoneStringList* names, bool* ok) { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1091 | 1091 |
| 1092 int pos = peek_position(); | 1092 int pos = peek_position(); |
| 1093 // Construct block expecting 16 statements. | 1093 // Construct block expecting 16 statements. |
| 1094 Block* body = factory()->NewBlock(NULL, 16, false, RelocInfo::kNoPosition); | 1094 Block* body = factory()->NewBlock(NULL, 16, false, RelocInfo::kNoPosition); |
| 1095 #ifdef DEBUG | 1095 #ifdef DEBUG |
| 1096 if (FLAG_print_interface_details) PrintF("# Literal "); | 1096 if (FLAG_print_interface_details) PrintF("# Literal "); |
| 1097 #endif | 1097 #endif |
| 1098 Scope* scope = NewScope(scope_, MODULE_SCOPE); | 1098 Scope* scope = NewScope(scope_, MODULE_SCOPE); |
| 1099 | 1099 |
| 1100 Expect(Token::LBRACE, CHECK_OK); | 1100 Expect(Token::LBRACE, CHECK_OK); |
| 1101 scope->set_start_position(scanner().location().beg_pos); | 1101 scope->set_start_position(scanner()->location().beg_pos); |
| 1102 scope->SetLanguageMode(EXTENDED_MODE); | 1102 scope->SetLanguageMode(EXTENDED_MODE); |
| 1103 | 1103 |
| 1104 { | 1104 { |
| 1105 BlockState block_state(&scope_, scope); | 1105 BlockState block_state(&scope_, scope); |
| 1106 TargetCollector collector(zone()); | 1106 TargetCollector collector(zone()); |
| 1107 Target target(&this->target_stack_, &collector); | 1107 Target target(&this->target_stack_, &collector); |
| 1108 Target target_body(&this->target_stack_, body); | 1108 Target target_body(&this->target_stack_, body); |
| 1109 | 1109 |
| 1110 while (peek() != Token::RBRACE) { | 1110 while (peek() != Token::RBRACE) { |
| 1111 Statement* stat = ParseModuleElement(NULL, CHECK_OK); | 1111 Statement* stat = ParseModuleElement(NULL, CHECK_OK); |
| 1112 if (stat && !stat->IsEmpty()) { | 1112 if (stat && !stat->IsEmpty()) { |
| 1113 body->AddStatement(stat, zone()); | 1113 body->AddStatement(stat, zone()); |
| 1114 } | 1114 } |
| 1115 } | 1115 } |
| 1116 } | 1116 } |
| 1117 | 1117 |
| 1118 Expect(Token::RBRACE, CHECK_OK); | 1118 Expect(Token::RBRACE, CHECK_OK); |
| 1119 scope->set_end_position(scanner().location().end_pos); | 1119 scope->set_end_position(scanner()->location().end_pos); |
| 1120 body->set_scope(scope); | 1120 body->set_scope(scope); |
| 1121 | 1121 |
| 1122 // Check that all exports are bound. | 1122 // Check that all exports are bound. |
| 1123 Interface* interface = scope->interface(); | 1123 Interface* interface = scope->interface(); |
| 1124 for (Interface::Iterator it = interface->iterator(); | 1124 for (Interface::Iterator it = interface->iterator(); |
| 1125 !it.done(); it.Advance()) { | 1125 !it.done(); it.Advance()) { |
| 1126 if (scope->LocalLookup(it.name()) == NULL) { | 1126 if (scope->LocalLookup(it.name()) == NULL) { |
| 1127 Handle<String> name(it.name()); | 1127 Handle<String> name(it.name()); |
| 1128 ParserTraits::ReportMessage("module_export_undefined", | 1128 ParserTraits::ReportMessage("module_export_undefined", |
| 1129 Vector<Handle<String> >(&name, 1)); | 1129 Vector<Handle<String> >(&name, 1)); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1181 // Identifier | 1181 // Identifier |
| 1182 | 1182 |
| 1183 int pos = peek_position(); | 1183 int pos = peek_position(); |
| 1184 Handle<String> name = ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK); | 1184 Handle<String> name = ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK); |
| 1185 #ifdef DEBUG | 1185 #ifdef DEBUG |
| 1186 if (FLAG_print_interface_details) | 1186 if (FLAG_print_interface_details) |
| 1187 PrintF("# Module variable %s ", name->ToAsciiArray()); | 1187 PrintF("# Module variable %s ", name->ToAsciiArray()); |
| 1188 #endif | 1188 #endif |
| 1189 VariableProxy* proxy = scope_->NewUnresolved( | 1189 VariableProxy* proxy = scope_->NewUnresolved( |
| 1190 factory(), name, Interface::NewModule(zone()), | 1190 factory(), name, Interface::NewModule(zone()), |
| 1191 scanner().location().beg_pos); | 1191 scanner()->location().beg_pos); |
| 1192 | 1192 |
| 1193 return factory()->NewModuleVariable(proxy, pos); | 1193 return factory()->NewModuleVariable(proxy, pos); |
| 1194 } | 1194 } |
| 1195 | 1195 |
| 1196 | 1196 |
| 1197 Module* Parser::ParseModuleUrl(bool* ok) { | 1197 Module* Parser::ParseModuleUrl(bool* ok) { |
| 1198 // Module: | 1198 // Module: |
| 1199 // String | 1199 // String |
| 1200 | 1200 |
| 1201 int pos = peek_position(); | 1201 int pos = peek_position(); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1330 break; | 1330 break; |
| 1331 | 1331 |
| 1332 case Token::VAR: | 1332 case Token::VAR: |
| 1333 case Token::LET: | 1333 case Token::LET: |
| 1334 case Token::CONST: | 1334 case Token::CONST: |
| 1335 result = ParseVariableStatement(kModuleElement, &names, CHECK_OK); | 1335 result = ParseVariableStatement(kModuleElement, &names, CHECK_OK); |
| 1336 break; | 1336 break; |
| 1337 | 1337 |
| 1338 default: | 1338 default: |
| 1339 *ok = false; | 1339 *ok = false; |
| 1340 ReportUnexpectedToken(scanner().current_token()); | 1340 ReportUnexpectedToken(scanner()->current_token()); |
| 1341 return NULL; | 1341 return NULL; |
| 1342 } | 1342 } |
| 1343 | 1343 |
| 1344 // Extract declared names into export declarations and interface. | 1344 // Extract declared names into export declarations and interface. |
| 1345 Interface* interface = scope_->interface(); | 1345 Interface* interface = scope_->interface(); |
| 1346 for (int i = 0; i < names.length(); ++i) { | 1346 for (int i = 0; i < names.length(); ++i) { |
| 1347 #ifdef DEBUG | 1347 #ifdef DEBUG |
| 1348 if (FLAG_print_interface_details) | 1348 if (FLAG_print_interface_details) |
| 1349 PrintF("# Export %s ", names[i]->ToAsciiArray()); | 1349 PrintF("# Export %s ", names[i]->ToAsciiArray()); |
| 1350 #endif | 1350 #endif |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1478 // SourceElement: | 1478 // SourceElement: |
| 1479 // Statement | 1479 // Statement |
| 1480 // FunctionDeclaration | 1480 // FunctionDeclaration |
| 1481 // Common language extension is to allow function declaration in place | 1481 // Common language extension is to allow function declaration in place |
| 1482 // of any statement. This language extension is disabled in strict mode. | 1482 // of any statement. This language extension is disabled in strict mode. |
| 1483 // | 1483 // |
| 1484 // In Harmony mode, this case also handles the extension: | 1484 // In Harmony mode, this case also handles the extension: |
| 1485 // Statement: | 1485 // Statement: |
| 1486 // GeneratorDeclaration | 1486 // GeneratorDeclaration |
| 1487 if (!scope_->is_classic_mode()) { | 1487 if (!scope_->is_classic_mode()) { |
| 1488 ReportMessageAt(scanner().peek_location(), "strict_function"); | 1488 ReportMessageAt(scanner()->peek_location(), "strict_function"); |
| 1489 *ok = false; | 1489 *ok = false; |
| 1490 return NULL; | 1490 return NULL; |
| 1491 } | 1491 } |
| 1492 return ParseFunctionDeclaration(NULL, ok); | 1492 return ParseFunctionDeclaration(NULL, ok); |
| 1493 } | 1493 } |
| 1494 | 1494 |
| 1495 case Token::DEBUGGER: | 1495 case Token::DEBUGGER: |
| 1496 return ParseDebuggerStatement(ok); | 1496 return ParseDebuggerStatement(ok); |
| 1497 | 1497 |
| 1498 default: | 1498 default: |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1721 // GeneratorDeclaration :: | 1721 // GeneratorDeclaration :: |
| 1722 // 'function' '*' Identifier '(' FormalParameterListopt ')' | 1722 // 'function' '*' Identifier '(' FormalParameterListopt ')' |
| 1723 // '{' FunctionBody '}' | 1723 // '{' FunctionBody '}' |
| 1724 Expect(Token::FUNCTION, CHECK_OK); | 1724 Expect(Token::FUNCTION, CHECK_OK); |
| 1725 int pos = position(); | 1725 int pos = position(); |
| 1726 bool is_generator = allow_generators() && Check(Token::MUL); | 1726 bool is_generator = allow_generators() && Check(Token::MUL); |
| 1727 bool is_strict_reserved = false; | 1727 bool is_strict_reserved = false; |
| 1728 Handle<String> name = ParseIdentifierOrStrictReservedWord( | 1728 Handle<String> name = ParseIdentifierOrStrictReservedWord( |
| 1729 &is_strict_reserved, CHECK_OK); | 1729 &is_strict_reserved, CHECK_OK); |
| 1730 FunctionLiteral* fun = ParseFunctionLiteral(name, | 1730 FunctionLiteral* fun = ParseFunctionLiteral(name, |
| 1731 scanner().location(), | 1731 scanner()->location(), |
| 1732 is_strict_reserved, | 1732 is_strict_reserved, |
| 1733 is_generator, | 1733 is_generator, |
| 1734 pos, | 1734 pos, |
| 1735 FunctionLiteral::DECLARATION, | 1735 FunctionLiteral::DECLARATION, |
| 1736 CHECK_OK); | 1736 CHECK_OK); |
| 1737 // Even if we're not at the top-level of the global or a function | 1737 // Even if we're not at the top-level of the global or a function |
| 1738 // scope, we treat it as such and introduce the function with its | 1738 // scope, we treat it as such and introduce the function with its |
| 1739 // initial value upon entering the corresponding scope. | 1739 // initial value upon entering the corresponding scope. |
| 1740 // In extended mode, a function behaves as a lexical binding, except in the | 1740 // In extended mode, a function behaves as a lexical binding, except in the |
| 1741 // global scope. | 1741 // global scope. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1781 // Block :: | 1781 // Block :: |
| 1782 // '{' BlockElement* '}' | 1782 // '{' BlockElement* '}' |
| 1783 | 1783 |
| 1784 // Construct block expecting 16 statements. | 1784 // Construct block expecting 16 statements. |
| 1785 Block* body = | 1785 Block* body = |
| 1786 factory()->NewBlock(labels, 16, false, RelocInfo::kNoPosition); | 1786 factory()->NewBlock(labels, 16, false, RelocInfo::kNoPosition); |
| 1787 Scope* block_scope = NewScope(scope_, BLOCK_SCOPE); | 1787 Scope* block_scope = NewScope(scope_, BLOCK_SCOPE); |
| 1788 | 1788 |
| 1789 // Parse the statements and collect escaping labels. | 1789 // Parse the statements and collect escaping labels. |
| 1790 Expect(Token::LBRACE, CHECK_OK); | 1790 Expect(Token::LBRACE, CHECK_OK); |
| 1791 block_scope->set_start_position(scanner().location().beg_pos); | 1791 block_scope->set_start_position(scanner()->location().beg_pos); |
| 1792 { BlockState block_state(&scope_, block_scope); | 1792 { BlockState block_state(&scope_, block_scope); |
| 1793 TargetCollector collector(zone()); | 1793 TargetCollector collector(zone()); |
| 1794 Target target(&this->target_stack_, &collector); | 1794 Target target(&this->target_stack_, &collector); |
| 1795 Target target_body(&this->target_stack_, body); | 1795 Target target_body(&this->target_stack_, body); |
| 1796 | 1796 |
| 1797 while (peek() != Token::RBRACE) { | 1797 while (peek() != Token::RBRACE) { |
| 1798 Statement* stat = ParseBlockElement(NULL, CHECK_OK); | 1798 Statement* stat = ParseBlockElement(NULL, CHECK_OK); |
| 1799 if (stat && !stat->IsEmpty()) { | 1799 if (stat && !stat->IsEmpty()) { |
| 1800 body->AddStatement(stat, zone()); | 1800 body->AddStatement(stat, zone()); |
| 1801 } | 1801 } |
| 1802 } | 1802 } |
| 1803 } | 1803 } |
| 1804 Expect(Token::RBRACE, CHECK_OK); | 1804 Expect(Token::RBRACE, CHECK_OK); |
| 1805 block_scope->set_end_position(scanner().location().end_pos); | 1805 block_scope->set_end_position(scanner()->location().end_pos); |
| 1806 block_scope = block_scope->FinalizeBlockScope(); | 1806 block_scope = block_scope->FinalizeBlockScope(); |
| 1807 body->set_scope(block_scope); | 1807 body->set_scope(block_scope); |
| 1808 return body; | 1808 return body; |
| 1809 } | 1809 } |
| 1810 | 1810 |
| 1811 | 1811 |
| 1812 Block* Parser::ParseVariableStatement(VariableDeclarationContext var_context, | 1812 Block* Parser::ParseVariableStatement(VariableDeclarationContext var_context, |
| 1813 ZoneStringList* names, | 1813 ZoneStringList* names, |
| 1814 bool* ok) { | 1814 bool* ok) { |
| 1815 // VariableStatement :: | 1815 // VariableStatement :: |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1961 // pre-resolve the proxy because it resides in the same scope as the | 1961 // pre-resolve the proxy because it resides in the same scope as the |
| 1962 // declaration. | 1962 // declaration. |
| 1963 Interface* interface = | 1963 Interface* interface = |
| 1964 is_const ? Interface::NewConst() : Interface::NewValue(); | 1964 is_const ? Interface::NewConst() : Interface::NewValue(); |
| 1965 VariableProxy* proxy = NewUnresolved(name, mode, interface); | 1965 VariableProxy* proxy = NewUnresolved(name, mode, interface); |
| 1966 Declaration* declaration = | 1966 Declaration* declaration = |
| 1967 factory()->NewVariableDeclaration(proxy, mode, scope_, pos); | 1967 factory()->NewVariableDeclaration(proxy, mode, scope_, pos); |
| 1968 Declare(declaration, mode != VAR, CHECK_OK); | 1968 Declare(declaration, mode != VAR, CHECK_OK); |
| 1969 nvars++; | 1969 nvars++; |
| 1970 if (declaration_scope->num_var_or_const() > kMaxNumFunctionLocals) { | 1970 if (declaration_scope->num_var_or_const() > kMaxNumFunctionLocals) { |
| 1971 ReportMessageAt(scanner().location(), "too_many_variables"); | 1971 ReportMessageAt(scanner()->location(), "too_many_variables"); |
| 1972 *ok = false; | 1972 *ok = false; |
| 1973 return NULL; | 1973 return NULL; |
| 1974 } | 1974 } |
| 1975 if (names) names->Add(name, zone()); | 1975 if (names) names->Add(name, zone()); |
| 1976 | 1976 |
| 1977 // Parse initialization expression if present and/or needed. A | 1977 // Parse initialization expression if present and/or needed. A |
| 1978 // declaration of the form: | 1978 // declaration of the form: |
| 1979 // | 1979 // |
| 1980 // var v = x; | 1980 // var v = x; |
| 1981 // | 1981 // |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2195 scope_->RemoveUnresolved(var); | 2195 scope_->RemoveUnresolved(var); |
| 2196 Expect(Token::COLON, CHECK_OK); | 2196 Expect(Token::COLON, CHECK_OK); |
| 2197 return ParseStatement(labels, ok); | 2197 return ParseStatement(labels, ok); |
| 2198 } | 2198 } |
| 2199 | 2199 |
| 2200 // If we have an extension, we allow a native function declaration. | 2200 // If we have an extension, we allow a native function declaration. |
| 2201 // A native function declaration starts with "native function" with | 2201 // A native function declaration starts with "native function" with |
| 2202 // no line-terminator between the two words. | 2202 // no line-terminator between the two words. |
| 2203 if (extension_ != NULL && | 2203 if (extension_ != NULL && |
| 2204 peek() == Token::FUNCTION && | 2204 peek() == Token::FUNCTION && |
| 2205 !scanner().HasAnyLineTerminatorBeforeNext() && | 2205 !scanner()->HasAnyLineTerminatorBeforeNext() && |
| 2206 expr != NULL && | 2206 expr != NULL && |
| 2207 expr->AsVariableProxy() != NULL && | 2207 expr->AsVariableProxy() != NULL && |
| 2208 expr->AsVariableProxy()->name()->Equals( | 2208 expr->AsVariableProxy()->name()->Equals( |
| 2209 isolate()->heap()->native_string()) && | 2209 isolate()->heap()->native_string()) && |
| 2210 !scanner().literal_contains_escapes()) { | 2210 !scanner()->literal_contains_escapes()) { |
| 2211 return ParseNativeDeclaration(ok); | 2211 return ParseNativeDeclaration(ok); |
| 2212 } | 2212 } |
| 2213 | 2213 |
| 2214 // Parsed expression statement, or the context-sensitive 'module' keyword. | 2214 // Parsed expression statement, or the context-sensitive 'module' keyword. |
| 2215 // Only expect semicolon in the former case. | 2215 // Only expect semicolon in the former case. |
| 2216 if (!FLAG_harmony_modules || | 2216 if (!FLAG_harmony_modules || |
| 2217 peek() != Token::IDENTIFIER || | 2217 peek() != Token::IDENTIFIER || |
| 2218 scanner().HasAnyLineTerminatorBeforeNext() || | 2218 scanner()->HasAnyLineTerminatorBeforeNext() || |
| 2219 expr->AsVariableProxy() == NULL || | 2219 expr->AsVariableProxy() == NULL || |
| 2220 !expr->AsVariableProxy()->name()->Equals( | 2220 !expr->AsVariableProxy()->name()->Equals( |
| 2221 isolate()->heap()->module_string()) || | 2221 isolate()->heap()->module_string()) || |
| 2222 scanner().literal_contains_escapes()) { | 2222 scanner()->literal_contains_escapes()) { |
| 2223 ExpectSemicolon(CHECK_OK); | 2223 ExpectSemicolon(CHECK_OK); |
| 2224 } | 2224 } |
| 2225 return factory()->NewExpressionStatement(expr, pos); | 2225 return factory()->NewExpressionStatement(expr, pos); |
| 2226 } | 2226 } |
| 2227 | 2227 |
| 2228 | 2228 |
| 2229 IfStatement* Parser::ParseIfStatement(ZoneStringList* labels, bool* ok) { | 2229 IfStatement* Parser::ParseIfStatement(ZoneStringList* labels, bool* ok) { |
| 2230 // IfStatement :: | 2230 // IfStatement :: |
| 2231 // 'if' '(' Expression ')' Statement ('else' Statement)? | 2231 // 'if' '(' Expression ')' Statement ('else' Statement)? |
| 2232 | 2232 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 2249 | 2249 |
| 2250 | 2250 |
| 2251 Statement* Parser::ParseContinueStatement(bool* ok) { | 2251 Statement* Parser::ParseContinueStatement(bool* ok) { |
| 2252 // ContinueStatement :: | 2252 // ContinueStatement :: |
| 2253 // 'continue' Identifier? ';' | 2253 // 'continue' Identifier? ';' |
| 2254 | 2254 |
| 2255 int pos = peek_position(); | 2255 int pos = peek_position(); |
| 2256 Expect(Token::CONTINUE, CHECK_OK); | 2256 Expect(Token::CONTINUE, CHECK_OK); |
| 2257 Handle<String> label = Handle<String>::null(); | 2257 Handle<String> label = Handle<String>::null(); |
| 2258 Token::Value tok = peek(); | 2258 Token::Value tok = peek(); |
| 2259 if (!scanner().HasAnyLineTerminatorBeforeNext() && | 2259 if (!scanner()->HasAnyLineTerminatorBeforeNext() && |
| 2260 tok != Token::SEMICOLON && tok != Token::RBRACE && tok != Token::EOS) { | 2260 tok != Token::SEMICOLON && tok != Token::RBRACE && tok != Token::EOS) { |
| 2261 // ECMA allows "eval" or "arguments" as labels even in strict mode. | 2261 // ECMA allows "eval" or "arguments" as labels even in strict mode. |
| 2262 label = ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); | 2262 label = ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); |
| 2263 } | 2263 } |
| 2264 IterationStatement* target = NULL; | 2264 IterationStatement* target = NULL; |
| 2265 target = LookupContinueTarget(label, CHECK_OK); | 2265 target = LookupContinueTarget(label, CHECK_OK); |
| 2266 if (target == NULL) { | 2266 if (target == NULL) { |
| 2267 // Illegal continue statement. | 2267 // Illegal continue statement. |
| 2268 const char* message = "illegal_continue"; | 2268 const char* message = "illegal_continue"; |
| 2269 Vector<Handle<String> > args; | 2269 Vector<Handle<String> > args; |
| 2270 if (!label.is_null()) { | 2270 if (!label.is_null()) { |
| 2271 message = "unknown_label"; | 2271 message = "unknown_label"; |
| 2272 args = Vector<Handle<String> >(&label, 1); | 2272 args = Vector<Handle<String> >(&label, 1); |
| 2273 } | 2273 } |
| 2274 ParserTraits::ReportMessageAt(scanner().location(), message, args); | 2274 ParserTraits::ReportMessageAt(scanner()->location(), message, args); |
| 2275 *ok = false; | 2275 *ok = false; |
| 2276 return NULL; | 2276 return NULL; |
| 2277 } | 2277 } |
| 2278 ExpectSemicolon(CHECK_OK); | 2278 ExpectSemicolon(CHECK_OK); |
| 2279 return factory()->NewContinueStatement(target, pos); | 2279 return factory()->NewContinueStatement(target, pos); |
| 2280 } | 2280 } |
| 2281 | 2281 |
| 2282 | 2282 |
| 2283 Statement* Parser::ParseBreakStatement(ZoneStringList* labels, bool* ok) { | 2283 Statement* Parser::ParseBreakStatement(ZoneStringList* labels, bool* ok) { |
| 2284 // BreakStatement :: | 2284 // BreakStatement :: |
| 2285 // 'break' Identifier? ';' | 2285 // 'break' Identifier? ';' |
| 2286 | 2286 |
| 2287 int pos = peek_position(); | 2287 int pos = peek_position(); |
| 2288 Expect(Token::BREAK, CHECK_OK); | 2288 Expect(Token::BREAK, CHECK_OK); |
| 2289 Handle<String> label; | 2289 Handle<String> label; |
| 2290 Token::Value tok = peek(); | 2290 Token::Value tok = peek(); |
| 2291 if (!scanner().HasAnyLineTerminatorBeforeNext() && | 2291 if (!scanner()->HasAnyLineTerminatorBeforeNext() && |
| 2292 tok != Token::SEMICOLON && tok != Token::RBRACE && tok != Token::EOS) { | 2292 tok != Token::SEMICOLON && tok != Token::RBRACE && tok != Token::EOS) { |
| 2293 // ECMA allows "eval" or "arguments" as labels even in strict mode. | 2293 // ECMA allows "eval" or "arguments" as labels even in strict mode. |
| 2294 label = ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); | 2294 label = ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); |
| 2295 } | 2295 } |
| 2296 // Parse labeled break statements that target themselves into | 2296 // Parse labeled break statements that target themselves into |
| 2297 // empty statements, e.g. 'l1: l2: l3: break l2;' | 2297 // empty statements, e.g. 'l1: l2: l3: break l2;' |
| 2298 if (!label.is_null() && ContainsLabel(labels, label)) { | 2298 if (!label.is_null() && ContainsLabel(labels, label)) { |
| 2299 ExpectSemicolon(CHECK_OK); | 2299 ExpectSemicolon(CHECK_OK); |
| 2300 return factory()->NewEmptyStatement(pos); | 2300 return factory()->NewEmptyStatement(pos); |
| 2301 } | 2301 } |
| 2302 BreakableStatement* target = NULL; | 2302 BreakableStatement* target = NULL; |
| 2303 target = LookupBreakTarget(label, CHECK_OK); | 2303 target = LookupBreakTarget(label, CHECK_OK); |
| 2304 if (target == NULL) { | 2304 if (target == NULL) { |
| 2305 // Illegal break statement. | 2305 // Illegal break statement. |
| 2306 const char* message = "illegal_break"; | 2306 const char* message = "illegal_break"; |
| 2307 Vector<Handle<String> > args; | 2307 Vector<Handle<String> > args; |
| 2308 if (!label.is_null()) { | 2308 if (!label.is_null()) { |
| 2309 message = "unknown_label"; | 2309 message = "unknown_label"; |
| 2310 args = Vector<Handle<String> >(&label, 1); | 2310 args = Vector<Handle<String> >(&label, 1); |
| 2311 } | 2311 } |
| 2312 ParserTraits::ReportMessageAt(scanner().location(), message, args); | 2312 ParserTraits::ReportMessageAt(scanner()->location(), message, args); |
| 2313 *ok = false; | 2313 *ok = false; |
| 2314 return NULL; | 2314 return NULL; |
| 2315 } | 2315 } |
| 2316 ExpectSemicolon(CHECK_OK); | 2316 ExpectSemicolon(CHECK_OK); |
| 2317 return factory()->NewBreakStatement(target, pos); | 2317 return factory()->NewBreakStatement(target, pos); |
| 2318 } | 2318 } |
| 2319 | 2319 |
| 2320 | 2320 |
| 2321 Statement* Parser::ParseReturnStatement(bool* ok) { | 2321 Statement* Parser::ParseReturnStatement(bool* ok) { |
| 2322 // ReturnStatement :: | 2322 // ReturnStatement :: |
| 2323 // 'return' Expression? ';' | 2323 // 'return' Expression? ';' |
| 2324 | 2324 |
| 2325 // Consume the return token. It is necessary to do that before | 2325 // Consume the return token. It is necessary to do that before |
| 2326 // reporting any errors on it, because of the way errors are | 2326 // reporting any errors on it, because of the way errors are |
| 2327 // reported (underlining). | 2327 // reported (underlining). |
| 2328 Expect(Token::RETURN, CHECK_OK); | 2328 Expect(Token::RETURN, CHECK_OK); |
| 2329 int pos = position(); | 2329 int pos = position(); |
| 2330 | 2330 |
| 2331 Token::Value tok = peek(); | 2331 Token::Value tok = peek(); |
| 2332 Statement* result; | 2332 Statement* result; |
| 2333 Expression* return_value; | 2333 Expression* return_value; |
| 2334 if (scanner().HasAnyLineTerminatorBeforeNext() || | 2334 if (scanner()->HasAnyLineTerminatorBeforeNext() || |
| 2335 tok == Token::SEMICOLON || | 2335 tok == Token::SEMICOLON || |
| 2336 tok == Token::RBRACE || | 2336 tok == Token::RBRACE || |
| 2337 tok == Token::EOS) { | 2337 tok == Token::EOS) { |
| 2338 return_value = GetLiteralUndefined(position()); | 2338 return_value = GetLiteralUndefined(position()); |
| 2339 } else { | 2339 } else { |
| 2340 return_value = ParseExpression(true, CHECK_OK); | 2340 return_value = ParseExpression(true, CHECK_OK); |
| 2341 } | 2341 } |
| 2342 ExpectSemicolon(CHECK_OK); | 2342 ExpectSemicolon(CHECK_OK); |
| 2343 if (is_generator()) { | 2343 if (is_generator()) { |
| 2344 Expression* generator = factory()->NewVariableProxy( | 2344 Expression* generator = factory()->NewVariableProxy( |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2381 } | 2381 } |
| 2382 | 2382 |
| 2383 Expect(Token::LPAREN, CHECK_OK); | 2383 Expect(Token::LPAREN, CHECK_OK); |
| 2384 Expression* expr = ParseExpression(true, CHECK_OK); | 2384 Expression* expr = ParseExpression(true, CHECK_OK); |
| 2385 Expect(Token::RPAREN, CHECK_OK); | 2385 Expect(Token::RPAREN, CHECK_OK); |
| 2386 | 2386 |
| 2387 scope_->DeclarationScope()->RecordWithStatement(); | 2387 scope_->DeclarationScope()->RecordWithStatement(); |
| 2388 Scope* with_scope = NewScope(scope_, WITH_SCOPE); | 2388 Scope* with_scope = NewScope(scope_, WITH_SCOPE); |
| 2389 Statement* stmt; | 2389 Statement* stmt; |
| 2390 { BlockState block_state(&scope_, with_scope); | 2390 { BlockState block_state(&scope_, with_scope); |
| 2391 with_scope->set_start_position(scanner().peek_location().beg_pos); | 2391 with_scope->set_start_position(scanner()->peek_location().beg_pos); |
| 2392 stmt = ParseStatement(labels, CHECK_OK); | 2392 stmt = ParseStatement(labels, CHECK_OK); |
| 2393 with_scope->set_end_position(scanner().location().end_pos); | 2393 with_scope->set_end_position(scanner()->location().end_pos); |
| 2394 } | 2394 } |
| 2395 return factory()->NewWithStatement(with_scope, expr, stmt, pos); | 2395 return factory()->NewWithStatement(with_scope, expr, stmt, pos); |
| 2396 } | 2396 } |
| 2397 | 2397 |
| 2398 | 2398 |
| 2399 CaseClause* Parser::ParseCaseClause(bool* default_seen_ptr, bool* ok) { | 2399 CaseClause* Parser::ParseCaseClause(bool* default_seen_ptr, bool* ok) { |
| 2400 // CaseClause :: | 2400 // CaseClause :: |
| 2401 // 'case' Expression ':' Statement* | 2401 // 'case' Expression ':' Statement* |
| 2402 // 'default' ':' Statement* | 2402 // 'default' ':' Statement* |
| 2403 | 2403 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2457 return statement; | 2457 return statement; |
| 2458 } | 2458 } |
| 2459 | 2459 |
| 2460 | 2460 |
| 2461 Statement* Parser::ParseThrowStatement(bool* ok) { | 2461 Statement* Parser::ParseThrowStatement(bool* ok) { |
| 2462 // ThrowStatement :: | 2462 // ThrowStatement :: |
| 2463 // 'throw' Expression ';' | 2463 // 'throw' Expression ';' |
| 2464 | 2464 |
| 2465 Expect(Token::THROW, CHECK_OK); | 2465 Expect(Token::THROW, CHECK_OK); |
| 2466 int pos = position(); | 2466 int pos = position(); |
| 2467 if (scanner().HasAnyLineTerminatorBeforeNext()) { | 2467 if (scanner()->HasAnyLineTerminatorBeforeNext()) { |
| 2468 ReportMessage("newline_after_throw", Vector<const char*>::empty()); | 2468 ReportMessage("newline_after_throw", Vector<const char*>::empty()); |
| 2469 *ok = false; | 2469 *ok = false; |
| 2470 return NULL; | 2470 return NULL; |
| 2471 } | 2471 } |
| 2472 Expression* exception = ParseExpression(true, CHECK_OK); | 2472 Expression* exception = ParseExpression(true, CHECK_OK); |
| 2473 ExpectSemicolon(CHECK_OK); | 2473 ExpectSemicolon(CHECK_OK); |
| 2474 | 2474 |
| 2475 return factory()->NewExpressionStatement( | 2475 return factory()->NewExpressionStatement( |
| 2476 factory()->NewThrow(exception, pos), pos); | 2476 factory()->NewThrow(exception, pos), pos); |
| 2477 } | 2477 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2513 TargetCollector catch_collector(zone()); | 2513 TargetCollector catch_collector(zone()); |
| 2514 Scope* catch_scope = NULL; | 2514 Scope* catch_scope = NULL; |
| 2515 Variable* catch_variable = NULL; | 2515 Variable* catch_variable = NULL; |
| 2516 Block* catch_block = NULL; | 2516 Block* catch_block = NULL; |
| 2517 Handle<String> name; | 2517 Handle<String> name; |
| 2518 if (tok == Token::CATCH) { | 2518 if (tok == Token::CATCH) { |
| 2519 Consume(Token::CATCH); | 2519 Consume(Token::CATCH); |
| 2520 | 2520 |
| 2521 Expect(Token::LPAREN, CHECK_OK); | 2521 Expect(Token::LPAREN, CHECK_OK); |
| 2522 catch_scope = NewScope(scope_, CATCH_SCOPE); | 2522 catch_scope = NewScope(scope_, CATCH_SCOPE); |
| 2523 catch_scope->set_start_position(scanner().location().beg_pos); | 2523 catch_scope->set_start_position(scanner()->location().beg_pos); |
| 2524 name = ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK); | 2524 name = ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK); |
| 2525 | 2525 |
| 2526 Expect(Token::RPAREN, CHECK_OK); | 2526 Expect(Token::RPAREN, CHECK_OK); |
| 2527 | 2527 |
| 2528 Target target(&this->target_stack_, &catch_collector); | 2528 Target target(&this->target_stack_, &catch_collector); |
| 2529 VariableMode mode = is_extended_mode() ? LET : VAR; | 2529 VariableMode mode = is_extended_mode() ? LET : VAR; |
| 2530 catch_variable = | 2530 catch_variable = |
| 2531 catch_scope->DeclareLocal(name, mode, kCreatedInitialized); | 2531 catch_scope->DeclareLocal(name, mode, kCreatedInitialized); |
| 2532 | 2532 |
| 2533 BlockState block_state(&scope_, catch_scope); | 2533 BlockState block_state(&scope_, catch_scope); |
| 2534 catch_block = ParseBlock(NULL, CHECK_OK); | 2534 catch_block = ParseBlock(NULL, CHECK_OK); |
| 2535 | 2535 |
| 2536 catch_scope->set_end_position(scanner().location().end_pos); | 2536 catch_scope->set_end_position(scanner()->location().end_pos); |
| 2537 tok = peek(); | 2537 tok = peek(); |
| 2538 } | 2538 } |
| 2539 | 2539 |
| 2540 Block* finally_block = NULL; | 2540 Block* finally_block = NULL; |
| 2541 ASSERT(tok == Token::FINALLY || catch_block != NULL); | 2541 ASSERT(tok == Token::FINALLY || catch_block != NULL); |
| 2542 if (tok == Token::FINALLY) { | 2542 if (tok == Token::FINALLY) { |
| 2543 Consume(Token::FINALLY); | 2543 Consume(Token::FINALLY); |
| 2544 finally_block = ParseBlock(NULL, CHECK_OK); | 2544 finally_block = ParseBlock(NULL, CHECK_OK); |
| 2545 } | 2545 } |
| 2546 | 2546 |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2719 int pos = peek_position(); | 2719 int pos = peek_position(); |
| 2720 Statement* init = NULL; | 2720 Statement* init = NULL; |
| 2721 | 2721 |
| 2722 // Create an in-between scope for let-bound iteration variables. | 2722 // Create an in-between scope for let-bound iteration variables. |
| 2723 Scope* saved_scope = scope_; | 2723 Scope* saved_scope = scope_; |
| 2724 Scope* for_scope = NewScope(scope_, BLOCK_SCOPE); | 2724 Scope* for_scope = NewScope(scope_, BLOCK_SCOPE); |
| 2725 scope_ = for_scope; | 2725 scope_ = for_scope; |
| 2726 | 2726 |
| 2727 Expect(Token::FOR, CHECK_OK); | 2727 Expect(Token::FOR, CHECK_OK); |
| 2728 Expect(Token::LPAREN, CHECK_OK); | 2728 Expect(Token::LPAREN, CHECK_OK); |
| 2729 for_scope->set_start_position(scanner().location().beg_pos); | 2729 for_scope->set_start_position(scanner()->location().beg_pos); |
| 2730 if (peek() != Token::SEMICOLON) { | 2730 if (peek() != Token::SEMICOLON) { |
| 2731 if (peek() == Token::VAR || peek() == Token::CONST) { | 2731 if (peek() == Token::VAR || peek() == Token::CONST) { |
| 2732 bool is_const = peek() == Token::CONST; | 2732 bool is_const = peek() == Token::CONST; |
| 2733 Handle<String> name; | 2733 Handle<String> name; |
| 2734 VariableDeclarationProperties decl_props = kHasNoInitializers; | 2734 VariableDeclarationProperties decl_props = kHasNoInitializers; |
| 2735 Block* variable_statement = | 2735 Block* variable_statement = |
| 2736 ParseVariableDeclarations(kForStatement, &decl_props, NULL, &name, | 2736 ParseVariableDeclarations(kForStatement, &decl_props, NULL, &name, |
| 2737 CHECK_OK); | 2737 CHECK_OK); |
| 2738 bool accept_OF = decl_props == kHasNoInitializers; | 2738 bool accept_OF = decl_props == kHasNoInitializers; |
| 2739 ForEachStatement::VisitMode mode; | 2739 ForEachStatement::VisitMode mode; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2750 | 2750 |
| 2751 VariableProxy* each = | 2751 VariableProxy* each = |
| 2752 scope_->NewUnresolved(factory(), name, interface); | 2752 scope_->NewUnresolved(factory(), name, interface); |
| 2753 Statement* body = ParseStatement(NULL, CHECK_OK); | 2753 Statement* body = ParseStatement(NULL, CHECK_OK); |
| 2754 InitializeForEachStatement(loop, each, enumerable, body); | 2754 InitializeForEachStatement(loop, each, enumerable, body); |
| 2755 Block* result = | 2755 Block* result = |
| 2756 factory()->NewBlock(NULL, 2, false, RelocInfo::kNoPosition); | 2756 factory()->NewBlock(NULL, 2, false, RelocInfo::kNoPosition); |
| 2757 result->AddStatement(variable_statement, zone()); | 2757 result->AddStatement(variable_statement, zone()); |
| 2758 result->AddStatement(loop, zone()); | 2758 result->AddStatement(loop, zone()); |
| 2759 scope_ = saved_scope; | 2759 scope_ = saved_scope; |
| 2760 for_scope->set_end_position(scanner().location().end_pos); | 2760 for_scope->set_end_position(scanner()->location().end_pos); |
| 2761 for_scope = for_scope->FinalizeBlockScope(); | 2761 for_scope = for_scope->FinalizeBlockScope(); |
| 2762 ASSERT(for_scope == NULL); | 2762 ASSERT(for_scope == NULL); |
| 2763 // Parsed for-in loop w/ variable/const declaration. | 2763 // Parsed for-in loop w/ variable/const declaration. |
| 2764 return result; | 2764 return result; |
| 2765 } else { | 2765 } else { |
| 2766 init = variable_statement; | 2766 init = variable_statement; |
| 2767 } | 2767 } |
| 2768 } else if (peek() == Token::LET) { | 2768 } else if (peek() == Token::LET) { |
| 2769 Handle<String> name; | 2769 Handle<String> name; |
| 2770 VariableDeclarationProperties decl_props = kHasNoInitializers; | 2770 VariableDeclarationProperties decl_props = kHasNoInitializers; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2814 factory()->NewBlock(NULL, 3, false, RelocInfo::kNoPosition); | 2814 factory()->NewBlock(NULL, 3, false, RelocInfo::kNoPosition); |
| 2815 Assignment* assignment = factory()->NewAssignment( | 2815 Assignment* assignment = factory()->NewAssignment( |
| 2816 Token::ASSIGN, each, temp_proxy, RelocInfo::kNoPosition); | 2816 Token::ASSIGN, each, temp_proxy, RelocInfo::kNoPosition); |
| 2817 Statement* assignment_statement = factory()->NewExpressionStatement( | 2817 Statement* assignment_statement = factory()->NewExpressionStatement( |
| 2818 assignment, RelocInfo::kNoPosition); | 2818 assignment, RelocInfo::kNoPosition); |
| 2819 body_block->AddStatement(variable_statement, zone()); | 2819 body_block->AddStatement(variable_statement, zone()); |
| 2820 body_block->AddStatement(assignment_statement, zone()); | 2820 body_block->AddStatement(assignment_statement, zone()); |
| 2821 body_block->AddStatement(body, zone()); | 2821 body_block->AddStatement(body, zone()); |
| 2822 InitializeForEachStatement(loop, temp_proxy, enumerable, body_block); | 2822 InitializeForEachStatement(loop, temp_proxy, enumerable, body_block); |
| 2823 scope_ = saved_scope; | 2823 scope_ = saved_scope; |
| 2824 for_scope->set_end_position(scanner().location().end_pos); | 2824 for_scope->set_end_position(scanner()->location().end_pos); |
| 2825 for_scope = for_scope->FinalizeBlockScope(); | 2825 for_scope = for_scope->FinalizeBlockScope(); |
| 2826 body_block->set_scope(for_scope); | 2826 body_block->set_scope(for_scope); |
| 2827 // Parsed for-in loop w/ let declaration. | 2827 // Parsed for-in loop w/ let declaration. |
| 2828 return loop; | 2828 return loop; |
| 2829 | 2829 |
| 2830 } else { | 2830 } else { |
| 2831 init = variable_statement; | 2831 init = variable_statement; |
| 2832 } | 2832 } |
| 2833 } else { | 2833 } else { |
| 2834 Expression* expression = ParseExpression(false, CHECK_OK); | 2834 Expression* expression = ParseExpression(false, CHECK_OK); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2848 ForEachStatement* loop = | 2848 ForEachStatement* loop = |
| 2849 factory()->NewForEachStatement(mode, labels, pos); | 2849 factory()->NewForEachStatement(mode, labels, pos); |
| 2850 Target target(&this->target_stack_, loop); | 2850 Target target(&this->target_stack_, loop); |
| 2851 | 2851 |
| 2852 Expression* enumerable = ParseExpression(true, CHECK_OK); | 2852 Expression* enumerable = ParseExpression(true, CHECK_OK); |
| 2853 Expect(Token::RPAREN, CHECK_OK); | 2853 Expect(Token::RPAREN, CHECK_OK); |
| 2854 | 2854 |
| 2855 Statement* body = ParseStatement(NULL, CHECK_OK); | 2855 Statement* body = ParseStatement(NULL, CHECK_OK); |
| 2856 InitializeForEachStatement(loop, expression, enumerable, body); | 2856 InitializeForEachStatement(loop, expression, enumerable, body); |
| 2857 scope_ = saved_scope; | 2857 scope_ = saved_scope; |
| 2858 for_scope->set_end_position(scanner().location().end_pos); | 2858 for_scope->set_end_position(scanner()->location().end_pos); |
| 2859 for_scope = for_scope->FinalizeBlockScope(); | 2859 for_scope = for_scope->FinalizeBlockScope(); |
| 2860 ASSERT(for_scope == NULL); | 2860 ASSERT(for_scope == NULL); |
| 2861 // Parsed for-in loop. | 2861 // Parsed for-in loop. |
| 2862 return loop; | 2862 return loop; |
| 2863 | 2863 |
| 2864 } else { | 2864 } else { |
| 2865 init = factory()->NewExpressionStatement( | 2865 init = factory()->NewExpressionStatement( |
| 2866 expression, RelocInfo::kNoPosition); | 2866 expression, RelocInfo::kNoPosition); |
| 2867 } | 2867 } |
| 2868 } | 2868 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2883 | 2883 |
| 2884 Statement* next = NULL; | 2884 Statement* next = NULL; |
| 2885 if (peek() != Token::RPAREN) { | 2885 if (peek() != Token::RPAREN) { |
| 2886 Expression* exp = ParseExpression(true, CHECK_OK); | 2886 Expression* exp = ParseExpression(true, CHECK_OK); |
| 2887 next = factory()->NewExpressionStatement(exp, RelocInfo::kNoPosition); | 2887 next = factory()->NewExpressionStatement(exp, RelocInfo::kNoPosition); |
| 2888 } | 2888 } |
| 2889 Expect(Token::RPAREN, CHECK_OK); | 2889 Expect(Token::RPAREN, CHECK_OK); |
| 2890 | 2890 |
| 2891 Statement* body = ParseStatement(NULL, CHECK_OK); | 2891 Statement* body = ParseStatement(NULL, CHECK_OK); |
| 2892 scope_ = saved_scope; | 2892 scope_ = saved_scope; |
| 2893 for_scope->set_end_position(scanner().location().end_pos); | 2893 for_scope->set_end_position(scanner()->location().end_pos); |
| 2894 for_scope = for_scope->FinalizeBlockScope(); | 2894 for_scope = for_scope->FinalizeBlockScope(); |
| 2895 if (for_scope != NULL) { | 2895 if (for_scope != NULL) { |
| 2896 // Rewrite a for statement of the form | 2896 // Rewrite a for statement of the form |
| 2897 // | 2897 // |
| 2898 // for (let x = i; c; n) b | 2898 // for (let x = i; c; n) b |
| 2899 // | 2899 // |
| 2900 // into | 2900 // into |
| 2901 // | 2901 // |
| 2902 // { | 2902 // { |
| 2903 // let x = i; | 2903 // let x = i; |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3252 return ParsePostfixExpression(ok); | 3252 return ParsePostfixExpression(ok); |
| 3253 } | 3253 } |
| 3254 } | 3254 } |
| 3255 | 3255 |
| 3256 | 3256 |
| 3257 Expression* Parser::ParsePostfixExpression(bool* ok) { | 3257 Expression* Parser::ParsePostfixExpression(bool* ok) { |
| 3258 // PostfixExpression :: | 3258 // PostfixExpression :: |
| 3259 // LeftHandSideExpression ('++' | '--')? | 3259 // LeftHandSideExpression ('++' | '--')? |
| 3260 | 3260 |
| 3261 Expression* expression = ParseLeftHandSideExpression(CHECK_OK); | 3261 Expression* expression = ParseLeftHandSideExpression(CHECK_OK); |
| 3262 if (!scanner().HasAnyLineTerminatorBeforeNext() && | 3262 if (!scanner()->HasAnyLineTerminatorBeforeNext() && |
| 3263 Token::IsCountOp(peek())) { | 3263 Token::IsCountOp(peek())) { |
| 3264 // Signal a reference error if the expression is an invalid | 3264 // Signal a reference error if the expression is an invalid |
| 3265 // left-hand side expression. We could report this as a syntax | 3265 // left-hand side expression. We could report this as a syntax |
| 3266 // error here but for compatibility with JSC we choose to report the | 3266 // error here but for compatibility with JSC we choose to report the |
| 3267 // error at runtime. | 3267 // error at runtime. |
| 3268 if (expression == NULL || !expression->IsValidLeftHandSide()) { | 3268 if (expression == NULL || !expression->IsValidLeftHandSide()) { |
| 3269 Handle<String> message = | 3269 Handle<String> message = |
| 3270 isolate()->factory()->invalid_lhs_in_postfix_op_string(); | 3270 isolate()->factory()->invalid_lhs_in_postfix_op_string(); |
| 3271 expression = NewThrowReferenceError(message); | 3271 expression = NewThrowReferenceError(message); |
| 3272 } | 3272 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3305 Consume(Token::LBRACK); | 3305 Consume(Token::LBRACK); |
| 3306 int pos = position(); | 3306 int pos = position(); |
| 3307 Expression* index = ParseExpression(true, CHECK_OK); | 3307 Expression* index = ParseExpression(true, CHECK_OK); |
| 3308 result = factory()->NewProperty(result, index, pos); | 3308 result = factory()->NewProperty(result, index, pos); |
| 3309 Expect(Token::RBRACK, CHECK_OK); | 3309 Expect(Token::RBRACK, CHECK_OK); |
| 3310 break; | 3310 break; |
| 3311 } | 3311 } |
| 3312 | 3312 |
| 3313 case Token::LPAREN: { | 3313 case Token::LPAREN: { |
| 3314 int pos; | 3314 int pos; |
| 3315 if (scanner().current_token() == Token::IDENTIFIER) { | 3315 if (scanner()->current_token() == Token::IDENTIFIER) { |
| 3316 // For call of an identifier we want to report position of | 3316 // For call of an identifier we want to report position of |
| 3317 // the identifier as position of the call in the stack trace. | 3317 // the identifier as position of the call in the stack trace. |
| 3318 pos = position(); | 3318 pos = position(); |
| 3319 } else { | 3319 } else { |
| 3320 // For other kinds of calls we record position of the parenthesis as | 3320 // For other kinds of calls we record position of the parenthesis as |
| 3321 // position of the call. Note that this is extremely important for | 3321 // position of the call. Note that this is extremely important for |
| 3322 // expressions of the form function(){...}() for which call position | 3322 // expressions of the form function(){...}() for which call position |
| 3323 // should not point to the closing brace otherwise it will intersect | 3323 // should not point to the closing brace otherwise it will intersect |
| 3324 // with positions recorded for function literal and confuse debugger. | 3324 // with positions recorded for function literal and confuse debugger. |
| 3325 pos = peek_position(); | 3325 pos = peek_position(); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3419 if (peek() == Token::FUNCTION) { | 3419 if (peek() == Token::FUNCTION) { |
| 3420 Consume(Token::FUNCTION); | 3420 Consume(Token::FUNCTION); |
| 3421 int function_token_position = position(); | 3421 int function_token_position = position(); |
| 3422 bool is_generator = allow_generators() && Check(Token::MUL); | 3422 bool is_generator = allow_generators() && Check(Token::MUL); |
| 3423 Handle<String> name; | 3423 Handle<String> name; |
| 3424 bool is_strict_reserved_name = false; | 3424 bool is_strict_reserved_name = false; |
| 3425 Scanner::Location function_name_location = Scanner::Location::invalid(); | 3425 Scanner::Location function_name_location = Scanner::Location::invalid(); |
| 3426 if (peek_any_identifier()) { | 3426 if (peek_any_identifier()) { |
| 3427 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved_name, | 3427 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved_name, |
| 3428 CHECK_OK); | 3428 CHECK_OK); |
| 3429 function_name_location = scanner().location(); | 3429 function_name_location = scanner()->location(); |
| 3430 } | 3430 } |
| 3431 FunctionLiteral::FunctionType function_type = name.is_null() | 3431 FunctionLiteral::FunctionType function_type = name.is_null() |
| 3432 ? FunctionLiteral::ANONYMOUS_EXPRESSION | 3432 ? FunctionLiteral::ANONYMOUS_EXPRESSION |
| 3433 : FunctionLiteral::NAMED_EXPRESSION; | 3433 : FunctionLiteral::NAMED_EXPRESSION; |
| 3434 result = ParseFunctionLiteral(name, | 3434 result = ParseFunctionLiteral(name, |
| 3435 function_name_location, | 3435 function_name_location, |
| 3436 is_strict_reserved_name, | 3436 is_strict_reserved_name, |
| 3437 is_generator, | 3437 is_generator, |
| 3438 function_token_position, | 3438 function_token_position, |
| 3439 function_type, | 3439 function_type, |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3630 return NULL; | 3630 return NULL; |
| 3631 } | 3631 } |
| 3632 // Validate the property. | 3632 // Validate the property. |
| 3633 PropertyKind type = is_getter ? kGetterProperty : kSetterProperty; | 3633 PropertyKind type = is_getter ? kGetterProperty : kSetterProperty; |
| 3634 checker.CheckProperty(next, type, CHECK_OK); | 3634 checker.CheckProperty(next, type, CHECK_OK); |
| 3635 Handle<String> name = is_keyword | 3635 Handle<String> name = is_keyword |
| 3636 ? isolate_->factory()->InternalizeUtf8String(Token::String(next)) | 3636 ? isolate_->factory()->InternalizeUtf8String(Token::String(next)) |
| 3637 : GetSymbol(); | 3637 : GetSymbol(); |
| 3638 FunctionLiteral* value = | 3638 FunctionLiteral* value = |
| 3639 ParseFunctionLiteral(name, | 3639 ParseFunctionLiteral(name, |
| 3640 scanner().location(), | 3640 scanner()->location(), |
| 3641 false, // reserved words are allowed here | 3641 false, // reserved words are allowed here |
| 3642 false, // not a generator | 3642 false, // not a generator |
| 3643 RelocInfo::kNoPosition, | 3643 RelocInfo::kNoPosition, |
| 3644 FunctionLiteral::ANONYMOUS_EXPRESSION, | 3644 FunctionLiteral::ANONYMOUS_EXPRESSION, |
| 3645 CHECK_OK); | 3645 CHECK_OK); |
| 3646 // Allow any number of parameters for compatibilty with JSC. | 3646 // Allow any number of parameters for compatibilty with JSC. |
| 3647 // Specification only allows zero parameters for get and one for set. | 3647 // Specification only allows zero parameters for get and one for set. |
| 3648 ObjectLiteral::Property* property = | 3648 ObjectLiteral::Property* property = |
| 3649 factory()->NewObjectLiteralProperty(is_getter, value, next_pos); | 3649 factory()->NewObjectLiteralProperty(is_getter, value, next_pos); |
| 3650 if (ObjectLiteral::IsBoilerplateProperty(property)) { | 3650 if (ObjectLiteral::IsBoilerplateProperty(property)) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 3671 uint32_t index; | 3671 uint32_t index; |
| 3672 if (!string.is_null() && string->AsArrayIndex(&index)) { | 3672 if (!string.is_null() && string->AsArrayIndex(&index)) { |
| 3673 key = factory()->NewNumberLiteral(index, next_pos); | 3673 key = factory()->NewNumberLiteral(index, next_pos); |
| 3674 break; | 3674 break; |
| 3675 } | 3675 } |
| 3676 key = factory()->NewLiteral(string, next_pos); | 3676 key = factory()->NewLiteral(string, next_pos); |
| 3677 break; | 3677 break; |
| 3678 } | 3678 } |
| 3679 case Token::NUMBER: { | 3679 case Token::NUMBER: { |
| 3680 Consume(Token::NUMBER); | 3680 Consume(Token::NUMBER); |
| 3681 ASSERT(scanner().is_literal_ascii()); | 3681 ASSERT(scanner()->is_literal_ascii()); |
| 3682 double value = StringToDouble(isolate()->unicode_cache(), | 3682 double value = StringToDouble(isolate()->unicode_cache(), |
| 3683 scanner().literal_ascii_string(), | 3683 scanner()->literal_ascii_string(), |
| 3684 ALLOW_HEX | ALLOW_OCTAL | | 3684 ALLOW_HEX | ALLOW_OCTAL | |
| 3685 ALLOW_IMPLICIT_OCTAL | ALLOW_BINARY); | 3685 ALLOW_IMPLICIT_OCTAL | ALLOW_BINARY); |
| 3686 key = factory()->NewNumberLiteral(value, next_pos); | 3686 key = factory()->NewNumberLiteral(value, next_pos); |
| 3687 break; | 3687 break; |
| 3688 } | 3688 } |
| 3689 default: | 3689 default: |
| 3690 if (Token::IsKeyword(next)) { | 3690 if (Token::IsKeyword(next)) { |
| 3691 Consume(next); | 3691 Consume(next); |
| 3692 Handle<String> string = GetSymbol(); | 3692 Handle<String> string = GetSymbol(); |
| 3693 key = factory()->NewLiteral(string, next_pos); | 3693 key = factory()->NewLiteral(string, next_pos); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3749 // Arguments :: | 3749 // Arguments :: |
| 3750 // '(' (AssignmentExpression)*[','] ')' | 3750 // '(' (AssignmentExpression)*[','] ')' |
| 3751 | 3751 |
| 3752 ZoneList<Expression*>* result = new(zone()) ZoneList<Expression*>(4, zone()); | 3752 ZoneList<Expression*>* result = new(zone()) ZoneList<Expression*>(4, zone()); |
| 3753 Expect(Token::LPAREN, CHECK_OK); | 3753 Expect(Token::LPAREN, CHECK_OK); |
| 3754 bool done = (peek() == Token::RPAREN); | 3754 bool done = (peek() == Token::RPAREN); |
| 3755 while (!done) { | 3755 while (!done) { |
| 3756 Expression* argument = ParseAssignmentExpression(true, CHECK_OK); | 3756 Expression* argument = ParseAssignmentExpression(true, CHECK_OK); |
| 3757 result->Add(argument, zone()); | 3757 result->Add(argument, zone()); |
| 3758 if (result->length() > Code::kMaxArguments) { | 3758 if (result->length() > Code::kMaxArguments) { |
| 3759 ReportMessageAt(scanner().location(), "too_many_arguments"); | 3759 ReportMessageAt(scanner()->location(), "too_many_arguments"); |
| 3760 *ok = false; | 3760 *ok = false; |
| 3761 return NULL; | 3761 return NULL; |
| 3762 } | 3762 } |
| 3763 done = (peek() == Token::RPAREN); | 3763 done = (peek() == Token::RPAREN); |
| 3764 if (!done) Expect(Token::COMMA, CHECK_OK); | 3764 if (!done) Expect(Token::COMMA, CHECK_OK); |
| 3765 } | 3765 } |
| 3766 Expect(Token::RPAREN, CHECK_OK); | 3766 Expect(Token::RPAREN, CHECK_OK); |
| 3767 return result; | 3767 return result; |
| 3768 } | 3768 } |
| 3769 | 3769 |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3950 // in a temporary variable, a definition that is used by "yield" | 3950 // in a temporary variable, a definition that is used by "yield" |
| 3951 // expressions. This also marks the FunctionState as a generator. | 3951 // expressions. This also marks the FunctionState as a generator. |
| 3952 Variable* temp = scope_->DeclarationScope()->NewTemporary( | 3952 Variable* temp = scope_->DeclarationScope()->NewTemporary( |
| 3953 isolate()->factory()->dot_generator_object_string()); | 3953 isolate()->factory()->dot_generator_object_string()); |
| 3954 function_state.set_generator_object_variable(temp); | 3954 function_state.set_generator_object_variable(temp); |
| 3955 } | 3955 } |
| 3956 | 3956 |
| 3957 // FormalParameterList :: | 3957 // FormalParameterList :: |
| 3958 // '(' (Identifier)*[','] ')' | 3958 // '(' (Identifier)*[','] ')' |
| 3959 Expect(Token::LPAREN, CHECK_OK); | 3959 Expect(Token::LPAREN, CHECK_OK); |
| 3960 scope->set_start_position(scanner().location().beg_pos); | 3960 scope->set_start_position(scanner()->location().beg_pos); |
| 3961 | 3961 |
| 3962 // We don't yet know if the function will be strict, so we cannot yet | 3962 // We don't yet know if the function will be strict, so we cannot yet |
| 3963 // produce errors for parameter names or duplicates. However, we remember | 3963 // produce errors for parameter names or duplicates. However, we remember |
| 3964 // the locations of these errors if they occur and produce the errors later. | 3964 // the locations of these errors if they occur and produce the errors later. |
| 3965 Scanner::Location eval_args_error_log = Scanner::Location::invalid(); | 3965 Scanner::Location eval_args_error_log = Scanner::Location::invalid(); |
| 3966 Scanner::Location dupe_error_loc = Scanner::Location::invalid(); | 3966 Scanner::Location dupe_error_loc = Scanner::Location::invalid(); |
| 3967 Scanner::Location reserved_loc = Scanner::Location::invalid(); | 3967 Scanner::Location reserved_loc = Scanner::Location::invalid(); |
| 3968 | 3968 |
| 3969 bool done = (peek() == Token::RPAREN); | 3969 bool done = (peek() == Token::RPAREN); |
| 3970 while (!done) { | 3970 while (!done) { |
| 3971 bool is_strict_reserved = false; | 3971 bool is_strict_reserved = false; |
| 3972 Handle<String> param_name = | 3972 Handle<String> param_name = |
| 3973 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); | 3973 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); |
| 3974 | 3974 |
| 3975 // Store locations for possible future error reports. | 3975 // Store locations for possible future error reports. |
| 3976 if (!eval_args_error_log.IsValid() && IsEvalOrArguments(param_name)) { | 3976 if (!eval_args_error_log.IsValid() && IsEvalOrArguments(param_name)) { |
| 3977 eval_args_error_log = scanner().location(); | 3977 eval_args_error_log = scanner()->location(); |
| 3978 } | 3978 } |
| 3979 if (!reserved_loc.IsValid() && is_strict_reserved) { | 3979 if (!reserved_loc.IsValid() && is_strict_reserved) { |
| 3980 reserved_loc = scanner().location(); | 3980 reserved_loc = scanner()->location(); |
| 3981 } | 3981 } |
| 3982 if (!dupe_error_loc.IsValid() && scope_->IsDeclared(param_name)) { | 3982 if (!dupe_error_loc.IsValid() && scope_->IsDeclared(param_name)) { |
| 3983 duplicate_parameters = FunctionLiteral::kHasDuplicateParameters; | 3983 duplicate_parameters = FunctionLiteral::kHasDuplicateParameters; |
| 3984 dupe_error_loc = scanner().location(); | 3984 dupe_error_loc = scanner()->location(); |
| 3985 } | 3985 } |
| 3986 | 3986 |
| 3987 scope_->DeclareParameter(param_name, VAR); | 3987 scope_->DeclareParameter(param_name, VAR); |
| 3988 num_parameters++; | 3988 num_parameters++; |
| 3989 if (num_parameters > Code::kMaxArguments) { | 3989 if (num_parameters > Code::kMaxArguments) { |
| 3990 ReportMessageAt(scanner().location(), "too_many_parameters"); | 3990 ReportMessageAt(scanner()->location(), "too_many_parameters"); |
| 3991 *ok = false; | 3991 *ok = false; |
| 3992 return NULL; | 3992 return NULL; |
| 3993 } | 3993 } |
| 3994 done = (peek() == Token::RPAREN); | 3994 done = (peek() == Token::RPAREN); |
| 3995 if (!done) Expect(Token::COMMA, CHECK_OK); | 3995 if (!done) Expect(Token::COMMA, CHECK_OK); |
| 3996 } | 3996 } |
| 3997 Expect(Token::RPAREN, CHECK_OK); | 3997 Expect(Token::RPAREN, CHECK_OK); |
| 3998 | 3998 |
| 3999 Expect(Token::LBRACE, CHECK_OK); | 3999 Expect(Token::LBRACE, CHECK_OK); |
| 4000 | 4000 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4041 // If we have pre_parse_data_, we use it to skip parsing the function | 4041 // If we have pre_parse_data_, we use it to skip parsing the function |
| 4042 // body. The preparser data contains the information we need to | 4042 // body. The preparser data contains the information we need to |
| 4043 // construct the lazy function. | 4043 // construct the lazy function. |
| 4044 entry = pre_parse_data()->GetFunctionEntry(function_block_pos); | 4044 entry = pre_parse_data()->GetFunctionEntry(function_block_pos); |
| 4045 if (entry.is_valid()) { | 4045 if (entry.is_valid()) { |
| 4046 if (entry.end_pos() <= function_block_pos) { | 4046 if (entry.end_pos() <= function_block_pos) { |
| 4047 // End position greater than end of stream is safe, and hard | 4047 // End position greater than end of stream is safe, and hard |
| 4048 // to check. | 4048 // to check. |
| 4049 ReportInvalidPreparseData(function_name, CHECK_OK); | 4049 ReportInvalidPreparseData(function_name, CHECK_OK); |
| 4050 } | 4050 } |
| 4051 scanner().SeekForward(entry.end_pos() - 1); | 4051 scanner()->SeekForward(entry.end_pos() - 1); |
| 4052 | 4052 |
| 4053 scope->set_end_position(entry.end_pos()); | 4053 scope->set_end_position(entry.end_pos()); |
| 4054 Expect(Token::RBRACE, CHECK_OK); | 4054 Expect(Token::RBRACE, CHECK_OK); |
| 4055 isolate()->counters()->total_preparse_skipped()->Increment( | 4055 isolate()->counters()->total_preparse_skipped()->Increment( |
| 4056 scope->end_position() - function_block_pos); | 4056 scope->end_position() - function_block_pos); |
| 4057 materialized_literal_count = entry.literal_count(); | 4057 materialized_literal_count = entry.literal_count(); |
| 4058 expected_property_count = entry.property_count(); | 4058 expected_property_count = entry.property_count(); |
| 4059 scope_->SetLanguageMode(entry.language_mode()); | 4059 scope_->SetLanguageMode(entry.language_mode()); |
| 4060 } else { | 4060 } else { |
| 4061 is_lazily_compiled = false; | 4061 is_lazily_compiled = false; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4141 get_proxy, undefined, Yield::FINAL, RelocInfo::kNoPosition); | 4141 get_proxy, undefined, Yield::FINAL, RelocInfo::kNoPosition); |
| 4142 body->Add(factory()->NewExpressionStatement( | 4142 body->Add(factory()->NewExpressionStatement( |
| 4143 yield, RelocInfo::kNoPosition), zone()); | 4143 yield, RelocInfo::kNoPosition), zone()); |
| 4144 } | 4144 } |
| 4145 | 4145 |
| 4146 materialized_literal_count = function_state.materialized_literal_count(); | 4146 materialized_literal_count = function_state.materialized_literal_count(); |
| 4147 expected_property_count = function_state.expected_property_count(); | 4147 expected_property_count = function_state.expected_property_count(); |
| 4148 handler_count = function_state.handler_count(); | 4148 handler_count = function_state.handler_count(); |
| 4149 | 4149 |
| 4150 Expect(Token::RBRACE, CHECK_OK); | 4150 Expect(Token::RBRACE, CHECK_OK); |
| 4151 scope->set_end_position(scanner().location().end_pos); | 4151 scope->set_end_position(scanner()->location().end_pos); |
| 4152 } | 4152 } |
| 4153 | 4153 |
| 4154 // Validate strict mode. We can do this only after parsing the function, | 4154 // Validate strict mode. We can do this only after parsing the function, |
| 4155 // since the function can declare itself strict. | 4155 // since the function can declare itself strict. |
| 4156 if (!scope_->is_classic_mode()) { | 4156 if (!scope_->is_classic_mode()) { |
| 4157 if (IsEvalOrArguments(function_name)) { | 4157 if (IsEvalOrArguments(function_name)) { |
| 4158 ReportMessageAt(function_name_location, "strict_eval_arguments"); | 4158 ReportMessageAt(function_name_location, "strict_eval_arguments"); |
| 4159 *ok = false; | 4159 *ok = false; |
| 4160 return NULL; | 4160 return NULL; |
| 4161 } | 4161 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4212 function_literal->set_dont_optimize_reason(dont_optimize_reason); | 4212 function_literal->set_dont_optimize_reason(dont_optimize_reason); |
| 4213 | 4213 |
| 4214 if (fni_ != NULL && should_infer_name) fni_->AddFunction(function_literal); | 4214 if (fni_ != NULL && should_infer_name) fni_->AddFunction(function_literal); |
| 4215 return function_literal; | 4215 return function_literal; |
| 4216 } | 4216 } |
| 4217 | 4217 |
| 4218 | 4218 |
| 4219 PreParser::PreParseResult Parser::LazyParseFunctionLiteral( | 4219 PreParser::PreParseResult Parser::LazyParseFunctionLiteral( |
| 4220 SingletonLogger* logger) { | 4220 SingletonLogger* logger) { |
| 4221 HistogramTimerScope preparse_scope(isolate()->counters()->pre_parse()); | 4221 HistogramTimerScope preparse_scope(isolate()->counters()->pre_parse()); |
| 4222 ASSERT_EQ(Token::LBRACE, scanner().current_token()); | 4222 ASSERT_EQ(Token::LBRACE, scanner()->current_token()); |
| 4223 | 4223 |
| 4224 if (reusable_preparser_ == NULL) { | 4224 if (reusable_preparser_ == NULL) { |
| 4225 intptr_t stack_limit = isolate()->stack_guard()->real_climit(); | 4225 intptr_t stack_limit = isolate()->stack_guard()->real_climit(); |
| 4226 reusable_preparser_ = new PreParser(&scanner_, NULL, stack_limit); | 4226 reusable_preparser_ = new PreParser(&scanner_, NULL, stack_limit); |
| 4227 reusable_preparser_->set_allow_harmony_scoping(allow_harmony_scoping()); | 4227 reusable_preparser_->set_allow_harmony_scoping(allow_harmony_scoping()); |
| 4228 reusable_preparser_->set_allow_modules(allow_modules()); | 4228 reusable_preparser_->set_allow_modules(allow_modules()); |
| 4229 reusable_preparser_->set_allow_natives_syntax(allow_natives_syntax()); | 4229 reusable_preparser_->set_allow_natives_syntax(allow_natives_syntax()); |
| 4230 reusable_preparser_->set_allow_lazy(true); | 4230 reusable_preparser_->set_allow_lazy(true); |
| 4231 reusable_preparser_->set_allow_generators(allow_generators()); | 4231 reusable_preparser_->set_allow_generators(allow_generators()); |
| 4232 reusable_preparser_->set_allow_for_of(allow_for_of()); | 4232 reusable_preparser_->set_allow_for_of(allow_for_of()); |
| (...skipping 1177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5410 ASSERT(info()->isolate()->has_pending_exception()); | 5410 ASSERT(info()->isolate()->has_pending_exception()); |
| 5411 } else { | 5411 } else { |
| 5412 result = ParseProgram(); | 5412 result = ParseProgram(); |
| 5413 } | 5413 } |
| 5414 } | 5414 } |
| 5415 info()->SetFunction(result); | 5415 info()->SetFunction(result); |
| 5416 return (result != NULL); | 5416 return (result != NULL); |
| 5417 } | 5417 } |
| 5418 | 5418 |
| 5419 } } // namespace v8::internal | 5419 } } // namespace v8::internal |
| OLD | NEW |