| OLD | NEW |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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/builtins/builtins.h" | 5 #include "src/builtins/builtins.h" |
| 6 | 6 |
| 7 #include "src/api-arguments.h" | 7 #include "src/api-arguments.h" |
| 8 #include "src/api-natives.h" | 8 #include "src/api-natives.h" |
| 9 #include "src/builtins/builtins-utils.h" | 9 #include "src/builtins/builtins-utils.h" |
| 10 | 10 |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 v->VisitPointers(lowest_address(), highest_address() + 1); | 150 v->VisitPointers(lowest_address(), highest_address() + 1); |
| 151 } | 151 } |
| 152 | 152 |
| 153 private: | 153 private: |
| 154 DISALLOW_COPY_AND_ASSIGN(RelocatableArguments); | 154 DISALLOW_COPY_AND_ASSIGN(RelocatableArguments); |
| 155 }; | 155 }; |
| 156 | 156 |
| 157 } // namespace | 157 } // namespace |
| 158 | 158 |
| 159 MaybeHandle<Object> Builtins::InvokeApiFunction(Isolate* isolate, | 159 MaybeHandle<Object> Builtins::InvokeApiFunction(Isolate* isolate, |
| 160 bool is_construct, |
| 160 Handle<HeapObject> function, | 161 Handle<HeapObject> function, |
| 161 Handle<Object> receiver, | 162 Handle<Object> receiver, |
| 162 int argc, | 163 int argc, Handle<Object> args[], |
| 163 Handle<Object> args[]) { | 164 Handle<HeapObject> new_target) { |
| 164 DCHECK(function->IsFunctionTemplateInfo() || | 165 DCHECK(function->IsFunctionTemplateInfo() || |
| 165 (function->IsJSFunction() && | 166 (function->IsJSFunction() && |
| 166 JSFunction::cast(*function)->shared()->IsApiFunction())); | 167 JSFunction::cast(*function)->shared()->IsApiFunction())); |
| 167 | 168 |
| 168 // Do proper receiver conversion for non-strict mode api functions. | 169 // Do proper receiver conversion for non-strict mode api functions. |
| 169 if (!receiver->IsJSReceiver()) { | 170 if (!is_construct && !receiver->IsJSReceiver()) { |
| 170 if (function->IsFunctionTemplateInfo() || | 171 if (function->IsFunctionTemplateInfo() || |
| 171 is_sloppy(JSFunction::cast(*function)->shared()->language_mode())) { | 172 is_sloppy(JSFunction::cast(*function)->shared()->language_mode())) { |
| 172 ASSIGN_RETURN_ON_EXCEPTION(isolate, receiver, | 173 ASSIGN_RETURN_ON_EXCEPTION(isolate, receiver, |
| 173 Object::ConvertReceiver(isolate, receiver), | 174 Object::ConvertReceiver(isolate, receiver), |
| 174 Object); | 175 Object); |
| 175 } | 176 } |
| 176 } | 177 } |
| 177 | 178 |
| 178 Handle<FunctionTemplateInfo> fun_data = | 179 Handle<FunctionTemplateInfo> fun_data = |
| 179 function->IsFunctionTemplateInfo() | 180 function->IsFunctionTemplateInfo() |
| 180 ? Handle<FunctionTemplateInfo>::cast(function) | 181 ? Handle<FunctionTemplateInfo>::cast(function) |
| 181 : handle(JSFunction::cast(*function)->shared()->get_api_func_data(), | 182 : handle(JSFunction::cast(*function)->shared()->get_api_func_data(), |
| 182 isolate); | 183 isolate); |
| 183 Handle<HeapObject> new_target = isolate->factory()->undefined_value(); | |
| 184 // Construct BuiltinArguments object: | 184 // Construct BuiltinArguments object: |
| 185 // new target, function, arguments reversed, receiver. | 185 // new target, function, arguments reversed, receiver. |
| 186 const int kBufferSize = 32; | 186 const int kBufferSize = 32; |
| 187 Object* small_argv[kBufferSize]; | 187 Object* small_argv[kBufferSize]; |
| 188 Object** argv; | 188 Object** argv; |
| 189 const int frame_argc = argc + BuiltinArguments::kNumExtraArgsWithReceiver; | 189 const int frame_argc = argc + BuiltinArguments::kNumExtraArgsWithReceiver; |
| 190 if (frame_argc <= kBufferSize) { | 190 if (frame_argc <= kBufferSize) { |
| 191 argv = small_argv; | 191 argv = small_argv; |
| 192 } else { | 192 } else { |
| 193 argv = new Object*[frame_argc]; | 193 argv = new Object*[frame_argc]; |
| 194 } | 194 } |
| 195 int cursor = frame_argc - 1; | 195 int cursor = frame_argc - 1; |
| 196 argv[cursor--] = *receiver; | 196 argv[cursor--] = *receiver; |
| 197 for (int i = 0; i < argc; ++i) { | 197 for (int i = 0; i < argc; ++i) { |
| 198 argv[cursor--] = *args[i]; | 198 argv[cursor--] = *args[i]; |
| 199 } | 199 } |
| 200 DCHECK(cursor == BuiltinArguments::kArgcOffset); | 200 DCHECK(cursor == BuiltinArguments::kArgcOffset); |
| 201 argv[BuiltinArguments::kArgcOffset] = Smi::FromInt(frame_argc); | 201 argv[BuiltinArguments::kArgcOffset] = Smi::FromInt(frame_argc); |
| 202 argv[BuiltinArguments::kTargetOffset] = *function; | 202 argv[BuiltinArguments::kTargetOffset] = *function; |
| 203 argv[BuiltinArguments::kNewTargetOffset] = *new_target; | 203 argv[BuiltinArguments::kNewTargetOffset] = *new_target; |
| 204 MaybeHandle<Object> result; | 204 MaybeHandle<Object> result; |
| 205 { | 205 { |
| 206 RelocatableArguments arguments(isolate, frame_argc, &argv[frame_argc - 1]); | 206 RelocatableArguments arguments(isolate, frame_argc, &argv[frame_argc - 1]); |
| 207 result = HandleApiCallHelper<false>(isolate, function, new_target, fun_data, | 207 if (is_construct) { |
| 208 receiver, arguments); | 208 result = HandleApiCallHelper<true>(isolate, function, new_target, |
| 209 fun_data, receiver, arguments); |
| 210 } else { |
| 211 result = HandleApiCallHelper<false>(isolate, function, new_target, |
| 212 fun_data, receiver, arguments); |
| 213 } |
| 209 } | 214 } |
| 210 if (argv != small_argv) delete[] argv; | 215 if (argv != small_argv) delete[] argv; |
| 211 return result; | 216 return result; |
| 212 } | 217 } |
| 213 | 218 |
| 214 // Helper function to handle calls to non-function objects created through the | 219 // Helper function to handle calls to non-function objects created through the |
| 215 // API. The object can be called as either a constructor (using new) or just as | 220 // API. The object can be called as either a constructor (using new) or just as |
| 216 // a function (without new). | 221 // a function (without new). |
| 217 MUST_USE_RESULT static Object* HandleApiCallAsFunctionOrConstructor( | 222 MUST_USE_RESULT static Object* HandleApiCallAsFunctionOrConstructor( |
| 218 Isolate* isolate, bool is_construct_call, BuiltinArguments args) { | 223 Isolate* isolate, bool is_construct_call, BuiltinArguments args) { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 } | 282 } |
| 278 | 283 |
| 279 // Handle calls to non-function objects created through the API. This delegate | 284 // Handle calls to non-function objects created through the API. This delegate |
| 280 // function is used when the call is a construct call. | 285 // function is used when the call is a construct call. |
| 281 BUILTIN(HandleApiCallAsConstructor) { | 286 BUILTIN(HandleApiCallAsConstructor) { |
| 282 return HandleApiCallAsFunctionOrConstructor(isolate, true, args); | 287 return HandleApiCallAsFunctionOrConstructor(isolate, true, args); |
| 283 } | 288 } |
| 284 | 289 |
| 285 } // namespace internal | 290 } // namespace internal |
| 286 } // namespace v8 | 291 } // namespace v8 |
| OLD | NEW |