Chromium Code Reviews| 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/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/deoptimizer.h" | 10 #include "src/deoptimizer.h" |
| (...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 568 Handle<Object> result; | 568 Handle<Object> result; |
| 569 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 569 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 570 isolate, result, | 570 isolate, result, |
| 571 Execution::Call(isolate, hfun, hreceiver, argc, argv, true)); | 571 Execution::Call(isolate, hfun, hreceiver, argc, argv, true)); |
| 572 return *result; | 572 return *result; |
| 573 } | 573 } |
| 574 | 574 |
| 575 | 575 |
| 576 RUNTIME_FUNCTION(Runtime_Apply) { | 576 RUNTIME_FUNCTION(Runtime_Apply) { |
| 577 HandleScope scope(isolate); | 577 HandleScope scope(isolate); |
| 578 DCHECK(args.length() == 5); | 578 DCHECK(args.length() == 5 || args.length() == 3); |
|
arv (Not doing code reviews)
2015/02/23 17:55:56
I think it would be cleaner to have to functions.
rossberg
2015/02/24 16:22:47
+1
caitp (gmail)
2015/02/25 00:00:24
done
| |
| 579 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, fun, 0); | 579 CONVERT_ARG_HANDLE_CHECKED(Object, fun, 0); |
| 580 CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 1); | 580 CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 1); |
| 581 CONVERT_ARG_HANDLE_CHECKED(JSObject, arguments, 2); | 581 CONVERT_ARG_HANDLE_CHECKED(JSObject, arguments, 2); |
| 582 CONVERT_INT32_ARG_CHECKED(offset, 3); | 582 |
| 583 CONVERT_INT32_ARG_CHECKED(argc, 4); | 583 int32_t offset = 0; |
| 584 int32_t argc = 0; | |
| 585 | |
| 586 if (args.length() == 5) { | |
| 587 RUNTIME_ASSERT(args[3]->IsNumber()); | |
| 588 RUNTIME_ASSERT(args[3]->ToInt32(&offset)); | |
| 589 RUNTIME_ASSERT(args[4]->IsNumber()); | |
| 590 RUNTIME_ASSERT(args[4]->ToInt32(&argc)); | |
| 591 } else { | |
| 592 RUNTIME_ASSERT(arguments->IsJSArray()); | |
| 593 RUNTIME_ASSERT(Handle<JSArray>::cast(arguments)->length()->ToInt32(&argc)); | |
| 594 } | |
| 595 | |
| 596 if (!fun->IsJSFunction()) { | |
| 597 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
| 598 isolate, fun, Execution::TryGetFunctionDelegate(isolate, fun)); | |
| 599 } | |
| 600 | |
| 584 RUNTIME_ASSERT(offset >= 0); | 601 RUNTIME_ASSERT(offset >= 0); |
| 585 // Loose upper bound to allow fuzzing. We'll most likely run out of | 602 // Loose upper bound to allow fuzzing. We'll most likely run out of |
| 586 // stack space before hitting this limit. | 603 // stack space before hitting this limit. |
| 587 static int kMaxArgc = 1000000; | 604 static int kMaxArgc = 1000000; |
| 588 RUNTIME_ASSERT(argc >= 0 && argc <= kMaxArgc); | 605 RUNTIME_ASSERT(argc >= 0 && argc <= kMaxArgc); |
| 589 | 606 |
| 590 // If there are too many arguments, allocate argv via malloc. | 607 // If there are too many arguments, allocate argv via malloc. |
| 591 const int argv_small_size = 10; | 608 const int argv_small_size = 10; |
| 592 Handle<Object> argv_small_buffer[argv_small_size]; | 609 Handle<Object> argv_small_buffer[argv_small_size]; |
| 593 SmartArrayPointer<Handle<Object> > argv_large_buffer; | 610 SmartArrayPointer<Handle<Object> > argv_large_buffer; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 604 } | 621 } |
| 605 | 622 |
| 606 Handle<Object> result; | 623 Handle<Object> result; |
| 607 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 624 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 608 isolate, result, | 625 isolate, result, |
| 609 Execution::Call(isolate, fun, receiver, argc, argv, true)); | 626 Execution::Call(isolate, fun, receiver, argc, argv, true)); |
| 610 return *result; | 627 return *result; |
| 611 } | 628 } |
| 612 | 629 |
| 613 | 630 |
| 631 RUNTIME_FUNCTION(Runtime_ApplyConstruct) { | |
| 632 HandleScope scope(isolate); | |
| 633 DCHECK(args.length() == 4 || args.length() == 2); | |
| 634 CONVERT_ARG_HANDLE_CHECKED(Object, fun, 0); | |
| 635 CONVERT_ARG_HANDLE_CHECKED(JSObject, arguments, 1); | |
| 636 int32_t offset = 0; | |
| 637 int32_t argc = 0; | |
| 638 | |
| 639 | |
| 640 if (args.length() == 4) { | |
| 641 RUNTIME_ASSERT(args[2]->IsNumber()); | |
| 642 RUNTIME_ASSERT(args[2]->ToInt32(&offset)); | |
| 643 RUNTIME_ASSERT(args[3]->IsNumber()); | |
| 644 RUNTIME_ASSERT(args[3]->ToInt32(&argc)); | |
| 645 } else { | |
| 646 RUNTIME_ASSERT(arguments->IsJSArray()); | |
| 647 RUNTIME_ASSERT(Handle<JSArray>::cast(arguments)->length()->ToInt32(&argc)); | |
| 648 } | |
| 649 | |
| 650 if (!fun->IsJSFunction()) { | |
| 651 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
| 652 isolate, fun, Execution::TryGetConstructorDelegate(isolate, fun)); | |
| 653 } | |
| 654 | |
| 655 RUNTIME_ASSERT(offset >= 0); | |
| 656 // Loose upper bound to allow fuzzing. We'll most likely run out of | |
| 657 // stack space before hitting this limit. | |
| 658 static int kMaxArgc = 1000000; | |
| 659 RUNTIME_ASSERT(argc >= 0 && argc <= kMaxArgc); | |
| 660 | |
| 661 // If there are too many arguments, allocate argv via malloc. | |
| 662 const int argv_small_size = 10; | |
| 663 Handle<Object> argv_small_buffer[argv_small_size]; | |
| 664 SmartArrayPointer<Handle<Object> > argv_large_buffer; | |
| 665 Handle<Object>* argv = argv_small_buffer; | |
| 666 if (argc > argv_small_size) { | |
| 667 argv = new Handle<Object>[argc]; | |
| 668 if (argv == NULL) return isolate->StackOverflow(); | |
| 669 argv_large_buffer = SmartArrayPointer<Handle<Object> >(argv); | |
| 670 } | |
| 671 | |
| 672 for (int i = 0; i < argc; ++i) { | |
| 673 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
| 674 isolate, argv[i], Object::GetElement(isolate, arguments, offset + i)); | |
| 675 } | |
| 676 | |
| 677 Handle<Object> result; | |
| 678 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result, | |
| 679 Execution::New(fun, argc, argv)); | |
| 680 return *result; | |
| 681 } | |
| 682 | |
| 683 | |
| 614 RUNTIME_FUNCTION(Runtime_GetFunctionDelegate) { | 684 RUNTIME_FUNCTION(Runtime_GetFunctionDelegate) { |
| 615 HandleScope scope(isolate); | 685 HandleScope scope(isolate); |
| 616 DCHECK(args.length() == 1); | 686 DCHECK(args.length() == 1); |
| 617 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); | 687 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); |
| 618 RUNTIME_ASSERT(!object->IsJSFunction()); | 688 RUNTIME_ASSERT(!object->IsJSFunction()); |
| 619 return *Execution::GetFunctionDelegate(isolate, object); | 689 return *Execution::GetFunctionDelegate(isolate, object); |
| 620 } | 690 } |
| 621 | 691 |
| 622 | 692 |
| 623 RUNTIME_FUNCTION(Runtime_GetConstructorDelegate) { | 693 RUNTIME_FUNCTION(Runtime_GetConstructorDelegate) { |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 645 | 715 |
| 646 | 716 |
| 647 RUNTIME_FUNCTION(RuntimeReference_IsFunction) { | 717 RUNTIME_FUNCTION(RuntimeReference_IsFunction) { |
| 648 SealHandleScope shs(isolate); | 718 SealHandleScope shs(isolate); |
| 649 DCHECK(args.length() == 1); | 719 DCHECK(args.length() == 1); |
| 650 CONVERT_ARG_CHECKED(Object, obj, 0); | 720 CONVERT_ARG_CHECKED(Object, obj, 0); |
| 651 return isolate->heap()->ToBoolean(obj->IsJSFunction()); | 721 return isolate->heap()->ToBoolean(obj->IsJSFunction()); |
| 652 } | 722 } |
| 653 } | 723 } |
| 654 } // namespace v8::internal | 724 } // namespace v8::internal |
| OLD | NEW |