@@ -3732,6 +3732,37 @@ bool AllowWasmCodeGenerationCallback(
3732
3732
return wasm_code_gen->IsUndefined () || wasm_code_gen->IsTrue ();
3733
3733
}
3734
3734
3735
+ void WasmCreateModule (const FunctionCallbackInfo<Value>& info) {
3736
+ Environment* env = Environment::GetCurrent (info.GetIsolate ());
3737
+ Local<Context> context = env->context ();
3738
+ Local<Value> buffer = info[0 ];
3739
+ CHECK (!buffer.IsEmpty ());
3740
+
3741
+ Local<Object> wasm = Local<Object>::Cast (
3742
+ context->Global ()->Get (context, env->webassembly_string ())
3743
+ .ToLocalChecked ());
3744
+ Local<Function> module = Local<Function>::Cast (wasm->Get (context,
3745
+ env->module_string ()).ToLocalChecked ());
3746
+ Local<Value> args[] = {buffer};
3747
+ Local<Value> module_instance = module->NewInstance (context, 1 , args)
3748
+ .ToLocalChecked ();
3749
+ info.GetReturnValue ().Set (module_instance);
3750
+ }
3751
+
3752
+ void WasmInstantiateStreamingCallback (const FunctionCallbackInfo<Value>& info) {
3753
+ Environment* env = Environment::GetCurrent (info.GetIsolate ());
3754
+ Local<Context> context = env->context ();
3755
+ CHECK (!info[0 ]->IsUndefined ());
3756
+ CHECK (info[0 ]->IsPromise ());
3757
+ Local<Promise> buffer_promise = info[0 ].As <Promise>();
3758
+
3759
+ Local<Function> create_module = Function::New (context, WasmCreateModule)
3760
+ .ToLocalChecked ();
3761
+ Local<Promise> module_promise = buffer_promise->Then (context, create_module)
3762
+ .ToLocalChecked ();
3763
+ info.GetReturnValue ().Set (module_promise);
3764
+ }
3765
+
3735
3766
Isolate* NewIsolate (ArrayBufferAllocator* allocator) {
3736
3767
Isolate::CreateParams params;
3737
3768
params.array_buffer_allocator = allocator;
@@ -3748,6 +3779,7 @@ Isolate* NewIsolate(ArrayBufferAllocator* allocator) {
3748
3779
isolate->SetMicrotasksPolicy (v8::MicrotasksPolicy::kExplicit );
3749
3780
isolate->SetFatalErrorHandler (OnFatalError);
3750
3781
isolate->SetAllowWasmCodeGenerationCallback (AllowWasmCodeGenerationCallback);
3782
+ isolate->SetWasmCompileStreamingCallback (WasmInstantiateStreamingCallback);
3751
3783
3752
3784
return isolate;
3753
3785
}
0 commit comments