| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/parsing/parser.h" | 5 #include "src/parsing/parser.h" |
| 6 | 6 |
| 7 #include "src/api.h" | 7 #include "src/api.h" |
| 8 #include "src/ast/ast.h" | 8 #include "src/ast/ast.h" |
| 9 #include "src/ast/ast-literal-reindexer.h" | 9 #include "src/ast/ast-literal-reindexer.h" |
| 10 #include "src/ast/scopeinfo.h" | 10 #include "src/ast/scopeinfo.h" |
| (...skipping 834 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 845 | 845 |
| 846 Expression* ParserTraits::ExpressionFromString(int pos, Scanner* scanner, | 846 Expression* ParserTraits::ExpressionFromString(int pos, Scanner* scanner, |
| 847 AstNodeFactory* factory) { | 847 AstNodeFactory* factory) { |
| 848 const AstRawString* symbol = GetSymbol(scanner); | 848 const AstRawString* symbol = GetSymbol(scanner); |
| 849 if (parser_->fni_ != NULL) parser_->fni_->PushLiteralName(symbol); | 849 if (parser_->fni_ != NULL) parser_->fni_->PushLiteralName(symbol); |
| 850 return factory->NewStringLiteral(symbol, pos); | 850 return factory->NewStringLiteral(symbol, pos); |
| 851 } | 851 } |
| 852 | 852 |
| 853 | 853 |
| 854 Expression* ParserTraits::GetIterator(Expression* iterable, | 854 Expression* ParserTraits::GetIterator(Expression* iterable, |
| 855 AstNodeFactory* factory) { | 855 AstNodeFactory* factory, int pos) { |
| 856 Expression* iterator_symbol_literal = | 856 Expression* iterator_symbol_literal = |
| 857 factory->NewSymbolLiteral("iterator_symbol", RelocInfo::kNoPosition); | 857 factory->NewSymbolLiteral("iterator_symbol", RelocInfo::kNoPosition); |
| 858 int pos = iterable->position(); | |
| 859 Expression* prop = | 858 Expression* prop = |
| 860 factory->NewProperty(iterable, iterator_symbol_literal, pos); | 859 factory->NewProperty(iterable, iterator_symbol_literal, pos); |
| 861 Zone* zone = parser_->zone(); | 860 Zone* zone = parser_->zone(); |
| 862 ZoneList<Expression*>* args = new (zone) ZoneList<Expression*>(0, zone); | 861 ZoneList<Expression*>* args = new (zone) ZoneList<Expression*>(0, zone); |
| 863 return factory->NewCall(prop, args, pos); | 862 return factory->NewCall(prop, args, pos); |
| 864 } | 863 } |
| 865 | 864 |
| 866 | 865 |
| 867 Literal* ParserTraits::GetLiteralTheHole(int position, | 866 Literal* ParserTraits::GetLiteralTheHole(int position, |
| 868 AstNodeFactory* factory) { | 867 AstNodeFactory* factory) { |
| (...skipping 2463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3332 ast_value_factory()->dot_iterator_string()); | 3331 ast_value_factory()->dot_iterator_string()); |
| 3333 Variable* result = scope_->NewTemporary( | 3332 Variable* result = scope_->NewTemporary( |
| 3334 ast_value_factory()->dot_result_string()); | 3333 ast_value_factory()->dot_result_string()); |
| 3335 | 3334 |
| 3336 Expression* assign_iterator; | 3335 Expression* assign_iterator; |
| 3337 Expression* next_result; | 3336 Expression* next_result; |
| 3338 Expression* result_done; | 3337 Expression* result_done; |
| 3339 Expression* assign_each; | 3338 Expression* assign_each; |
| 3340 | 3339 |
| 3341 // iterator = subject[Symbol.iterator]() | 3340 // iterator = subject[Symbol.iterator]() |
| 3341 // Hackily disambiguate o from o.next and o [Symbol.iterator](). |
| 3342 // TODO(verwaest): Come up with a better solution. |
| 3342 assign_iterator = factory()->NewAssignment( | 3343 assign_iterator = factory()->NewAssignment( |
| 3343 Token::ASSIGN, factory()->NewVariableProxy(iterator), | 3344 Token::ASSIGN, factory()->NewVariableProxy(iterator), |
| 3344 GetIterator(subject, factory()), subject->position()); | 3345 GetIterator(subject, factory(), subject->position() - 2), |
| 3346 subject->position()); |
| 3345 | 3347 |
| 3346 // !%_IsJSReceiver(result = iterator.next()) && | 3348 // !%_IsJSReceiver(result = iterator.next()) && |
| 3347 // %ThrowIteratorResultNotAnObject(result) | 3349 // %ThrowIteratorResultNotAnObject(result) |
| 3348 { | 3350 { |
| 3349 // result = iterator.next() | 3351 // result = iterator.next() |
| 3350 Expression* iterator_proxy = factory()->NewVariableProxy(iterator); | 3352 Expression* iterator_proxy = factory()->NewVariableProxy(iterator); |
| 3351 next_result = | 3353 // Hackily disambiguate o from o.next and o [Symbol.iterator](). |
| 3352 BuildIteratorNextResult(iterator_proxy, result, subject->position()); | 3354 // TODO(verwaest): Come up with a better solution. |
| 3355 next_result = BuildIteratorNextResult(iterator_proxy, result, |
| 3356 subject->position() - 1); |
| 3353 } | 3357 } |
| 3354 | 3358 |
| 3355 // result.done | 3359 // result.done |
| 3356 { | 3360 { |
| 3357 Expression* done_literal = factory()->NewStringLiteral( | 3361 Expression* done_literal = factory()->NewStringLiteral( |
| 3358 ast_value_factory()->done_string(), RelocInfo::kNoPosition); | 3362 ast_value_factory()->done_string(), RelocInfo::kNoPosition); |
| 3359 Expression* result_proxy = factory()->NewVariableProxy(result); | 3363 Expression* result_proxy = factory()->NewVariableProxy(result); |
| 3360 result_done = factory()->NewProperty( | 3364 result_done = factory()->NewProperty( |
| 3361 result_proxy, done_literal, RelocInfo::kNoPosition); | 3365 result_proxy, done_literal, RelocInfo::kNoPosition); |
| 3362 } | 3366 } |
| (...skipping 3094 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6457 } | 6461 } |
| 6458 | 6462 |
| 6459 | 6463 |
| 6460 void Parser::RaiseLanguageMode(LanguageMode mode) { | 6464 void Parser::RaiseLanguageMode(LanguageMode mode) { |
| 6461 SetLanguageMode(scope_, | 6465 SetLanguageMode(scope_, |
| 6462 static_cast<LanguageMode>(scope_->language_mode() | mode)); | 6466 static_cast<LanguageMode>(scope_->language_mode() | mode)); |
| 6463 } | 6467 } |
| 6464 | 6468 |
| 6465 } // namespace internal | 6469 } // namespace internal |
| 6466 } // namespace v8 | 6470 } // namespace v8 |
| OLD | NEW |