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 736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
747 Handle<JSArrayBuffer> ret = isolate->factory()->NewJSArrayBuffer(); | 747 Handle<JSArrayBuffer> ret = isolate->factory()->NewJSArrayBuffer(); |
748 JSArrayBuffer::Setup(ret, isolate, false, buff, data->length()); | 748 JSArrayBuffer::Setup(ret, isolate, false, buff, data->length()); |
749 memcpy(buff, data->data(), data->length()); | 749 memcpy(buff, data->data(), data->length()); |
750 return *ret; | 750 return *ret; |
751 } | 751 } |
752 | 752 |
753 // Take an array buffer and attempt to reconstruct a compiled wasm module. | 753 // Take an array buffer and attempt to reconstruct a compiled wasm module. |
754 // Return undefined if unsuccessful. | 754 // Return undefined if unsuccessful. |
755 RUNTIME_FUNCTION(Runtime_DeserializeWasmModule) { | 755 RUNTIME_FUNCTION(Runtime_DeserializeWasmModule) { |
756 HandleScope shs(isolate); | 756 HandleScope shs(isolate); |
757 DCHECK(args.length() == 1); | 757 DCHECK(args.length() == 2); |
758 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, buffer, 0); | 758 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, buffer, 0); |
759 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, wire_bytes, 1); | |
759 | 760 |
760 Address mem_start = static_cast<Address>(buffer->backing_store()); | 761 Address mem_start = static_cast<Address>(buffer->backing_store()); |
761 int mem_size = static_cast<int>(buffer->byte_length()->Number()); | 762 int mem_size = static_cast<int>(buffer->byte_length()->Number()); |
762 | 763 |
764 // DeserializeWasmModule will allocate. We assume JSArrayBuffer doesn't | |
765 // get relocated. | |
763 ScriptData sc(mem_start, mem_size); | 766 ScriptData sc(mem_start, mem_size); |
764 MaybeHandle<FixedArray> maybe_compiled_module = | 767 MaybeHandle<FixedArray> maybe_compiled_module = |
765 WasmCompiledModuleSerializer::DeserializeWasmModule(isolate, &sc); | 768 WasmCompiledModuleSerializer::DeserializeWasmModule( |
769 isolate, &sc, | |
770 Vector<const uint8_t>( | |
771 reinterpret_cast<uint8_t*>(wire_bytes->backing_store()), | |
titzer
2016/10/20 08:32:08
This raw pointer is unsafe unless the buffer is ex
Mircea Trofin
2016/10/20 16:06:41
Done, and added mlippautz to double-check this is
| |
772 static_cast<int>(wire_bytes->byte_length()->Number()))); | |
773 | |
766 Handle<FixedArray> compiled_module; | 774 Handle<FixedArray> compiled_module; |
767 if (!maybe_compiled_module.ToHandle(&compiled_module)) { | 775 if (!maybe_compiled_module.ToHandle(&compiled_module)) { |
768 return isolate->heap()->undefined_value(); | 776 return isolate->heap()->undefined_value(); |
769 } | 777 } |
770 return *wasm::CreateWasmModuleObject( | 778 return *wasm::CreateWasmModuleObject( |
771 isolate, Handle<wasm::WasmCompiledModule>::cast(compiled_module), | 779 isolate, Handle<wasm::WasmCompiledModule>::cast(compiled_module), |
772 wasm::kWasmOrigin); | 780 wasm::kWasmOrigin); |
773 } | 781 } |
774 | 782 |
775 RUNTIME_FUNCTION(Runtime_ValidateWasmInstancesChain) { | 783 RUNTIME_FUNCTION(Runtime_ValidateWasmInstancesChain) { |
(...skipping 17 matching lines...) Expand all Loading... | |
793 RUNTIME_FUNCTION(Runtime_ValidateWasmOrphanedInstance) { | 801 RUNTIME_FUNCTION(Runtime_ValidateWasmOrphanedInstance) { |
794 HandleScope shs(isolate); | 802 HandleScope shs(isolate); |
795 DCHECK(args.length() == 1); | 803 DCHECK(args.length() == 1); |
796 CONVERT_ARG_HANDLE_CHECKED(JSObject, instance_obj, 0); | 804 CONVERT_ARG_HANDLE_CHECKED(JSObject, instance_obj, 0); |
797 wasm::testing::ValidateOrphanedInstance(isolate, instance_obj); | 805 wasm::testing::ValidateOrphanedInstance(isolate, instance_obj); |
798 return isolate->heap()->ToBoolean(true); | 806 return isolate->heap()->ToBoolean(true); |
799 } | 807 } |
800 | 808 |
801 } // namespace internal | 809 } // namespace internal |
802 } // namespace v8 | 810 } // namespace v8 |
OLD | NEW |