Index: src/wasm/wasm-module.cc |
diff --git a/src/wasm/wasm-module.cc b/src/wasm/wasm-module.cc |
index df99e93e6169db06b8de88febb17d372178c6e5e..40015a70e161c889906896a242e94d7b4fa399b9 100644 |
--- a/src/wasm/wasm-module.cc |
+++ b/src/wasm/wasm-module.cc |
@@ -2604,6 +2604,44 @@ |
instance_object.ToHandleChecked()); |
} |
+void wasm::AsyncCompileAndInstantiate(Isolate* isolate, |
+ Handle<JSPromise> promise, |
+ const ModuleWireBytes& bytes, |
+ MaybeHandle<JSReceiver> imports) { |
+ ErrorThrower thrower(isolate, nullptr); |
+ |
+ // Compile the module. |
+ MaybeHandle<WasmModuleObject> module_object = |
+ SyncCompile(isolate, &thrower, bytes); |
+ if (thrower.error()) { |
+ RejectPromise(isolate, handle(isolate->context()), &thrower, promise); |
+ return; |
+ } |
+ Handle<WasmModuleObject> module = module_object.ToHandleChecked(); |
+ |
+ // Instantiate the module. |
+ MaybeHandle<WasmInstanceObject> instance_object = SyncInstantiate( |
+ isolate, &thrower, module, imports, Handle<JSArrayBuffer>::null()); |
+ if (thrower.error()) { |
+ RejectPromise(isolate, handle(isolate->context()), &thrower, promise); |
+ return; |
+ } |
+ |
+ Handle<JSFunction> object_function = |
+ Handle<JSFunction>(isolate->native_context()->object_function(), isolate); |
+ Handle<JSObject> ret = |
+ isolate->factory()->NewJSObject(object_function, TENURED); |
+ Handle<String> module_property_name = |
+ isolate->factory()->InternalizeUtf8String("module"); |
+ Handle<String> instance_property_name = |
+ isolate->factory()->InternalizeUtf8String("instance"); |
+ JSObject::AddProperty(ret, module_property_name, module, NONE); |
+ JSObject::AddProperty(ret, instance_property_name, |
+ instance_object.ToHandleChecked(), NONE); |
+ |
+ ResolvePromise(isolate, handle(isolate->context()), promise, ret); |
+} |
+ |
// Encapsulates all the state and steps of an asynchronous compilation. |
// An asynchronous compile job consists of a number of tasks that are executed |
// as foreground and background tasks. Any phase that touches the V8 heap or |