| 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/parsing/parser.h" | 5 #include "src/parsing/parser.h" |
| 6 | 6 |
| 7 #include "src/api.h" | 7 #include "src/api.h" |
| 8 #include "src/ast/ast.h" | 8 #include "src/ast/ast.h" |
| 9 #include "src/ast/ast-expression-rewriter.h" | 9 #include "src/ast/ast-expression-rewriter.h" |
| 10 #include "src/ast/ast-expression-visitor.h" | 10 #include "src/ast/ast-expression-visitor.h" |
| (...skipping 6085 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6096 // | 6096 // |
| 6097 // do { | 6097 // do { |
| 6098 // let O = lhs; | 6098 // let O = lhs; |
| 6099 // let C = rhs; | 6099 // let C = rhs; |
| 6100 // if (!IS_RECEIVER(C)) throw MakeTypeError(kNonObjectInInstanceOfCheck); | 6100 // if (!IS_RECEIVER(C)) throw MakeTypeError(kNonObjectInInstanceOfCheck); |
| 6101 // let handler_result = C[Symbol.hasInstance]; | 6101 // let handler_result = C[Symbol.hasInstance]; |
| 6102 // if (handler_result === undefined) { | 6102 // if (handler_result === undefined) { |
| 6103 // if (!IS_CALLABLE(C)) { | 6103 // if (!IS_CALLABLE(C)) { |
| 6104 // throw MakeTypeError(kCalledNonCallableInstanceOf); | 6104 // throw MakeTypeError(kCalledNonCallableInstanceOf); |
| 6105 // } | 6105 // } |
| 6106 // handler_result = %ordinary_has_instance(C, O); | 6106 // handler_result = %_GetOrdinaryHasInstance() |
| 6107 // handler_result = %_Call(handler_result, C, O); |
| 6107 // } else { | 6108 // } else { |
| 6108 // handler_result = !!(%_Call(handler_result, C, O)); | 6109 // handler_result = !!(%_Call(handler_result, C, O)); |
| 6109 // } | 6110 // } |
| 6110 // handler_result; | 6111 // handler_result; |
| 6111 // } | 6112 // } |
| 6112 // | 6113 // |
| 6113 Expression* ParserTraits::RewriteInstanceof(Expression* lhs, Expression* rhs, | 6114 Expression* ParserTraits::RewriteInstanceof(Expression* lhs, Expression* rhs, |
| 6114 int pos) { | 6115 int pos) { |
| 6115 const int nopos = RelocInfo::kNoPosition; | 6116 const int nopos = RelocInfo::kNoPosition; |
| 6116 | 6117 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 6141 | 6142 |
| 6142 // if (!IS_RECEIVER(C)) throw MakeTypeError(kNonObjectInInstanceOfCheck); | 6143 // if (!IS_RECEIVER(C)) throw MakeTypeError(kNonObjectInInstanceOfCheck); |
| 6143 Statement* validate_C; | 6144 Statement* validate_C; |
| 6144 { | 6145 { |
| 6145 auto args = new (zone) ZoneList<Expression*>(1, zone); | 6146 auto args = new (zone) ZoneList<Expression*>(1, zone); |
| 6146 args->Add(factory->NewVariableProxy(var_C), zone); | 6147 args->Add(factory->NewVariableProxy(var_C), zone); |
| 6147 Expression* is_receiver_call = | 6148 Expression* is_receiver_call = |
| 6148 factory->NewCallRuntime(Runtime::kInlineIsJSReceiver, args, nopos); | 6149 factory->NewCallRuntime(Runtime::kInlineIsJSReceiver, args, nopos); |
| 6149 Expression* call = | 6150 Expression* call = |
| 6150 NewThrowTypeError(MessageTemplate::kNonObjectInInstanceOfCheck, | 6151 NewThrowTypeError(MessageTemplate::kNonObjectInInstanceOfCheck, |
| 6151 avfactory->empty_string(), nopos); | 6152 avfactory->empty_string(), pos); |
| 6152 Statement* throw_call = factory->NewExpressionStatement(call, nopos); | 6153 Statement* throw_call = factory->NewExpressionStatement(call, nopos); |
| 6153 | 6154 |
| 6154 validate_C = | 6155 validate_C = |
| 6155 factory->NewIfStatement(is_receiver_call, | 6156 factory->NewIfStatement(is_receiver_call, |
| 6156 factory->NewEmptyStatement(nopos), | 6157 factory->NewEmptyStatement(nopos), |
| 6157 throw_call, | 6158 throw_call, |
| 6158 nopos); | 6159 nopos); |
| 6159 } | 6160 } |
| 6160 | 6161 |
| 6161 // let handler_result = C[Symbol.hasInstance]; | 6162 // let handler_result = C[Symbol.hasInstance]; |
| 6162 Variable* var_handler_result = scope->NewTemporary(avfactory->empty_string()); | 6163 Variable* var_handler_result = scope->NewTemporary(avfactory->empty_string()); |
| 6163 Statement* initialize_handler; | 6164 Statement* initialize_handler; |
| 6164 { | 6165 { |
| 6165 Expression* hasInstance_symbol_literal = | 6166 Expression* hasInstance_symbol_literal = |
| 6166 factory->NewSymbolLiteral("hasInstance_symbol", RelocInfo::kNoPosition); | 6167 factory->NewSymbolLiteral("hasInstance_symbol", RelocInfo::kNoPosition); |
| 6167 Expression* prop = factory->NewProperty(factory->NewVariableProxy(var_C), | 6168 Expression* prop = factory->NewProperty(factory->NewVariableProxy(var_C), |
| 6168 hasInstance_symbol_literal, pos); | 6169 hasInstance_symbol_literal, pos); |
| 6169 Expression* handler_proxy = factory->NewVariableProxy(var_handler_result); | 6170 Expression* handler_proxy = factory->NewVariableProxy(var_handler_result); |
| 6170 Expression* assignment = | 6171 Expression* assignment = |
| 6171 factory->NewAssignment(Token::ASSIGN, handler_proxy, prop, nopos); | 6172 factory->NewAssignment(Token::ASSIGN, handler_proxy, prop, nopos); |
| 6172 initialize_handler = factory->NewExpressionStatement(assignment, nopos); | 6173 initialize_handler = factory->NewExpressionStatement(assignment, nopos); |
| 6173 } | 6174 } |
| 6174 | 6175 |
| 6175 // if (handler_result === undefined) { | 6176 // if (handler_result === undefined) { |
| 6176 // if (!IS_CALLABLE(C)) { | 6177 // if (!IS_CALLABLE(C)) { |
| 6177 // throw MakeTypeError(kCalledNonCallableInstanceOf); | 6178 // throw MakeTypeError(kCalledNonCallableInstanceOf); |
| 6178 // } | 6179 // } |
| 6179 // result = %ordinary_has_instance(C, O); | 6180 // handler_result = %_GetOrdinaryHasInstance() |
| 6181 // handler_result = %_Call(handler_result, C, O); |
| 6180 // } else { | 6182 // } else { |
| 6181 // handler_result = !!%_Call(handler_result, C, O); | 6183 // handler_result = !!%_Call(handler_result, C, O); |
| 6182 // } | 6184 // } |
| 6183 Statement* call_handler; | 6185 Statement* call_handler; |
| 6184 { | 6186 { |
| 6185 Expression* condition = factory->NewCompareOperation( | 6187 Expression* condition = factory->NewCompareOperation( |
| 6186 Token::EQ_STRICT, factory->NewVariableProxy(var_handler_result), | 6188 Token::EQ_STRICT, factory->NewVariableProxy(var_handler_result), |
| 6187 factory->NewUndefinedLiteral(nopos), nopos); | 6189 factory->NewUndefinedLiteral(nopos), nopos); |
| 6188 | 6190 |
| 6189 Block* then_side = factory->NewBlock(nullptr, 2, false, nopos); | 6191 Block* then_side = factory->NewBlock(nullptr, 3, false, nopos); |
| 6190 { | 6192 { |
| 6191 Expression* throw_expr = | 6193 Expression* throw_expr = |
| 6192 NewThrowTypeError(MessageTemplate::kCalledNonCallableInstanceOf, | 6194 NewThrowTypeError(MessageTemplate::kCalledNonCallableInstanceOf, |
| 6193 avfactory->empty_string(), nopos); | 6195 avfactory->empty_string(), pos); |
| 6194 Statement* validate_C = CheckCallable(var_C, throw_expr); | 6196 Statement* validate_C = CheckCallable(var_C, throw_expr); |
| 6195 ZoneList<Expression*>* args = new (zone) ZoneList<Expression*>(2, zone); | 6197 |
| 6198 ZoneList<Expression*>* empty_args = |
| 6199 new (zone) ZoneList<Expression*>(0, zone); |
| 6200 Expression* ordinary_has_instance = factory->NewCallRuntime( |
| 6201 Runtime::kInlineGetOrdinaryHasInstance, empty_args, pos); |
| 6202 Expression* handler_proxy = factory->NewVariableProxy(var_handler_result); |
| 6203 Expression* assignment_handler = factory->NewAssignment( |
| 6204 Token::ASSIGN, handler_proxy, ordinary_has_instance, nopos); |
| 6205 Statement* assignment_get_handler = |
| 6206 factory->NewExpressionStatement(assignment_handler, nopos); |
| 6207 |
| 6208 ZoneList<Expression*>* args = new (zone) ZoneList<Expression*>(3, zone); |
| 6209 args->Add(factory->NewVariableProxy(var_handler_result), zone); |
| 6196 args->Add(factory->NewVariableProxy(var_C), zone); | 6210 args->Add(factory->NewVariableProxy(var_C), zone); |
| 6197 args->Add(factory->NewVariableProxy(var_O), zone); | 6211 args->Add(factory->NewVariableProxy(var_O), zone); |
| 6198 CallRuntime* call = factory->NewCallRuntime( | 6212 Expression* call = |
| 6199 Context::ORDINARY_HAS_INSTANCE_INDEX, args, pos); | 6213 factory->NewCallRuntime(Runtime::kInlineCall, args, pos); |
| 6200 Expression* result_proxy = factory->NewVariableProxy(var_handler_result); | 6214 Expression* result_proxy = factory->NewVariableProxy(var_handler_result); |
| 6201 Expression* assignment = | 6215 Expression* assignment = |
| 6202 factory->NewAssignment(Token::ASSIGN, result_proxy, call, nopos); | 6216 factory->NewAssignment(Token::ASSIGN, result_proxy, call, nopos); |
| 6203 Statement* assignment_return = | 6217 Statement* assignment_return = |
| 6204 factory->NewExpressionStatement(assignment, nopos); | 6218 factory->NewExpressionStatement(assignment, nopos); |
| 6205 | 6219 |
| 6206 then_side->statements()->Add(validate_C, zone); | 6220 then_side->statements()->Add(validate_C, zone); |
| 6221 then_side->statements()->Add(assignment_get_handler, zone); |
| 6207 then_side->statements()->Add(assignment_return, zone); | 6222 then_side->statements()->Add(assignment_return, zone); |
| 6208 } | 6223 } |
| 6209 | 6224 |
| 6210 Statement* else_side; | 6225 Statement* else_side; |
| 6211 { | 6226 { |
| 6212 auto args = new (zone) ZoneList<Expression*>(3, zone); | 6227 auto args = new (zone) ZoneList<Expression*>(3, zone); |
| 6213 args->Add(factory->NewVariableProxy(var_handler_result), zone); | 6228 args->Add(factory->NewVariableProxy(var_handler_result), zone); |
| 6214 args->Add(factory->NewVariableProxy(var_C), zone); | 6229 args->Add(factory->NewVariableProxy(var_C), zone); |
| 6215 args->Add(factory->NewVariableProxy(var_O), zone); | 6230 args->Add(factory->NewVariableProxy(var_O), zone); |
| 6216 Expression* call = | 6231 Expression* call = |
| (...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6782 try_block, target); | 6797 try_block, target); |
| 6783 final_loop = target; | 6798 final_loop = target; |
| 6784 } | 6799 } |
| 6785 | 6800 |
| 6786 return final_loop; | 6801 return final_loop; |
| 6787 } | 6802 } |
| 6788 | 6803 |
| 6789 | 6804 |
| 6790 } // namespace internal | 6805 } // namespace internal |
| 6791 } // namespace v8 | 6806 } // namespace v8 |
| OLD | NEW |