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

Unified Diff: src/parser.cc

Issue 332663004: For-of calls [Symbol.iterator]() on RHS to get iterator (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/mips/full-codegen-mips.cc ('k') | src/x64/full-codegen-x64.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index 51065568bac7855a841c4fc724ba1d60d5e633a1..9bca3d552401b93770765c2c0bcc390655050715 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -2778,21 +2778,46 @@ void Parser::InitializeForEachStatement(ForEachStatement* stmt,
if (for_of != NULL) {
Factory* heap_factory = isolate()->factory();
+ Variable* iterable = scope_->DeclarationScope()->NewTemporary(
+ heap_factory->dot_iterable_string());
Variable* iterator = scope_->DeclarationScope()->NewTemporary(
heap_factory->dot_iterator_string());
Variable* result = scope_->DeclarationScope()->NewTemporary(
heap_factory->dot_result_string());
+ Expression* assign_iterable;
Expression* assign_iterator;
Expression* next_result;
Expression* result_done;
Expression* assign_each;
- // var iterator = iterable;
+ // var iterable = subject;
{
+ Expression* iterable_proxy = factory()->NewVariableProxy(iterable);
+ assign_iterable = factory()->NewAssignment(
+ Token::ASSIGN, iterable_proxy, subject, subject->position());
+ }
+
+ // var iterator = iterable[Symbol.iterator]();
+ {
+ Expression* iterable_proxy = factory()->NewVariableProxy(iterable);
+ Handle<Symbol> iterator_symbol(
+ isolate()->native_context()->iterator_symbol(), isolate());
+ Expression* iterator_symbol_literal = factory()->NewLiteral(
+ iterator_symbol, RelocInfo::kNoPosition);
+ // FIXME(wingo): Unhappily, it will be a common error that the RHS of a
+ // for-of doesn't have a Symbol.iterator property. We should do better
+ // than informing the user that "undefined is not a function".
+ int pos = subject->position();
+ Expression* iterator_property = factory()->NewProperty(
+ iterable_proxy, iterator_symbol_literal, pos);
+ ZoneList<Expression*>* iterator_arguments =
+ new(zone()) ZoneList<Expression*>(0, zone());
+ Expression* iterator_call = factory()->NewCall(
+ iterator_property, iterator_arguments, pos);
Expression* iterator_proxy = factory()->NewVariableProxy(iterator);
assign_iterator = factory()->NewAssignment(
- Token::ASSIGN, iterator_proxy, subject, RelocInfo::kNoPosition);
+ Token::ASSIGN, iterator_proxy, iterator_call, RelocInfo::kNoPosition);
}
// var result = iterator.next();
@@ -2832,7 +2857,11 @@ void Parser::InitializeForEachStatement(ForEachStatement* stmt,
}
for_of->Initialize(each, subject, body,
- assign_iterator, next_result, result_done, assign_each);
+ assign_iterable,
+ assign_iterator,
+ next_result,
+ result_done,
+ assign_each);
} else {
stmt->Initialize(each, subject, body);
}
« no previous file with comments | « src/mips/full-codegen-mips.cc ('k') | src/x64/full-codegen-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698