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/runtime/runtime-utils.h" | 5 #include "src/runtime/runtime-utils.h" |
6 | 6 |
7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/arguments.h" | 8 #include "src/arguments.h" |
9 #include "src/compiler.h" | 9 #include "src/compiler.h" |
10 #include "src/cpu-profiler.h" | 10 #include "src/cpu-profiler.h" |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 JSFunction* func = JSFunction::cast(*object); | 306 JSFunction* func = JSFunction::cast(*object); |
307 func->shared()->set_force_inline(true); | 307 func->shared()->set_force_inline(true); |
308 } | 308 } |
309 return isolate->heap()->undefined_value(); | 309 return isolate->heap()->undefined_value(); |
310 } | 310 } |
311 | 311 |
312 | 312 |
313 // Find the arguments of the JavaScript function invocation that called | 313 // Find the arguments of the JavaScript function invocation that called |
314 // into C++ code. Collect these in a newly allocated array of handles (possibly | 314 // into C++ code. Collect these in a newly allocated array of handles (possibly |
315 // prefixed by a number of empty handles). | 315 // prefixed by a number of empty handles). |
316 static base::SmartArrayPointer<Handle<Object> > GetCallerArguments( | 316 base::SmartArrayPointer<Handle<Object>> Runtime::GetCallerArguments( |
317 Isolate* isolate, int prefix_argc, int* total_argc) { | 317 Isolate* isolate, int prefix_argc, int* total_argc) { |
318 // Find frame containing arguments passed to the caller. | 318 // Find frame containing arguments passed to the caller. |
319 JavaScriptFrameIterator it(isolate); | 319 JavaScriptFrameIterator it(isolate); |
320 JavaScriptFrame* frame = it.frame(); | 320 JavaScriptFrame* frame = it.frame(); |
321 List<JSFunction*> functions(2); | 321 List<JSFunction*> functions(2); |
322 frame->GetFunctions(&functions); | 322 frame->GetFunctions(&functions); |
323 if (functions.length() > 1) { | 323 if (functions.length() > 1) { |
324 int inlined_jsframe_index = functions.length() - 1; | 324 int inlined_jsframe_index = functions.length() - 1; |
325 TranslatedState translated_values(frame); | 325 TranslatedState translated_values(frame); |
326 translated_values.Prepare(false, frame->fp()); | 326 translated_values.Prepare(false, frame->fp()); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 CONVERT_ARG_HANDLE_CHECKED(Object, bindee, 1); | 378 CONVERT_ARG_HANDLE_CHECKED(Object, bindee, 1); |
379 CONVERT_ARG_HANDLE_CHECKED(Object, this_object, 2); | 379 CONVERT_ARG_HANDLE_CHECKED(Object, this_object, 2); |
380 CONVERT_NUMBER_ARG_HANDLE_CHECKED(new_length, 3); | 380 CONVERT_NUMBER_ARG_HANDLE_CHECKED(new_length, 3); |
381 | 381 |
382 // TODO(lrn): Create bound function in C++ code from premade shared info. | 382 // TODO(lrn): Create bound function in C++ code from premade shared info. |
383 bound_function->shared()->set_bound(true); | 383 bound_function->shared()->set_bound(true); |
384 bound_function->shared()->set_optimized_code_map(Smi::FromInt(0)); | 384 bound_function->shared()->set_optimized_code_map(Smi::FromInt(0)); |
385 bound_function->shared()->set_inferred_name(isolate->heap()->empty_string()); | 385 bound_function->shared()->set_inferred_name(isolate->heap()->empty_string()); |
386 // Get all arguments of calling function (Function.prototype.bind). | 386 // Get all arguments of calling function (Function.prototype.bind). |
387 int argc = 0; | 387 int argc = 0; |
388 base::SmartArrayPointer<Handle<Object> > arguments = | 388 base::SmartArrayPointer<Handle<Object>> arguments = |
389 GetCallerArguments(isolate, 0, &argc); | 389 Runtime::GetCallerArguments(isolate, 0, &argc); |
390 // Don't count the this-arg. | 390 // Don't count the this-arg. |
391 if (argc > 0) { | 391 if (argc > 0) { |
392 RUNTIME_ASSERT(arguments[0].is_identical_to(this_object)); | 392 RUNTIME_ASSERT(arguments[0].is_identical_to(this_object)); |
393 argc--; | 393 argc--; |
394 } else { | 394 } else { |
395 RUNTIME_ASSERT(this_object->IsUndefined()); | 395 RUNTIME_ASSERT(this_object->IsUndefined()); |
396 } | 396 } |
397 // Initialize array of bindings (function, this, and any existing arguments | 397 // Initialize array of bindings (function, this, and any existing arguments |
398 // if the function was already bound). | 398 // if the function was already bound). |
399 Handle<FixedArray> new_bindings; | 399 Handle<FixedArray> new_bindings; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 Handle<FixedArray> bound_args = | 480 Handle<FixedArray> bound_args = |
481 Handle<FixedArray>(FixedArray::cast(function->function_bindings())); | 481 Handle<FixedArray>(FixedArray::cast(function->function_bindings())); |
482 int bound_argc = bound_args->length() - JSFunction::kBoundArgumentsStartIndex; | 482 int bound_argc = bound_args->length() - JSFunction::kBoundArgumentsStartIndex; |
483 Handle<Object> bound_function( | 483 Handle<Object> bound_function( |
484 JSReceiver::cast(bound_args->get(JSFunction::kBoundFunctionIndex)), | 484 JSReceiver::cast(bound_args->get(JSFunction::kBoundFunctionIndex)), |
485 isolate); | 485 isolate); |
486 DCHECK(!bound_function->IsJSFunction() || | 486 DCHECK(!bound_function->IsJSFunction() || |
487 !Handle<JSFunction>::cast(bound_function)->shared()->bound()); | 487 !Handle<JSFunction>::cast(bound_function)->shared()->bound()); |
488 | 488 |
489 int total_argc = 0; | 489 int total_argc = 0; |
490 base::SmartArrayPointer<Handle<Object> > param_data = | 490 base::SmartArrayPointer<Handle<Object>> param_data = |
491 GetCallerArguments(isolate, bound_argc, &total_argc); | 491 Runtime::GetCallerArguments(isolate, bound_argc, &total_argc); |
492 for (int i = 0; i < bound_argc; i++) { | 492 for (int i = 0; i < bound_argc; i++) { |
493 param_data[i] = Handle<Object>( | 493 param_data[i] = Handle<Object>( |
494 bound_args->get(JSFunction::kBoundArgumentsStartIndex + i), isolate); | 494 bound_args->get(JSFunction::kBoundArgumentsStartIndex + i), isolate); |
495 } | 495 } |
496 | 496 |
497 if (!bound_function->IsJSFunction()) { | 497 if (!bound_function->IsJSFunction()) { |
498 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 498 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
499 isolate, bound_function, | 499 isolate, bound_function, |
500 Execution::GetConstructorDelegate(isolate, bound_function)); | 500 Execution::GetConstructorDelegate(isolate, bound_function)); |
501 } | 501 } |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
651 | 651 |
652 | 652 |
653 RUNTIME_FUNCTION(Runtime_ThrowStrongModeTooFewArguments) { | 653 RUNTIME_FUNCTION(Runtime_ThrowStrongModeTooFewArguments) { |
654 HandleScope scope(isolate); | 654 HandleScope scope(isolate); |
655 DCHECK(args.length() == 0); | 655 DCHECK(args.length() == 0); |
656 THROW_NEW_ERROR_RETURN_FAILURE(isolate, | 656 THROW_NEW_ERROR_RETURN_FAILURE(isolate, |
657 NewTypeError(MessageTemplate::kStrongArity)); | 657 NewTypeError(MessageTemplate::kStrongArity)); |
658 } | 658 } |
659 } // namespace internal | 659 } // namespace internal |
660 } // namespace v8 | 660 } // namespace v8 |
OLD | NEW |