| 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/frames-inl.h" | 9 #include "src/frames-inl.h" |
| 10 #include "src/isolate-inl.h" | 10 #include "src/isolate-inl.h" |
| (...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 698 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); | 698 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); |
| 699 | 699 |
| 700 DCHECK(function->context() == isolate->context()); | 700 DCHECK(function->context() == isolate->context()); |
| 701 int length = function->shared()->scope_info()->ContextLength(); | 701 int length = function->shared()->scope_info()->ContextLength(); |
| 702 return *isolate->factory()->NewFunctionContext(length, function); | 702 return *isolate->factory()->NewFunctionContext(length, function); |
| 703 } | 703 } |
| 704 | 704 |
| 705 | 705 |
| 706 RUNTIME_FUNCTION(Runtime_PushWithContext) { | 706 RUNTIME_FUNCTION(Runtime_PushWithContext) { |
| 707 HandleScope scope(isolate); | 707 HandleScope scope(isolate); |
| 708 DCHECK(args.length() == 2); | 708 DCHECK_EQ(2, args.length()); |
| 709 CONVERT_ARG_HANDLE_CHECKED(Object, value, 0); |
| 710 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 1); |
| 709 Handle<JSReceiver> extension_object; | 711 Handle<JSReceiver> extension_object; |
| 710 if (args[0]->IsJSReceiver()) { | 712 if (!Object::ToObject(isolate, value).ToHandle(&extension_object)) { |
| 711 extension_object = args.at<JSReceiver>(0); | 713 THROW_NEW_ERROR_RETURN_FAILURE( |
| 712 } else { | 714 isolate, NewTypeError(MessageTemplate::kUndefinedOrNullToObject)); |
| 713 // Try to convert the object to a proper JavaScript object. | |
| 714 MaybeHandle<JSReceiver> maybe_object = | |
| 715 Object::ToObject(isolate, args.at<Object>(0)); | |
| 716 if (!maybe_object.ToHandle(&extension_object)) { | |
| 717 Handle<Object> handle = args.at<Object>(0); | |
| 718 THROW_NEW_ERROR_RETURN_FAILURE( | |
| 719 isolate, NewTypeError(MessageTemplate::kWithExpression, handle)); | |
| 720 } | |
| 721 } | 715 } |
| 722 | |
| 723 Handle<JSFunction> function; | |
| 724 if (args[1]->IsSmi()) { | |
| 725 // A smi sentinel indicates a context nested inside global code rather | |
| 726 // than some function. There is a canonical empty function that can be | |
| 727 // gotten from the native context. | |
| 728 function = handle(isolate->native_context()->closure()); | |
| 729 } else { | |
| 730 function = args.at<JSFunction>(1); | |
| 731 } | |
| 732 | |
| 733 Handle<Context> current(isolate->context()); | 716 Handle<Context> current(isolate->context()); |
| 734 Handle<Context> context = | 717 Handle<Context> context = |
| 735 isolate->factory()->NewWithContext(function, current, extension_object); | 718 isolate->factory()->NewWithContext(function, current, extension_object); |
| 736 isolate->set_context(*context); | 719 isolate->set_context(*context); |
| 737 return *context; | 720 return *context; |
| 738 } | 721 } |
| 739 | 722 |
| 740 | 723 |
| 741 RUNTIME_FUNCTION(Runtime_PushCatchContext) { | 724 RUNTIME_FUNCTION(Runtime_PushCatchContext) { |
| 742 HandleScope scope(isolate); | 725 HandleScope scope(isolate); |
| 743 DCHECK(args.length() == 3); | 726 DCHECK_EQ(3, args.length()); |
| 744 CONVERT_ARG_HANDLE_CHECKED(String, name, 0); | 727 CONVERT_ARG_HANDLE_CHECKED(String, name, 0); |
| 745 CONVERT_ARG_HANDLE_CHECKED(Object, thrown_object, 1); | 728 CONVERT_ARG_HANDLE_CHECKED(Object, thrown_object, 1); |
| 746 Handle<JSFunction> function; | 729 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 2); |
| 747 if (args[2]->IsSmi()) { | |
| 748 // A smi sentinel indicates a context nested inside global code rather | |
| 749 // than some function. There is a canonical empty function that can be | |
| 750 // gotten from the native context. | |
| 751 function = handle(isolate->native_context()->closure()); | |
| 752 } else { | |
| 753 function = args.at<JSFunction>(2); | |
| 754 } | |
| 755 Handle<Context> current(isolate->context()); | 730 Handle<Context> current(isolate->context()); |
| 756 Handle<Context> context = isolate->factory()->NewCatchContext( | 731 Handle<Context> context = isolate->factory()->NewCatchContext( |
| 757 function, current, name, thrown_object); | 732 function, current, name, thrown_object); |
| 758 isolate->set_context(*context); | 733 isolate->set_context(*context); |
| 759 return *context; | 734 return *context; |
| 760 } | 735 } |
| 761 | 736 |
| 762 | 737 |
| 763 RUNTIME_FUNCTION(Runtime_PushBlockContext) { | 738 RUNTIME_FUNCTION(Runtime_PushBlockContext) { |
| 764 HandleScope scope(isolate); | 739 HandleScope scope(isolate); |
| 765 DCHECK(args.length() == 2); | 740 DCHECK_EQ(2, args.length()); |
| 766 CONVERT_ARG_HANDLE_CHECKED(ScopeInfo, scope_info, 0); | 741 CONVERT_ARG_HANDLE_CHECKED(ScopeInfo, scope_info, 0); |
| 767 Handle<JSFunction> function; | 742 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 1); |
| 768 if (args[1]->IsSmi()) { | |
| 769 // A smi sentinel indicates a context nested inside global code rather | |
| 770 // than some function. There is a canonical empty function that can be | |
| 771 // gotten from the native context. | |
| 772 function = handle(isolate->native_context()->closure()); | |
| 773 } else { | |
| 774 function = args.at<JSFunction>(1); | |
| 775 } | |
| 776 Handle<Context> current(isolate->context()); | 743 Handle<Context> current(isolate->context()); |
| 777 Handle<Context> context = | 744 Handle<Context> context = |
| 778 isolate->factory()->NewBlockContext(function, current, scope_info); | 745 isolate->factory()->NewBlockContext(function, current, scope_info); |
| 779 isolate->set_context(*context); | 746 isolate->set_context(*context); |
| 780 return *context; | 747 return *context; |
| 781 } | 748 } |
| 782 | 749 |
| 783 | 750 |
| 784 RUNTIME_FUNCTION(Runtime_IsJSModule) { | 751 RUNTIME_FUNCTION(Runtime_IsJSModule) { |
| 785 SealHandleScope shs(isolate); | 752 SealHandleScope shs(isolate); |
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1166 | 1133 |
| 1167 // Lookup in the initial Object.prototype object. | 1134 // Lookup in the initial Object.prototype object. |
| 1168 Handle<Object> result; | 1135 Handle<Object> result; |
| 1169 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 1136 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 1170 isolate, result, | 1137 isolate, result, |
| 1171 Object::GetProperty(isolate->initial_object_prototype(), key)); | 1138 Object::GetProperty(isolate->initial_object_prototype(), key)); |
| 1172 return *result; | 1139 return *result; |
| 1173 } | 1140 } |
| 1174 } // namespace internal | 1141 } // namespace internal |
| 1175 } // namespace v8 | 1142 } // namespace v8 |
| OLD | NEW |