diff --git a/src/asmjs/asm-js.cc b/src/asmjs/asm-js.cc index 4521403b5a..a6c499c790 100644 --- a/src/asmjs/asm-js.cc +++ b/src/asmjs/asm-js.cc @@ -74,14 +74,14 @@ MaybeHandle AsmJs::ConvertAsmToWasm(ParseInfo* info) { info->literal(), &typer); i::Handle foreign_globals; auto module = builder.Run(&foreign_globals); - size_t byte_length = module->end() - module->begin(); - Handle buffer = info->isolate()->factory()->NewJSArrayBuffer(); - JSArrayBuffer::SetupAllocatingData(buffer, info->isolate(), byte_length, - false, SharedFlag::kNotShared); - uint8_t* module_bytes = reinterpret_cast(buffer->backing_store()); - memcpy(module_bytes, module->begin(), byte_length); + + i::MaybeHandle compiled = + CompileModule(info->isolate(), module->begin(), module->end(), &thrower, + internal::wasm::kAsmJsOrigin); + DCHECK(!compiled.is_null()); + Handle result = info->isolate()->factory()->NewFixedArray(2); - result->set(0, *buffer); + result->set(0, *compiled.ToHandleChecked()); result->set(1, *foreign_globals); return result; } @@ -90,27 +90,14 @@ MaybeHandle AsmJs::InstantiateAsmWasm(i::Isolate* isolate, Handle wasm_data, Handle memory, Handle foreign) { - i::Handle module_bytes( - i::JSArrayBuffer::cast(wasm_data->get(0))); + i::Handle compiled(i::FixedArray::cast(wasm_data->get(0))); i::Handle foreign_globals( i::FixedArray::cast(wasm_data->get(1))); ErrorThrower thrower(isolate, "Asm.js -> WebAssembly instantiation"); - const byte* module_start = - reinterpret_cast(module_bytes->backing_store()); - size_t module_length = - static_cast(module_bytes->byte_length()->Number()); - const byte* module_end = module_start + module_length; - i::MaybeHandle compiled = - CompileModule(isolate, module_start, module_end, &thrower, - internal::wasm::kAsmJsOrigin); - if (compiled.is_null()) { - return MaybeHandle(); - } i::MaybeHandle maybe_module_object = - i::wasm::WasmModule::Instantiate(isolate, compiled.ToHandleChecked(), - foreign, memory); + i::wasm::WasmModule::Instantiate(isolate, compiled, foreign, memory); if (maybe_module_object.is_null()) { return MaybeHandle(); }