Index: src/api.cc |
diff --git a/src/api.cc b/src/api.cc |
index 9337708dcf0f7b3985b580c2208edde485fc88e5..74b1511a20ae2a9d17d73d3d35bfb543d4d53ef6 100644 |
--- a/src/api.cc |
+++ b/src/api.cc |
@@ -3131,6 +3131,15 @@ Maybe<uint32_t> ValueSerializer::Delegate::GetSharedArrayBufferId( |
return Nothing<uint32_t>(); |
} |
+Maybe<uint32_t> ValueSerializer::Delegate::GetWasmModuleTransferId( |
+ Isolate* v8_isolate, Local<WasmCompiledModule> module) { |
+ i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); |
+ isolate->ScheduleThrow(*isolate->factory()->NewError( |
+ isolate->error_function(), i::MessageTemplate::kDataCloneError, |
+ Utils::OpenHandle(*module))); |
+ return Nothing<uint32_t>(); |
+} |
+ |
void* ValueSerializer::Delegate::ReallocateBufferMemory(void* old_buffer, |
size_t size, |
size_t* actual_size) { |
@@ -3281,6 +3290,10 @@ void ValueDeserializer::SetSupportsLegacyWireFormat( |
private_->supports_legacy_wire_format = supports_legacy_wire_format; |
} |
+void ValueDeserializer::SetAllowInlineWasm(bool allow_inline_wasm) { |
+ private_->deserializer.set_allow_inline_wasm(allow_inline_wasm); |
+} |
+ |
uint32_t ValueDeserializer::GetWireFormatVersion() const { |
CHECK(!private_->has_aborted); |
return private_->deserializer.GetWireFormatVersion(); |
@@ -3316,6 +3329,14 @@ void ValueDeserializer::TransferSharedArrayBuffer( |
transfer_id, Utils::OpenHandle(*shared_array_buffer)); |
} |
+void ValueDeserializer::TransferWasmCompiledModule( |
+ uint32_t transfer_id, Local<WasmCompiledModule> module) { |
+ CHECK(!private_->has_aborted); |
+ private_->deserializer.TransferWasmModule( |
+ transfer_id, |
+ i::Handle<i::WasmModuleObject>::cast(Utils::OpenHandle(*module))); |
+} |
+ |
bool ValueDeserializer::ReadUint32(uint32_t* value) { |
return private_->deserializer.ReadUint32(value); |
} |
@@ -7517,6 +7538,36 @@ Local<String> WasmCompiledModule::GetWasmWireBytes() { |
return Local<String>::Cast(Utils::ToLocal(wire_bytes)); |
} |
+// Currently, wasm modules are bound, both to Isolate and to |
+// the Context they were created in. The currently-supported means to |
+// decontextualize and then re-contextualize a module is via |
+// serialization/deserialization. |
+WasmCompiledModule::TransferrableModule |
+WasmCompiledModule::GetTransferrableModule() { |
+ i::DisallowHeapAllocation no_gc; |
+ WasmCompiledModule::SerializedModule compiled_part = Serialize(); |
+ |
+ Local<String> wire_bytes = GetWasmWireBytes(); |
+ size_t wire_size = static_cast<size_t>(wire_bytes->Length()); |
+ uint8_t* bytes = new uint8_t[wire_size]; |
+ wire_bytes->WriteOneByte(bytes, 0, wire_bytes->Length()); |
+ |
+ return TransferrableModule( |
+ std::move(compiled_part), |
+ std::make_pair( |
+ std::unique_ptr<const uint8_t[]>(const_cast<const uint8_t*>(bytes)), |
+ wire_size)); |
+} |
+ |
+MaybeLocal<WasmCompiledModule> WasmCompiledModule::FromTransferrableModule( |
+ Isolate* isolate, |
+ const WasmCompiledModule::TransferrableModule& transferrable_module) { |
+ MaybeLocal<WasmCompiledModule> ret = |
+ Deserialize(isolate, AsCallerOwned(transferrable_module.compiled_code), |
+ AsCallerOwned(transferrable_module.wire_bytes)); |
+ return ret; |
+} |
+ |
WasmCompiledModule::SerializedModule WasmCompiledModule::Serialize() { |
i::Handle<i::JSObject> obj = |
i::Handle<i::JSObject>::cast(Utils::OpenHandle(this)); |