Index: src/api.cc |
diff --git a/src/api.cc b/src/api.cc |
index a29d294fafd6ca7fbbd5b6d57b6ea5ba5b7f8e50..361472b073655e93a4824f4283853e7f4c548425 100644 |
--- a/src/api.cc |
+++ b/src/api.cc |
@@ -60,6 +60,7 @@ |
#include "src/runtime-profiler.h" |
#include "src/runtime/runtime.h" |
#include "src/simulator.h" |
+#include "src/snapshot/code-serializer.h" |
#include "src/snapshot/natives.h" |
#include "src/snapshot/snapshot.h" |
#include "src/startup-data-util.h" |
@@ -69,6 +70,7 @@ |
#include "src/v8threads.h" |
#include "src/version.h" |
#include "src/vm-state-inl.h" |
+#include "src/wasm/wasm-module.h" |
namespace v8 { |
@@ -2952,7 +2954,11 @@ bool Value::IsNumber() const { |
bool Value::IsProxy() const { return Utils::OpenHandle(this)->IsJSProxy(); } |
bool Value::IsWebAssemblyCompiledModule() const { |
- return Utils::OpenHandle(this)->IsWebAssemblyCompiledModule(); |
+ i::Handle<i::Object> obj = Utils::OpenHandle(this); |
+ if (!obj->IsJSObject()) return false; |
+ i::Handle<i::JSObject> js_obj = i::Handle<i::JSObject>::cast(obj); |
+ return js_obj->GetIsolate()->native_context()->wasm_module_constructor() == |
+ js_obj->map()->GetConstructor(); |
} |
#define VALUE_IS_SPECIFIC_TYPE(Type, Class) \ |
@@ -3296,6 +3302,11 @@ void v8::Proxy::CheckCast(Value* that) { |
"Could not convert to proxy"); |
} |
+void v8::WasmCompiledModule::CheckCast(Value* that) { |
+ Utils::ApiCheck(that->IsWebAssemblyCompiledModule(), |
+ "v8::WasmCompiledModule::Cast", |
+ "Could not convert to wasm compiled module"); |
+} |
void v8::ArrayBuffer::CheckCast(Value* that) { |
i::Handle<i::Object> obj = Utils::OpenHandle(that); |
@@ -6821,6 +6832,35 @@ MaybeLocal<Proxy> Proxy::New(Local<Context> context, Local<Object> local_target, |
RETURN_ESCAPED(result); |
} |
+WasmCompiledModule::SerializedModule WasmCompiledModule::Serialize() { |
+ i::Handle<i::JSObject> obj = |
+ i::Handle<i::JSObject>::cast(Utils::OpenHandle(this)); |
+ i::Handle<i::FixedArray> compiled_part = |
+ i::handle(i::FixedArray::cast(obj->GetInternalField(0))); |
+ std::unique_ptr<i::ScriptData> script_data = |
+ i::WasmCompiledModuleSerializer::SerializeWasmModule(obj->GetIsolate(), |
+ compiled_part); |
+ size_t size = static_cast<size_t>(script_data->length()); |
+ script_data.release(); |
+ return {std::unique_ptr<const uint8_t[]>(script_data->data()), size}; |
+} |
+ |
+MaybeLocal<WasmCompiledModule> WasmCompiledModule::Deserialize( |
+ Isolate* isolate, |
+ const WasmCompiledModule::SerializedModule serialized_data) { |
+ int size = static_cast<int>(serialized_data.second); |
+ i::ScriptData sc(serialized_data.first.get(), size); |
+ i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
+ i::MaybeHandle<i::FixedArray> maybe_compiled_part = |
+ i::WasmCompiledModuleSerializer::DeserializeWasmModule(i_isolate, &sc); |
+ i::Handle<i::FixedArray> compiled_part; |
+ if (!maybe_compiled_part.ToHandle(&compiled_part)) { |
+ return MaybeLocal<WasmCompiledModule>(); |
+ } |
+ return Local<WasmCompiledModule>::Cast(Utils::ToLocal( |
+ i::wasm::CreateCompiledModuleObject(i_isolate, compiled_part))); |
+} |
+ |
// static |
v8::ArrayBuffer::Allocator* v8::ArrayBuffer::Allocator::NewDefaultAllocator() { |
return new ArrayBufferAllocator(); |