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 <memory> | 7 #include <memory> |
8 | 8 |
9 #include "src/arguments.h" | 9 #include "src/arguments.h" |
10 #include "src/compiler-dispatcher/optimizing-compile-dispatcher.h" | 10 #include "src/compiler-dispatcher/optimizing-compile-dispatcher.h" |
(...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
729 | 729 |
730 #undef FIXED_TYPED_ARRAYS_CHECK_RUNTIME_FUNCTION | 730 #undef FIXED_TYPED_ARRAYS_CHECK_RUNTIME_FUNCTION |
731 | 731 |
732 | 732 |
733 RUNTIME_FUNCTION(Runtime_SpeciesProtector) { | 733 RUNTIME_FUNCTION(Runtime_SpeciesProtector) { |
734 SealHandleScope shs(isolate); | 734 SealHandleScope shs(isolate); |
735 DCHECK_EQ(0, args.length()); | 735 DCHECK_EQ(0, args.length()); |
736 return isolate->heap()->ToBoolean(isolate->IsArraySpeciesLookupChainIntact()); | 736 return isolate->heap()->ToBoolean(isolate->IsArraySpeciesLookupChainIntact()); |
737 } | 737 } |
738 | 738 |
| 739 #define CONVERT_ARG_HANDLE_CHECKED_2(Type, name, index) \ |
| 740 CHECK(Type::Is##Type(args[index])); \ |
| 741 Handle<Type> name = args.at<Type>(index); |
| 742 |
739 // Take a compiled wasm module, serialize it and copy the buffer into an array | 743 // Take a compiled wasm module, serialize it and copy the buffer into an array |
740 // buffer, which is then returned. | 744 // buffer, which is then returned. |
741 RUNTIME_FUNCTION(Runtime_SerializeWasmModule) { | 745 RUNTIME_FUNCTION(Runtime_SerializeWasmModule) { |
742 HandleScope shs(isolate); | 746 HandleScope shs(isolate); |
743 DCHECK(args.length() == 1); | 747 DCHECK(args.length() == 1); |
744 CONVERT_ARG_HANDLE_CHECKED(JSObject, module_obj, 0); | 748 CONVERT_ARG_HANDLE_CHECKED_2(WasmModuleObject, module_obj, 0); |
745 | 749 |
746 Handle<FixedArray> orig = | 750 Handle<WasmCompiledModule> orig = handle(module_obj->get_compiled_module()); |
747 handle(FixedArray::cast(module_obj->GetInternalField(0))); | |
748 std::unique_ptr<ScriptData> data = | 751 std::unique_ptr<ScriptData> data = |
749 WasmCompiledModuleSerializer::SerializeWasmModule(isolate, orig); | 752 WasmCompiledModuleSerializer::SerializeWasmModule(isolate, orig); |
750 void* buff = isolate->array_buffer_allocator()->Allocate(data->length()); | 753 void* buff = isolate->array_buffer_allocator()->Allocate(data->length()); |
751 Handle<JSArrayBuffer> ret = isolate->factory()->NewJSArrayBuffer(); | 754 Handle<JSArrayBuffer> ret = isolate->factory()->NewJSArrayBuffer(); |
752 JSArrayBuffer::Setup(ret, isolate, false, buff, data->length()); | 755 JSArrayBuffer::Setup(ret, isolate, false, buff, data->length()); |
753 memcpy(buff, data->data(), data->length()); | 756 memcpy(buff, data->data(), data->length()); |
754 return *ret; | 757 return *ret; |
755 } | 758 } |
756 | 759 |
757 // Take an array buffer and attempt to reconstruct a compiled wasm module. | 760 // Take an array buffer and attempt to reconstruct a compiled wasm module. |
(...skipping 29 matching lines...) Expand all Loading... |
787 if (!maybe_compiled_module.ToHandle(&compiled_module)) { | 790 if (!maybe_compiled_module.ToHandle(&compiled_module)) { |
788 return isolate->heap()->undefined_value(); | 791 return isolate->heap()->undefined_value(); |
789 } | 792 } |
790 return *WasmModuleObject::New( | 793 return *WasmModuleObject::New( |
791 isolate, Handle<WasmCompiledModule>::cast(compiled_module)); | 794 isolate, Handle<WasmCompiledModule>::cast(compiled_module)); |
792 } | 795 } |
793 | 796 |
794 RUNTIME_FUNCTION(Runtime_ValidateWasmInstancesChain) { | 797 RUNTIME_FUNCTION(Runtime_ValidateWasmInstancesChain) { |
795 HandleScope shs(isolate); | 798 HandleScope shs(isolate); |
796 DCHECK(args.length() == 2); | 799 DCHECK(args.length() == 2); |
797 CONVERT_ARG_HANDLE_CHECKED(JSObject, module_obj, 0); | 800 CONVERT_ARG_HANDLE_CHECKED_2(WasmModuleObject, module_obj, 0); |
798 CONVERT_ARG_HANDLE_CHECKED(Smi, instance_count, 1); | 801 CONVERT_ARG_HANDLE_CHECKED(Smi, instance_count, 1); |
799 wasm::testing::ValidateInstancesChain(isolate, module_obj, | 802 wasm::testing::ValidateInstancesChain(isolate, module_obj, |
800 instance_count->value()); | 803 instance_count->value()); |
801 return isolate->heap()->ToBoolean(true); | 804 return isolate->heap()->ToBoolean(true); |
802 } | 805 } |
803 | 806 |
804 RUNTIME_FUNCTION(Runtime_ValidateWasmModuleState) { | 807 RUNTIME_FUNCTION(Runtime_ValidateWasmModuleState) { |
805 HandleScope shs(isolate); | 808 HandleScope shs(isolate); |
806 DCHECK(args.length() == 1); | 809 DCHECK(args.length() == 1); |
807 CONVERT_ARG_HANDLE_CHECKED(JSObject, module_obj, 0); | 810 CONVERT_ARG_HANDLE_CHECKED_2(WasmModuleObject, module_obj, 0); |
808 wasm::testing::ValidateModuleState(isolate, module_obj); | 811 wasm::testing::ValidateModuleState(isolate, module_obj); |
809 return isolate->heap()->ToBoolean(true); | 812 return isolate->heap()->ToBoolean(true); |
810 } | 813 } |
811 | 814 |
812 RUNTIME_FUNCTION(Runtime_ValidateWasmOrphanedInstance) { | 815 RUNTIME_FUNCTION(Runtime_ValidateWasmOrphanedInstance) { |
813 HandleScope shs(isolate); | 816 HandleScope shs(isolate); |
814 DCHECK(args.length() == 1); | 817 DCHECK(args.length() == 1); |
815 CONVERT_ARG_HANDLE_CHECKED(JSObject, instance_obj, 0); | 818 CONVERT_ARG_HANDLE_CHECKED_2(WasmInstanceObject, instance, 0); |
816 wasm::testing::ValidateOrphanedInstance(isolate, instance_obj); | 819 wasm::testing::ValidateOrphanedInstance(isolate, instance); |
817 return isolate->heap()->ToBoolean(true); | 820 return isolate->heap()->ToBoolean(true); |
818 } | 821 } |
819 | 822 |
820 } // namespace internal | 823 } // namespace internal |
821 } // namespace v8 | 824 } // namespace v8 |
OLD | NEW |