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" |
11 #include "src/deoptimizer.h" | 11 #include "src/deoptimizer.h" |
12 #include "src/frames-inl.h" | 12 #include "src/frames-inl.h" |
13 #include "src/isolate-inl.h" | 13 #include "src/isolate-inl.h" |
14 #include "src/messages.h" | 14 #include "src/messages.h" |
15 | 15 |
16 namespace v8 { | 16 namespace v8 { |
17 namespace internal { | 17 namespace internal { |
18 | 18 |
19 // TODO(bmeurer): This is an awful hack resulting from our inability to decide | |
20 // who's responsible for doing the receiver patching. By any means, we really | |
21 // need to kill this runtime function and just do things right instead!! | |
22 RUNTIME_FUNCTION(Runtime_IsSloppyModeFunction) { | |
23 SealHandleScope shs(isolate); | |
24 DCHECK(args.length() == 1); | |
25 CONVERT_ARG_CHECKED(JSReceiver, callable, 0); | |
26 if (!callable->IsJSFunction()) { | |
27 HandleScope scope(isolate); | |
28 Handle<JSFunction> delegate; | |
29 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
30 isolate, delegate, | |
31 Execution::GetFunctionDelegate(isolate, Handle<JSReceiver>(callable))); | |
32 callable = JSFunction::cast(*delegate); | |
33 } | |
34 JSFunction* function = JSFunction::cast(callable); | |
35 SharedFunctionInfo* shared = function->shared(); | |
36 return isolate->heap()->ToBoolean(is_sloppy(shared->language_mode())); | |
37 } | |
38 | |
39 | |
40 RUNTIME_FUNCTION(Runtime_FunctionGetName) { | 19 RUNTIME_FUNCTION(Runtime_FunctionGetName) { |
41 SealHandleScope shs(isolate); | 20 SealHandleScope shs(isolate); |
42 DCHECK(args.length() == 1); | 21 DCHECK(args.length() == 1); |
43 | 22 |
44 CONVERT_ARG_CHECKED(JSFunction, f, 0); | 23 CONVERT_ARG_CHECKED(JSFunction, f, 0); |
45 return f->shared()->name(); | 24 return f->shared()->name(); |
46 } | 25 } |
47 | 26 |
48 | 27 |
49 RUNTIME_FUNCTION(Runtime_FunctionSetName) { | 28 RUNTIME_FUNCTION(Runtime_FunctionSetName) { |
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 Handle<Object> result; | 504 Handle<Object> result; |
526 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 505 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
527 isolate, result, Execution::New(Handle<JSFunction>::cast(bound_function), | 506 isolate, result, Execution::New(Handle<JSFunction>::cast(bound_function), |
528 total_argc, param_data.get())); | 507 total_argc, param_data.get())); |
529 return *result; | 508 return *result; |
530 } | 509 } |
531 | 510 |
532 | 511 |
533 RUNTIME_FUNCTION(Runtime_Call) { | 512 RUNTIME_FUNCTION(Runtime_Call) { |
534 HandleScope scope(isolate); | 513 HandleScope scope(isolate); |
535 DCHECK(args.length() >= 2); | 514 DCHECK_LE(2, args.length()); |
536 int argc = args.length() - 2; | 515 int const argc = args.length() - 2; |
537 CONVERT_ARG_CHECKED(JSReceiver, fun, argc + 1); | 516 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, target, 0); |
538 Object* receiver = args[0]; | 517 CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 1); |
539 | 518 ScopedVector<Handle<Object>> argv(argc); |
540 // If there are too many arguments, allocate argv via malloc. | 519 for (int i = 0; i < argc; ++i) { |
541 const int argv_small_size = 10; | 520 argv[i] = args.at<Object>(2 + i); |
542 Handle<Object> argv_small_buffer[argv_small_size]; | |
543 base::SmartArrayPointer<Handle<Object> > argv_large_buffer; | |
544 Handle<Object>* argv = argv_small_buffer; | |
545 if (argc > argv_small_size) { | |
546 argv = new Handle<Object>[argc]; | |
547 if (argv == NULL) return isolate->StackOverflow(); | |
548 argv_large_buffer = base::SmartArrayPointer<Handle<Object> >(argv); | |
549 } | 521 } |
550 | |
551 for (int i = 0; i < argc; ++i) { | |
552 argv[i] = Handle<Object>(args[1 + i], isolate); | |
553 } | |
554 | |
555 Handle<JSReceiver> hfun(fun); | |
556 Handle<Object> hreceiver(receiver, isolate); | |
557 Handle<Object> result; | 522 Handle<Object> result; |
558 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 523 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
559 isolate, result, | 524 isolate, result, |
560 Execution::Call(isolate, hfun, hreceiver, argc, argv, true)); | 525 Execution::Call(isolate, target, receiver, argc, argv.start(), true)); |
561 return *result; | 526 return *result; |
562 } | 527 } |
563 | 528 |
564 | 529 |
565 RUNTIME_FUNCTION(Runtime_Apply) { | 530 RUNTIME_FUNCTION(Runtime_Apply) { |
566 HandleScope scope(isolate); | 531 HandleScope scope(isolate); |
567 DCHECK(args.length() == 5); | 532 DCHECK(args.length() == 5); |
568 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, fun, 0); | 533 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, fun, 0); |
569 CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 1); | 534 CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 1); |
570 CONVERT_ARG_HANDLE_CHECKED(JSObject, arguments, 2); | 535 CONVERT_ARG_HANDLE_CHECKED(JSObject, arguments, 2); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 RUNTIME_FUNCTION(Runtime_GetOriginalConstructor) { | 592 RUNTIME_FUNCTION(Runtime_GetOriginalConstructor) { |
628 SealHandleScope shs(isolate); | 593 SealHandleScope shs(isolate); |
629 DCHECK(args.length() == 0); | 594 DCHECK(args.length() == 0); |
630 JavaScriptFrameIterator it(isolate); | 595 JavaScriptFrameIterator it(isolate); |
631 JavaScriptFrame* frame = it.frame(); | 596 JavaScriptFrame* frame = it.frame(); |
632 return frame->IsConstructor() ? frame->GetOriginalConstructor() | 597 return frame->IsConstructor() ? frame->GetOriginalConstructor() |
633 : isolate->heap()->undefined_value(); | 598 : isolate->heap()->undefined_value(); |
634 } | 599 } |
635 | 600 |
636 | 601 |
| 602 // TODO(bmeurer): Kill %_CallFunction ASAP as it is almost never used |
| 603 // correctly because of the weird semantics underneath. |
637 RUNTIME_FUNCTION(Runtime_CallFunction) { | 604 RUNTIME_FUNCTION(Runtime_CallFunction) { |
638 SealHandleScope shs(isolate); | 605 HandleScope scope(isolate); |
639 return __RT_impl_Runtime_Call(args, isolate); | 606 DCHECK(args.length() >= 2); |
| 607 int argc = args.length() - 2; |
| 608 CONVERT_ARG_CHECKED(JSReceiver, fun, argc + 1); |
| 609 Object* receiver = args[0]; |
| 610 |
| 611 // If there are too many arguments, allocate argv via malloc. |
| 612 const int argv_small_size = 10; |
| 613 Handle<Object> argv_small_buffer[argv_small_size]; |
| 614 base::SmartArrayPointer<Handle<Object>> argv_large_buffer; |
| 615 Handle<Object>* argv = argv_small_buffer; |
| 616 if (argc > argv_small_size) { |
| 617 argv = new Handle<Object>[argc]; |
| 618 if (argv == NULL) return isolate->StackOverflow(); |
| 619 argv_large_buffer = base::SmartArrayPointer<Handle<Object>>(argv); |
| 620 } |
| 621 |
| 622 for (int i = 0; i < argc; ++i) { |
| 623 argv[i] = Handle<Object>(args[1 + i], isolate); |
| 624 } |
| 625 |
| 626 Handle<JSReceiver> hfun(fun); |
| 627 Handle<Object> hreceiver(receiver, isolate); |
| 628 Handle<Object> result; |
| 629 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 630 isolate, result, |
| 631 Execution::Call(isolate, hfun, hreceiver, argc, argv, true)); |
| 632 return *result; |
640 } | 633 } |
641 | 634 |
642 | 635 |
643 RUNTIME_FUNCTION(Runtime_IsConstructCall) { | 636 RUNTIME_FUNCTION(Runtime_IsConstructCall) { |
644 SealHandleScope shs(isolate); | 637 SealHandleScope shs(isolate); |
645 DCHECK(args.length() == 0); | 638 DCHECK(args.length() == 0); |
646 JavaScriptFrameIterator it(isolate); | 639 JavaScriptFrameIterator it(isolate); |
647 JavaScriptFrame* frame = it.frame(); | 640 JavaScriptFrame* frame = it.frame(); |
648 return isolate->heap()->ToBoolean(frame->IsConstructor()); | 641 return isolate->heap()->ToBoolean(frame->IsConstructor()); |
649 } | 642 } |
650 | 643 |
651 | 644 |
652 RUNTIME_FUNCTION(Runtime_IsFunction) { | 645 RUNTIME_FUNCTION(Runtime_IsFunction) { |
653 SealHandleScope shs(isolate); | 646 SealHandleScope shs(isolate); |
654 DCHECK(args.length() == 1); | 647 DCHECK(args.length() == 1); |
655 CONVERT_ARG_CHECKED(Object, obj, 0); | 648 CONVERT_ARG_CHECKED(Object, obj, 0); |
656 return isolate->heap()->ToBoolean(obj->IsJSFunction()); | 649 return isolate->heap()->ToBoolean(obj->IsJSFunction()); |
657 } | 650 } |
658 | 651 |
659 | 652 |
660 RUNTIME_FUNCTION(Runtime_ThrowStrongModeTooFewArguments) { | 653 RUNTIME_FUNCTION(Runtime_ThrowStrongModeTooFewArguments) { |
661 HandleScope scope(isolate); | 654 HandleScope scope(isolate); |
662 DCHECK(args.length() == 0); | 655 DCHECK(args.length() == 0); |
663 THROW_NEW_ERROR_RETURN_FAILURE(isolate, | 656 THROW_NEW_ERROR_RETURN_FAILURE(isolate, |
664 NewTypeError(MessageTemplate::kStrongArity)); | 657 NewTypeError(MessageTemplate::kStrongArity)); |
665 } | 658 } |
666 } // namespace internal | 659 } // namespace internal |
667 } // namespace v8 | 660 } // namespace v8 |
OLD | NEW |