| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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/ic/call-optimization.h" | 7 #include "src/ic/call-optimization.h" |
| 8 | 8 |
| 9 | 9 |
| 10 namespace v8 { | 10 namespace v8 { |
| 11 namespace internal { | 11 namespace internal { |
| 12 | 12 |
| 13 CallOptimization::CallOptimization(Handle<JSFunction> function) { | 13 CallOptimization::CallOptimization(Handle<JSFunction> function) { |
| 14 Initialize(function); | 14 Initialize(function); |
| 15 } | 15 } |
| 16 | 16 |
| 17 | 17 |
| 18 Handle<JSObject> CallOptimization::LookupHolderOfExpectedType( | 18 Handle<JSObject> CallOptimization::LookupHolderOfExpectedType( |
| 19 Handle<Map> object_map, HolderLookup* holder_lookup) const { | 19 Handle<Map> object_map, HolderLookup* holder_lookup, |
| 20 int* holder_depth_in_prototype_chain) const { |
| 20 DCHECK(is_simple_api_call()); | 21 DCHECK(is_simple_api_call()); |
| 21 if (!object_map->IsJSObjectMap()) { | 22 if (!object_map->IsJSObjectMap()) { |
| 22 *holder_lookup = kHolderNotFound; | 23 *holder_lookup = kHolderNotFound; |
| 23 return Handle<JSObject>::null(); | 24 return Handle<JSObject>::null(); |
| 24 } | 25 } |
| 25 if (expected_receiver_type_.is_null() || | 26 if (expected_receiver_type_.is_null() || |
| 26 expected_receiver_type_->IsTemplateFor(*object_map)) { | 27 expected_receiver_type_->IsTemplateFor(*object_map)) { |
| 27 *holder_lookup = kHolderIsReceiver; | 28 *holder_lookup = kHolderIsReceiver; |
| 28 return Handle<JSObject>::null(); | 29 return Handle<JSObject>::null(); |
| 29 } | 30 } |
| 30 while (true) { | 31 for (int depth = 1; true; depth++) { |
| 31 if (!object_map->prototype()->IsJSObject()) break; | 32 if (!object_map->prototype()->IsJSObject()) break; |
| 32 Handle<JSObject> prototype(JSObject::cast(object_map->prototype())); | 33 Handle<JSObject> prototype(JSObject::cast(object_map->prototype())); |
| 33 if (!prototype->map()->is_hidden_prototype()) break; | 34 if (!prototype->map()->is_hidden_prototype()) break; |
| 34 object_map = handle(prototype->map()); | 35 object_map = handle(prototype->map()); |
| 35 if (expected_receiver_type_->IsTemplateFor(*object_map)) { | 36 if (expected_receiver_type_->IsTemplateFor(*object_map)) { |
| 36 *holder_lookup = kHolderFound; | 37 *holder_lookup = kHolderFound; |
| 38 if (holder_depth_in_prototype_chain != NULL) { |
| 39 *holder_depth_in_prototype_chain = depth; |
| 40 } |
| 37 return prototype; | 41 return prototype; |
| 38 } | 42 } |
| 39 } | 43 } |
| 40 *holder_lookup = kHolderNotFound; | 44 *holder_lookup = kHolderNotFound; |
| 41 return Handle<JSObject>::null(); | 45 return Handle<JSObject>::null(); |
| 42 } | 46 } |
| 43 | 47 |
| 44 | 48 |
| 45 bool CallOptimization::IsCompatibleReceiver(Handle<Object> receiver, | 49 bool CallOptimization::IsCompatibleReceiver(Handle<Object> receiver, |
| 46 Handle<JSObject> holder) const { | 50 Handle<JSObject> holder) const { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 | 100 |
| 97 if (!info->signature()->IsUndefined()) { | 101 if (!info->signature()->IsUndefined()) { |
| 98 expected_receiver_type_ = | 102 expected_receiver_type_ = |
| 99 handle(FunctionTemplateInfo::cast(info->signature())); | 103 handle(FunctionTemplateInfo::cast(info->signature())); |
| 100 } | 104 } |
| 101 | 105 |
| 102 is_simple_api_call_ = true; | 106 is_simple_api_call_ = true; |
| 103 } | 107 } |
| 104 } | 108 } |
| 105 } // namespace v8::internal | 109 } // namespace v8::internal |
| OLD | NEW |