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/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/bailout-reason.h" | 9 #include "src/bailout-reason.h" |
10 #include "src/base/platform/platform.h" | 10 #include "src/base/platform/platform.h" |
(...skipping 3042 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3053 Expect(Token::LPAREN, CHECK_OK); | 3053 Expect(Token::LPAREN, CHECK_OK); |
3054 Expression* cond = ParseExpression(true, CHECK_OK); | 3054 Expression* cond = ParseExpression(true, CHECK_OK); |
3055 Expect(Token::RPAREN, CHECK_OK); | 3055 Expect(Token::RPAREN, CHECK_OK); |
3056 Statement* body = ParseSubStatement(NULL, CHECK_OK); | 3056 Statement* body = ParseSubStatement(NULL, CHECK_OK); |
3057 | 3057 |
3058 if (loop != NULL) loop->Initialize(cond, body); | 3058 if (loop != NULL) loop->Initialize(cond, body); |
3059 return loop; | 3059 return loop; |
3060 } | 3060 } |
3061 | 3061 |
3062 | 3062 |
| 3063 // !%_IsSpecObject(result = iterator.next()) && |
| 3064 // %ThrowIteratorResultNotAnObject(result) |
| 3065 Expression* Parser::BuildIteratorNextResult(Expression* iterator, |
| 3066 Variable* result, int pos) { |
| 3067 Expression* next_literal = factory()->NewStringLiteral( |
| 3068 ast_value_factory()->next_string(), RelocInfo::kNoPosition); |
| 3069 Expression* next_property = |
| 3070 factory()->NewProperty(iterator, next_literal, RelocInfo::kNoPosition); |
| 3071 ZoneList<Expression*>* next_arguments = |
| 3072 new (zone()) ZoneList<Expression*>(0, zone()); |
| 3073 Expression* next_call = |
| 3074 factory()->NewCall(next_property, next_arguments, pos); |
| 3075 Expression* result_proxy = factory()->NewVariableProxy(result); |
| 3076 Expression* left = |
| 3077 factory()->NewAssignment(Token::ASSIGN, result_proxy, next_call, pos); |
| 3078 |
| 3079 // %_IsSpecObject(...) |
| 3080 ZoneList<Expression*>* is_spec_object_args = |
| 3081 new (zone()) ZoneList<Expression*>(1, zone()); |
| 3082 is_spec_object_args->Add(left, zone()); |
| 3083 Expression* is_spec_object_call = factory()->NewCallRuntime( |
| 3084 ast_value_factory()->is_spec_object_string(), |
| 3085 Runtime::FunctionForId(Runtime::kInlineIsSpecObject), is_spec_object_args, |
| 3086 pos); |
| 3087 |
| 3088 // %ThrowIteratorResultNotAnObject(result) |
| 3089 Expression* result_proxy_again = factory()->NewVariableProxy(result); |
| 3090 ZoneList<Expression*>* throw_arguments = |
| 3091 new (zone()) ZoneList<Expression*>(1, zone()); |
| 3092 throw_arguments->Add(result_proxy_again, zone()); |
| 3093 Expression* throw_call = factory()->NewCallRuntime( |
| 3094 ast_value_factory()->throw_iterator_result_not_an_object_string(), |
| 3095 Runtime::FunctionForId(Runtime::kThrowIteratorResultNotAnObject), |
| 3096 throw_arguments, pos); |
| 3097 |
| 3098 return factory()->NewBinaryOperation( |
| 3099 Token::AND, |
| 3100 factory()->NewUnaryOperation(Token::NOT, is_spec_object_call, pos), |
| 3101 throw_call, pos); |
| 3102 } |
| 3103 |
| 3104 |
3063 void Parser::InitializeForEachStatement(ForEachStatement* stmt, | 3105 void Parser::InitializeForEachStatement(ForEachStatement* stmt, |
3064 Expression* each, | 3106 Expression* each, |
3065 Expression* subject, | 3107 Expression* subject, |
3066 Statement* body) { | 3108 Statement* body) { |
3067 ForOfStatement* for_of = stmt->AsForOfStatement(); | 3109 ForOfStatement* for_of = stmt->AsForOfStatement(); |
3068 | 3110 |
3069 if (for_of != NULL) { | 3111 if (for_of != NULL) { |
3070 Variable* iterator = scope_->DeclarationScope()->NewTemporary( | 3112 Variable* iterator = scope_->DeclarationScope()->NewTemporary( |
3071 ast_value_factory()->dot_iterator_string()); | 3113 ast_value_factory()->dot_iterator_string()); |
3072 Variable* result = scope_->DeclarationScope()->NewTemporary( | 3114 Variable* result = scope_->DeclarationScope()->NewTemporary( |
3073 ast_value_factory()->dot_result_string()); | 3115 ast_value_factory()->dot_result_string()); |
3074 | 3116 |
3075 Expression* assign_iterator; | 3117 Expression* assign_iterator; |
3076 Expression* next_result; | 3118 Expression* next_result; |
3077 Expression* result_done; | 3119 Expression* result_done; |
3078 Expression* assign_each; | 3120 Expression* assign_each; |
3079 | 3121 |
3080 // iterator = subject[Symbol.iterator]() | 3122 // iterator = subject[Symbol.iterator]() |
3081 assign_iterator = factory()->NewAssignment( | 3123 assign_iterator = factory()->NewAssignment( |
3082 Token::ASSIGN, factory()->NewVariableProxy(iterator), | 3124 Token::ASSIGN, factory()->NewVariableProxy(iterator), |
3083 GetIterator(subject, factory()), subject->position()); | 3125 GetIterator(subject, factory()), subject->position()); |
3084 | 3126 |
3085 // !%_IsSpecObject(result = iterator.next()) && | 3127 // !%_IsSpecObject(result = iterator.next()) && |
3086 // %ThrowIteratorResultNotAnObject(result) | 3128 // %ThrowIteratorResultNotAnObject(result) |
3087 { | 3129 { |
3088 // result = iterator.next() | 3130 // result = iterator.next() |
3089 Expression* iterator_proxy = factory()->NewVariableProxy(iterator); | 3131 Expression* iterator_proxy = factory()->NewVariableProxy(iterator); |
3090 Expression* next_literal = factory()->NewStringLiteral( | 3132 next_result = |
3091 ast_value_factory()->next_string(), RelocInfo::kNoPosition); | 3133 BuildIteratorNextResult(iterator_proxy, result, subject->position()); |
3092 Expression* next_property = factory()->NewProperty( | |
3093 iterator_proxy, next_literal, RelocInfo::kNoPosition); | |
3094 ZoneList<Expression*>* next_arguments = | |
3095 new (zone()) ZoneList<Expression*>(0, zone()); | |
3096 Expression* next_call = factory()->NewCall(next_property, next_arguments, | |
3097 subject->position()); | |
3098 Expression* result_proxy = factory()->NewVariableProxy(result); | |
3099 next_result = factory()->NewAssignment(Token::ASSIGN, result_proxy, | |
3100 next_call, subject->position()); | |
3101 | |
3102 // %_IsSpecObject(...) | |
3103 ZoneList<Expression*>* is_spec_object_args = | |
3104 new (zone()) ZoneList<Expression*>(1, zone()); | |
3105 is_spec_object_args->Add(next_result, zone()); | |
3106 Expression* is_spec_object_call = factory()->NewCallRuntime( | |
3107 ast_value_factory()->is_spec_object_string(), | |
3108 Runtime::FunctionForId(Runtime::kInlineIsSpecObject), | |
3109 is_spec_object_args, subject->position()); | |
3110 | |
3111 // %ThrowIteratorResultNotAnObject(result) | |
3112 Expression* result_proxy_again = factory()->NewVariableProxy(result); | |
3113 ZoneList<Expression*>* throw_arguments = | |
3114 new (zone()) ZoneList<Expression*>(1, zone()); | |
3115 throw_arguments->Add(result_proxy_again, zone()); | |
3116 Expression* throw_call = factory()->NewCallRuntime( | |
3117 ast_value_factory()->throw_iterator_result_not_an_object_string(), | |
3118 Runtime::FunctionForId(Runtime::kThrowIteratorResultNotAnObject), | |
3119 throw_arguments, subject->position()); | |
3120 | |
3121 next_result = factory()->NewBinaryOperation( | |
3122 Token::AND, factory()->NewUnaryOperation( | |
3123 Token::NOT, is_spec_object_call, subject->position()), | |
3124 throw_call, subject->position()); | |
3125 } | 3134 } |
3126 | 3135 |
3127 // result.done | 3136 // result.done |
3128 { | 3137 { |
3129 Expression* done_literal = factory()->NewStringLiteral( | 3138 Expression* done_literal = factory()->NewStringLiteral( |
3130 ast_value_factory()->done_string(), RelocInfo::kNoPosition); | 3139 ast_value_factory()->done_string(), RelocInfo::kNoPosition); |
3131 Expression* result_proxy = factory()->NewVariableProxy(result); | 3140 Expression* result_proxy = factory()->NewVariableProxy(result); |
3132 result_done = factory()->NewProperty( | 3141 result_done = factory()->NewProperty( |
3133 result_proxy, done_literal, RelocInfo::kNoPosition); | 3142 result_proxy, done_literal, RelocInfo::kNoPosition); |
3134 } | 3143 } |
(...skipping 2657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5792 | 5801 |
5793 Expression* Parser::SpreadCallNew(Expression* function, | 5802 Expression* Parser::SpreadCallNew(Expression* function, |
5794 ZoneList<v8::internal::Expression*>* args, | 5803 ZoneList<v8::internal::Expression*>* args, |
5795 int pos) { | 5804 int pos) { |
5796 args->InsertAt(0, function, zone()); | 5805 args->InsertAt(0, function, zone()); |
5797 | 5806 |
5798 return factory()->NewCallRuntime( | 5807 return factory()->NewCallRuntime( |
5799 ast_value_factory()->reflect_construct_string(), NULL, args, pos); | 5808 ast_value_factory()->reflect_construct_string(), NULL, args, pos); |
5800 } | 5809 } |
5801 } } // namespace v8::internal | 5810 } } // namespace v8::internal |
OLD | NEW |