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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/mips/full-codegen-mips.cc ('k') | src/x64/full-codegen-x64.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 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/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/ast.h" 8 #include "src/ast.h"
9 #include "src/bootstrapper.h" 9 #include "src/bootstrapper.h"
10 #include "src/char-predicates-inl.h" 10 #include "src/char-predicates-inl.h"
(...skipping 2760 matching lines...) Expand 10 before | Expand all | Expand 10 after
2771 2771
2772 2772
2773 void Parser::InitializeForEachStatement(ForEachStatement* stmt, 2773 void Parser::InitializeForEachStatement(ForEachStatement* stmt,
2774 Expression* each, 2774 Expression* each,
2775 Expression* subject, 2775 Expression* subject,
2776 Statement* body) { 2776 Statement* body) {
2777 ForOfStatement* for_of = stmt->AsForOfStatement(); 2777 ForOfStatement* for_of = stmt->AsForOfStatement();
2778 2778
2779 if (for_of != NULL) { 2779 if (for_of != NULL) {
2780 Factory* heap_factory = isolate()->factory(); 2780 Factory* heap_factory = isolate()->factory();
2781 Variable* iterable = scope_->DeclarationScope()->NewTemporary(
2782 heap_factory->dot_iterable_string());
2781 Variable* iterator = scope_->DeclarationScope()->NewTemporary( 2783 Variable* iterator = scope_->DeclarationScope()->NewTemporary(
2782 heap_factory->dot_iterator_string()); 2784 heap_factory->dot_iterator_string());
2783 Variable* result = scope_->DeclarationScope()->NewTemporary( 2785 Variable* result = scope_->DeclarationScope()->NewTemporary(
2784 heap_factory->dot_result_string()); 2786 heap_factory->dot_result_string());
2785 2787
2788 Expression* assign_iterable;
2786 Expression* assign_iterator; 2789 Expression* assign_iterator;
2787 Expression* next_result; 2790 Expression* next_result;
2788 Expression* result_done; 2791 Expression* result_done;
2789 Expression* assign_each; 2792 Expression* assign_each;
2790 2793
2791 // var iterator = iterable; 2794 // var iterable = subject;
2792 { 2795 {
2796 Expression* iterable_proxy = factory()->NewVariableProxy(iterable);
2797 assign_iterable = factory()->NewAssignment(
2798 Token::ASSIGN, iterable_proxy, subject, subject->position());
2799 }
2800
2801 // var iterator = iterable[Symbol.iterator]();
2802 {
2803 Expression* iterable_proxy = factory()->NewVariableProxy(iterable);
2804 Handle<Symbol> iterator_symbol(
2805 isolate()->native_context()->iterator_symbol(), isolate());
2806 Expression* iterator_symbol_literal = factory()->NewLiteral(
2807 iterator_symbol, RelocInfo::kNoPosition);
2808 // FIXME(wingo): Unhappily, it will be a common error that the RHS of a
2809 // for-of doesn't have a Symbol.iterator property. We should do better
2810 // than informing the user that "undefined is not a function".
2811 int pos = subject->position();
2812 Expression* iterator_property = factory()->NewProperty(
2813 iterable_proxy, iterator_symbol_literal, pos);
2814 ZoneList<Expression*>* iterator_arguments =
2815 new(zone()) ZoneList<Expression*>(0, zone());
2816 Expression* iterator_call = factory()->NewCall(
2817 iterator_property, iterator_arguments, pos);
2793 Expression* iterator_proxy = factory()->NewVariableProxy(iterator); 2818 Expression* iterator_proxy = factory()->NewVariableProxy(iterator);
2794 assign_iterator = factory()->NewAssignment( 2819 assign_iterator = factory()->NewAssignment(
2795 Token::ASSIGN, iterator_proxy, subject, RelocInfo::kNoPosition); 2820 Token::ASSIGN, iterator_proxy, iterator_call, RelocInfo::kNoPosition);
2796 } 2821 }
2797 2822
2798 // var result = iterator.next(); 2823 // var result = iterator.next();
2799 { 2824 {
2800 Expression* iterator_proxy = factory()->NewVariableProxy(iterator); 2825 Expression* iterator_proxy = factory()->NewVariableProxy(iterator);
2801 Expression* next_literal = factory()->NewLiteral( 2826 Expression* next_literal = factory()->NewLiteral(
2802 heap_factory->next_string(), RelocInfo::kNoPosition); 2827 heap_factory->next_string(), RelocInfo::kNoPosition);
2803 Expression* next_property = factory()->NewProperty( 2828 Expression* next_property = factory()->NewProperty(
2804 iterator_proxy, next_literal, RelocInfo::kNoPosition); 2829 iterator_proxy, next_literal, RelocInfo::kNoPosition);
2805 ZoneList<Expression*>* next_arguments = 2830 ZoneList<Expression*>* next_arguments =
(...skipping 19 matching lines...) Expand all
2825 Expression* value_literal = factory()->NewLiteral( 2850 Expression* value_literal = factory()->NewLiteral(
2826 heap_factory->value_string(), RelocInfo::kNoPosition); 2851 heap_factory->value_string(), RelocInfo::kNoPosition);
2827 Expression* result_proxy = factory()->NewVariableProxy(result); 2852 Expression* result_proxy = factory()->NewVariableProxy(result);
2828 Expression* result_value = factory()->NewProperty( 2853 Expression* result_value = factory()->NewProperty(
2829 result_proxy, value_literal, RelocInfo::kNoPosition); 2854 result_proxy, value_literal, RelocInfo::kNoPosition);
2830 assign_each = factory()->NewAssignment( 2855 assign_each = factory()->NewAssignment(
2831 Token::ASSIGN, each, result_value, RelocInfo::kNoPosition); 2856 Token::ASSIGN, each, result_value, RelocInfo::kNoPosition);
2832 } 2857 }
2833 2858
2834 for_of->Initialize(each, subject, body, 2859 for_of->Initialize(each, subject, body,
2835 assign_iterator, next_result, result_done, assign_each); 2860 assign_iterable,
2861 assign_iterator,
2862 next_result,
2863 result_done,
2864 assign_each);
2836 } else { 2865 } else {
2837 stmt->Initialize(each, subject, body); 2866 stmt->Initialize(each, subject, body);
2838 } 2867 }
2839 } 2868 }
2840 2869
2841 2870
2842 Statement* Parser::DesugarLetBindingsInForStatement( 2871 Statement* Parser::DesugarLetBindingsInForStatement(
2843 Scope* inner_scope, ZoneStringList* names, ForStatement* loop, 2872 Scope* inner_scope, ZoneStringList* names, ForStatement* loop,
2844 Statement* init, Expression* cond, Statement* next, Statement* body, 2873 Statement* init, Expression* cond, Statement* next, Statement* body,
2845 bool* ok) { 2874 bool* ok) {
(...skipping 1937 matching lines...) Expand 10 before | Expand all | Expand 10 after
4783 ASSERT(info()->isolate()->has_pending_exception()); 4812 ASSERT(info()->isolate()->has_pending_exception());
4784 } else { 4813 } else {
4785 result = ParseProgram(); 4814 result = ParseProgram();
4786 } 4815 }
4787 } 4816 }
4788 info()->SetFunction(result); 4817 info()->SetFunction(result);
4789 return (result != NULL); 4818 return (result != NULL);
4790 } 4819 }
4791 4820
4792 } } // namespace v8::internal 4821 } } // namespace v8::internal
OLDNEW
« 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