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

Unified Diff: src/parser.cc

Issue 1139603005: [destructuring] Implement BindingArrayPattern (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebased + feedback Created 5 years, 7 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/parser.h ('k') | src/pattern-rewriter.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 374b59c7a7e9b4e78707bd57d0ce94ad266e6bdf..9e1d8fdcf3069a4dfbe0645360973f3e34e1f63e 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -3060,6 +3060,48 @@ WhileStatement* Parser::ParseWhileStatement(
}
+// !%_IsSpecObject(result = iterator.next()) &&
+// %ThrowIteratorResultNotAnObject(result)
+Expression* Parser::BuildIteratorNextResult(Expression* iterator,
+ Variable* result, int pos) {
+ Expression* next_literal = factory()->NewStringLiteral(
+ ast_value_factory()->next_string(), RelocInfo::kNoPosition);
+ Expression* next_property =
+ factory()->NewProperty(iterator, next_literal, RelocInfo::kNoPosition);
+ ZoneList<Expression*>* next_arguments =
+ new (zone()) ZoneList<Expression*>(0, zone());
+ Expression* next_call =
+ factory()->NewCall(next_property, next_arguments, pos);
+ Expression* result_proxy = factory()->NewVariableProxy(result);
+ Expression* left =
+ factory()->NewAssignment(Token::ASSIGN, result_proxy, next_call, pos);
+
+ // %_IsSpecObject(...)
+ ZoneList<Expression*>* is_spec_object_args =
+ new (zone()) ZoneList<Expression*>(1, zone());
+ is_spec_object_args->Add(left, zone());
+ Expression* is_spec_object_call = factory()->NewCallRuntime(
+ ast_value_factory()->is_spec_object_string(),
+ Runtime::FunctionForId(Runtime::kInlineIsSpecObject), is_spec_object_args,
+ pos);
+
+ // %ThrowIteratorResultNotAnObject(result)
+ Expression* result_proxy_again = factory()->NewVariableProxy(result);
+ ZoneList<Expression*>* throw_arguments =
+ new (zone()) ZoneList<Expression*>(1, zone());
+ throw_arguments->Add(result_proxy_again, zone());
+ Expression* throw_call = factory()->NewCallRuntime(
+ ast_value_factory()->throw_iterator_result_not_an_object_string(),
+ Runtime::FunctionForId(Runtime::kThrowIteratorResultNotAnObject),
+ throw_arguments, pos);
+
+ return factory()->NewBinaryOperation(
+ Token::AND,
+ factory()->NewUnaryOperation(Token::NOT, is_spec_object_call, pos),
+ throw_call, pos);
+}
+
+
void Parser::InitializeForEachStatement(ForEachStatement* stmt,
Expression* each,
Expression* subject,
@@ -3087,41 +3129,8 @@ void Parser::InitializeForEachStatement(ForEachStatement* stmt,
{
// result = iterator.next()
Expression* iterator_proxy = factory()->NewVariableProxy(iterator);
- Expression* next_literal = factory()->NewStringLiteral(
- ast_value_factory()->next_string(), RelocInfo::kNoPosition);
- Expression* next_property = factory()->NewProperty(
- iterator_proxy, next_literal, RelocInfo::kNoPosition);
- ZoneList<Expression*>* next_arguments =
- new (zone()) ZoneList<Expression*>(0, zone());
- Expression* next_call = factory()->NewCall(next_property, next_arguments,
- subject->position());
- Expression* result_proxy = factory()->NewVariableProxy(result);
- next_result = factory()->NewAssignment(Token::ASSIGN, result_proxy,
- next_call, subject->position());
-
- // %_IsSpecObject(...)
- ZoneList<Expression*>* is_spec_object_args =
- new (zone()) ZoneList<Expression*>(1, zone());
- is_spec_object_args->Add(next_result, zone());
- Expression* is_spec_object_call = factory()->NewCallRuntime(
- ast_value_factory()->is_spec_object_string(),
- Runtime::FunctionForId(Runtime::kInlineIsSpecObject),
- is_spec_object_args, subject->position());
-
- // %ThrowIteratorResultNotAnObject(result)
- Expression* result_proxy_again = factory()->NewVariableProxy(result);
- ZoneList<Expression*>* throw_arguments =
- new (zone()) ZoneList<Expression*>(1, zone());
- throw_arguments->Add(result_proxy_again, zone());
- Expression* throw_call = factory()->NewCallRuntime(
- ast_value_factory()->throw_iterator_result_not_an_object_string(),
- Runtime::FunctionForId(Runtime::kThrowIteratorResultNotAnObject),
- throw_arguments, subject->position());
-
- next_result = factory()->NewBinaryOperation(
- Token::AND, factory()->NewUnaryOperation(
- Token::NOT, is_spec_object_call, subject->position()),
- throw_call, subject->position());
+ next_result =
+ BuildIteratorNextResult(iterator_proxy, result, subject->position());
}
// result.done
« no previous file with comments | « src/parser.h ('k') | src/pattern-rewriter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698