Commit 50e142c9 authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[wasm] Simplify Runtime_DeserializeWasmModule implementation.

R=herhut@chromium.org

Change-Id: I572a240f0d8f4598e3b4357d50329bcdafd7c60c
Reviewed-on: https://chromium-review.googlesource.com/1186585Reviewed-by: 's avatarStephan Herhut <herhut@chromium.org>
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55362}
parent 524215be
...@@ -916,7 +916,7 @@ RUNTIME_FUNCTION(Runtime_PromiseSpeciesProtector) { ...@@ -916,7 +916,7 @@ RUNTIME_FUNCTION(Runtime_PromiseSpeciesProtector) {
// Take a compiled wasm module and serialize it into an array buffer, which is // Take a compiled wasm module and serialize it into an array buffer, which is
// then returned. // then returned.
RUNTIME_FUNCTION(Runtime_SerializeWasmModule) { RUNTIME_FUNCTION(Runtime_SerializeWasmModule) {
HandleScope shs(isolate); HandleScope scope(isolate);
DCHECK_EQ(1, args.length()); DCHECK_EQ(1, args.length());
CONVERT_ARG_HANDLE_CHECKED(WasmModuleObject, module_obj, 0); CONVERT_ARG_HANDLE_CHECKED(WasmModuleObject, module_obj, 0);
...@@ -937,31 +937,20 @@ RUNTIME_FUNCTION(Runtime_SerializeWasmModule) { ...@@ -937,31 +937,20 @@ RUNTIME_FUNCTION(Runtime_SerializeWasmModule) {
// Take an array buffer and attempt to reconstruct a compiled wasm module. // Take an array buffer and attempt to reconstruct a compiled wasm module.
// Return undefined if unsuccessful. // Return undefined if unsuccessful.
RUNTIME_FUNCTION(Runtime_DeserializeWasmModule) { RUNTIME_FUNCTION(Runtime_DeserializeWasmModule) {
HandleScope shs(isolate); HandleScope scope(isolate);
DCHECK_EQ(2, args.length()); DCHECK_EQ(2, args.length());
CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, buffer, 0); CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, buffer, 0);
CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, wire_bytes, 1); CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, wire_bytes, 1);
uint8_t* mem_start = reinterpret_cast<uint8_t*>(buffer->backing_store());
size_t mem_size = static_cast<size_t>(buffer->byte_length()->Number());
// Note that {wasm::DeserializeNativeModule} will allocate. We assume the // Note that {wasm::DeserializeNativeModule} will allocate. We assume the
// JSArrayBuffer doesn't get relocated. // JSArrayBuffer backing store doesn't get relocated.
bool already_external = wire_bytes->is_external();
if (!already_external) {
wire_bytes->set_is_external(true);
isolate->heap()->UnregisterArrayBuffer(*wire_bytes);
}
MaybeHandle<WasmModuleObject> maybe_module_object = MaybeHandle<WasmModuleObject> maybe_module_object =
wasm::DeserializeNativeModule( wasm::DeserializeNativeModule(
isolate, {mem_start, mem_size}, isolate,
Vector<const uint8_t>( {reinterpret_cast<uint8_t*>(buffer->backing_store()),
reinterpret_cast<uint8_t*>(wire_bytes->backing_store()), static_cast<size_t>(buffer->byte_length()->Number())},
static_cast<int>(wire_bytes->byte_length()->Number()))); {reinterpret_cast<uint8_t*>(wire_bytes->backing_store()),
if (!already_external) { static_cast<size_t>(wire_bytes->byte_length()->Number())});
wire_bytes->set_is_external(false);
isolate->heap()->RegisterNewArrayBuffer(*wire_bytes);
}
Handle<WasmModuleObject> module_object; Handle<WasmModuleObject> module_object;
if (!maybe_module_object.ToHandle(&module_object)) { if (!maybe_module_object.ToHandle(&module_object)) {
return ReadOnlyRoots(isolate).undefined_value(); return ReadOnlyRoots(isolate).undefined_value();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment