Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Unified Diff: src/api.cc

Issue 2748473004: [wasm] Transferrable modules (Closed)
Patch Set: Transferrable modules Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index 38668efba1c616cacd3cb8f98a86867163333d9c..a9612da050c4ff763da26717961fc30685194a74 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -3143,6 +3143,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) {
@@ -3231,6 +3240,15 @@ MaybeLocal<Object> ValueDeserializer::Delegate::ReadHostObject(
return MaybeLocal<Object>();
}
+MaybeLocal<WasmCompiledModule> ValueDeserializer::Delegate::GetWasmModuleFromId(
+ Isolate* v8_isolate, uint32_t id) {
+ i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
+ isolate->ScheduleThrow(*isolate->factory()->NewError(
+ isolate->error_function(),
+ i::MessageTemplate::kDataCloneDeserializationError));
+ return MaybeLocal<WasmCompiledModule>();
+}
+
struct ValueDeserializer::PrivateData {
PrivateData(i::Isolate* i, i::Vector<const uint8_t> data, Delegate* delegate)
: isolate(i), deserializer(i, data, delegate) {}
@@ -7519,6 +7537,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::AsTransferrableModule() {
+ 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,
+ 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));

Powered by Google App Engine
This is Rietveld 408576698