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

Side by Side Diff: src/parser.cc

Issue 416033002: For-of on null or undefined is an error (Closed) Base URL: git://github.com/v8/v8.git@master
Patch Set: Created 6 years, 5 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
« no previous file with comments | « src/mips64/full-codegen-mips64.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/base/platform/platform.h" 9 #include "src/base/platform/platform.h"
10 #include "src/bootstrapper.h" 10 #include "src/bootstrapper.h"
(...skipping 2731 matching lines...) Expand 10 before | Expand all | Expand 10 after
2742 } 2742 }
2743 2743
2744 2744
2745 void Parser::InitializeForEachStatement(ForEachStatement* stmt, 2745 void Parser::InitializeForEachStatement(ForEachStatement* stmt,
2746 Expression* each, 2746 Expression* each,
2747 Expression* subject, 2747 Expression* subject,
2748 Statement* body) { 2748 Statement* body) {
2749 ForOfStatement* for_of = stmt->AsForOfStatement(); 2749 ForOfStatement* for_of = stmt->AsForOfStatement();
2750 2750
2751 if (for_of != NULL) { 2751 if (for_of != NULL) {
2752 Variable* iterable = scope_->DeclarationScope()->NewTemporary(
2753 ast_value_factory_->dot_iterable_string());
2754 Variable* iterator = scope_->DeclarationScope()->NewTemporary( 2752 Variable* iterator = scope_->DeclarationScope()->NewTemporary(
2755 ast_value_factory_->dot_iterator_string()); 2753 ast_value_factory_->dot_iterator_string());
2756 Variable* result = scope_->DeclarationScope()->NewTemporary( 2754 Variable* result = scope_->DeclarationScope()->NewTemporary(
2757 ast_value_factory_->dot_result_string()); 2755 ast_value_factory_->dot_result_string());
2758 2756
2759 Expression* assign_iterable;
2760 Expression* assign_iterator; 2757 Expression* assign_iterator;
2761 Expression* next_result; 2758 Expression* next_result;
2762 Expression* result_done; 2759 Expression* result_done;
2763 Expression* assign_each; 2760 Expression* assign_each;
2764 2761
2765 // var iterable = subject; 2762 // var iterator = subject[Symbol.iterator]();
2766 { 2763 {
2767 Expression* iterable_proxy = factory()->NewVariableProxy(iterable);
2768 assign_iterable = factory()->NewAssignment(
2769 Token::ASSIGN, iterable_proxy, subject, subject->position());
2770 }
2771
2772 // var iterator = iterable[Symbol.iterator]();
2773 {
2774 Expression* iterable_proxy = factory()->NewVariableProxy(iterable);
2775 Expression* iterator_symbol_literal = 2764 Expression* iterator_symbol_literal =
2776 factory()->NewSymbolLiteral("symbolIterator", RelocInfo::kNoPosition); 2765 factory()->NewSymbolLiteral("symbolIterator", RelocInfo::kNoPosition);
2777 // FIXME(wingo): Unhappily, it will be a common error that the RHS of a 2766 // FIXME(wingo): Unhappily, it will be a common error that the RHS of a
2778 // for-of doesn't have a Symbol.iterator property. We should do better 2767 // for-of doesn't have a Symbol.iterator property. We should do better
2779 // than informing the user that "undefined is not a function". 2768 // than informing the user that "undefined is not a function".
2780 int pos = subject->position(); 2769 int pos = subject->position();
2781 Expression* iterator_property = factory()->NewProperty( 2770 Expression* iterator_property =
2782 iterable_proxy, iterator_symbol_literal, pos); 2771 factory()->NewProperty(subject, iterator_symbol_literal, pos);
2783 ZoneList<Expression*>* iterator_arguments = 2772 ZoneList<Expression*>* iterator_arguments =
2784 new(zone()) ZoneList<Expression*>(0, zone()); 2773 new(zone()) ZoneList<Expression*>(0, zone());
2785 Expression* iterator_call = factory()->NewCall( 2774 Expression* iterator_call = factory()->NewCall(
2786 iterator_property, iterator_arguments, pos); 2775 iterator_property, iterator_arguments, pos);
2787 Expression* iterator_proxy = factory()->NewVariableProxy(iterator); 2776 Expression* iterator_proxy = factory()->NewVariableProxy(iterator);
2788 assign_iterator = factory()->NewAssignment( 2777 assign_iterator = factory()->NewAssignment(
2789 Token::ASSIGN, iterator_proxy, iterator_call, RelocInfo::kNoPosition); 2778 Token::ASSIGN, iterator_proxy, iterator_call, RelocInfo::kNoPosition);
2790 } 2779 }
2791 2780
2792 // var result = iterator.next(); 2781 // var result = iterator.next();
(...skipping 26 matching lines...) Expand all
2819 Expression* value_literal = factory()->NewStringLiteral( 2808 Expression* value_literal = factory()->NewStringLiteral(
2820 ast_value_factory_->value_string(), RelocInfo::kNoPosition); 2809 ast_value_factory_->value_string(), RelocInfo::kNoPosition);
2821 Expression* result_proxy = factory()->NewVariableProxy(result); 2810 Expression* result_proxy = factory()->NewVariableProxy(result);
2822 Expression* result_value = factory()->NewProperty( 2811 Expression* result_value = factory()->NewProperty(
2823 result_proxy, value_literal, RelocInfo::kNoPosition); 2812 result_proxy, value_literal, RelocInfo::kNoPosition);
2824 assign_each = factory()->NewAssignment( 2813 assign_each = factory()->NewAssignment(
2825 Token::ASSIGN, each, result_value, RelocInfo::kNoPosition); 2814 Token::ASSIGN, each, result_value, RelocInfo::kNoPosition);
2826 } 2815 }
2827 2816
2828 for_of->Initialize(each, subject, body, 2817 for_of->Initialize(each, subject, body,
2829 assign_iterable,
2830 assign_iterator, 2818 assign_iterator,
2831 next_result, 2819 next_result,
2832 result_done, 2820 result_done,
2833 assign_each); 2821 assign_each);
2834 } else { 2822 } else {
2835 stmt->Initialize(each, subject, body); 2823 stmt->Initialize(each, subject, body);
2836 } 2824 }
2837 } 2825 }
2838 2826
2839 2827
(...skipping 1957 matching lines...) Expand 10 before | Expand all | Expand 10 after
4797 info()->SetAstValueFactory(ast_value_factory_); 4785 info()->SetAstValueFactory(ast_value_factory_);
4798 } 4786 }
4799 ast_value_factory_ = NULL; 4787 ast_value_factory_ = NULL;
4800 4788
4801 InternalizeUseCounts(); 4789 InternalizeUseCounts();
4802 4790
4803 return (result != NULL); 4791 return (result != NULL);
4804 } 4792 }
4805 4793
4806 } } // namespace v8::internal 4794 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/mips64/full-codegen-mips64.cc ('k') | src/x64/full-codegen-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698