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/ic/call-optimization.h" | 5 #include "src/ic/call-optimization.h" |
6 | 6 |
7 | 7 |
8 namespace v8 { | 8 namespace v8 { |
9 namespace internal { | 9 namespace internal { |
10 | 10 |
11 CallOptimization::CallOptimization(Handle<Object> function) { | 11 CallOptimization::CallOptimization(Handle<JSFunction> function) { |
12 constant_function_ = Handle<JSFunction>::null(); | 12 Initialize(function); |
13 is_simple_api_call_ = false; | |
14 expected_receiver_type_ = Handle<FunctionTemplateInfo>::null(); | |
15 api_call_info_ = Handle<CallHandlerInfo>::null(); | |
16 if (function->IsJSFunction()) { | |
17 Initialize(Handle<JSFunction>::cast(function)); | |
18 } else if (function->IsFunctionTemplateInfo()) { | |
19 Initialize(Handle<FunctionTemplateInfo>::cast(function)); | |
20 } | |
21 } | 13 } |
22 | 14 |
23 | 15 |
24 Handle<JSObject> CallOptimization::LookupHolderOfExpectedType( | 16 Handle<JSObject> CallOptimization::LookupHolderOfExpectedType( |
25 Handle<Map> object_map, HolderLookup* holder_lookup, | 17 Handle<Map> object_map, HolderLookup* holder_lookup, |
26 int* holder_depth_in_prototype_chain) const { | 18 int* holder_depth_in_prototype_chain) const { |
27 DCHECK(is_simple_api_call()); | 19 DCHECK(is_simple_api_call()); |
28 if (!object_map->IsJSObjectMap()) { | 20 if (!object_map->IsJSObjectMap()) { |
29 *holder_lookup = kHolderNotFound; | 21 *holder_lookup = kHolderNotFound; |
30 return Handle<JSObject>::null(); | 22 return Handle<JSObject>::null(); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 if (prototype == *holder) return true; | 73 if (prototype == *holder) return true; |
82 object = JSObject::cast(prototype); | 74 object = JSObject::cast(prototype); |
83 } | 75 } |
84 } | 76 } |
85 break; | 77 break; |
86 } | 78 } |
87 UNREACHABLE(); | 79 UNREACHABLE(); |
88 return false; | 80 return false; |
89 } | 81 } |
90 | 82 |
91 void CallOptimization::Initialize( | |
92 Handle<FunctionTemplateInfo> function_template_info) { | |
93 if (function_template_info->call_code()->IsUndefined()) return; | |
94 api_call_info_ = | |
95 handle(CallHandlerInfo::cast(function_template_info->call_code())); | |
96 | |
97 if (!function_template_info->signature()->IsUndefined()) { | |
98 expected_receiver_type_ = | |
99 handle(FunctionTemplateInfo::cast(function_template_info->signature())); | |
100 } | |
101 is_simple_api_call_ = true; | |
102 } | |
103 | 83 |
104 void CallOptimization::Initialize(Handle<JSFunction> function) { | 84 void CallOptimization::Initialize(Handle<JSFunction> function) { |
| 85 constant_function_ = Handle<JSFunction>::null(); |
| 86 is_simple_api_call_ = false; |
| 87 expected_receiver_type_ = Handle<FunctionTemplateInfo>::null(); |
| 88 api_call_info_ = Handle<CallHandlerInfo>::null(); |
| 89 |
105 if (function.is_null() || !function->is_compiled()) return; | 90 if (function.is_null() || !function->is_compiled()) return; |
106 | 91 |
107 constant_function_ = function; | 92 constant_function_ = function; |
108 AnalyzePossibleApiFunction(function); | 93 AnalyzePossibleApiFunction(function); |
109 } | 94 } |
110 | 95 |
111 | 96 |
112 void CallOptimization::AnalyzePossibleApiFunction(Handle<JSFunction> function) { | 97 void CallOptimization::AnalyzePossibleApiFunction(Handle<JSFunction> function) { |
113 if (!function->shared()->IsApiFunction()) return; | 98 if (!function->shared()->IsApiFunction()) return; |
114 Handle<FunctionTemplateInfo> info(function->shared()->get_api_func_data()); | 99 Handle<FunctionTemplateInfo> info(function->shared()->get_api_func_data()); |
115 | 100 |
116 // Require a C++ callback. | 101 // Require a C++ callback. |
117 if (info->call_code()->IsUndefined()) return; | 102 if (info->call_code()->IsUndefined()) return; |
118 api_call_info_ = handle(CallHandlerInfo::cast(info->call_code())); | 103 api_call_info_ = handle(CallHandlerInfo::cast(info->call_code())); |
119 | 104 |
120 if (!info->signature()->IsUndefined()) { | 105 if (!info->signature()->IsUndefined()) { |
121 expected_receiver_type_ = | 106 expected_receiver_type_ = |
122 handle(FunctionTemplateInfo::cast(info->signature())); | 107 handle(FunctionTemplateInfo::cast(info->signature())); |
123 } | 108 } |
124 | 109 |
125 is_simple_api_call_ = true; | 110 is_simple_api_call_ = true; |
126 } | 111 } |
127 } // namespace internal | 112 } // namespace internal |
128 } // namespace v8 | 113 } // namespace v8 |
OLD | NEW |