Commit fb096eea authored by Mircea Trofin's avatar Mircea Trofin Committed by Commit Bot

[wasm] Refactor implementation of {instantiate|compile}Streaming

This places in the scaffolding for completely relying on the embedder
for these APIs. Once Chrome uses these instead of the old APIs,
we can cleanup further by removing the old callback insertion points
and not exposing the streaming APIs if callbacks aren't provided.

Bug: 
Cq-Include-Trybots: master.tryserver.chromium.linux:linux_chromium_rel_ng
Change-Id: I15abd257257be512674b18aa4af2e0a0153612a5
Reviewed-on: https://chromium-review.googlesource.com/520602
Commit-Queue: Brad Nelson <bradnelson@chromium.org>
Reviewed-by: 's avatarBrad Nelson <bradnelson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#45696}
parent 90b68baa
...@@ -6207,6 +6207,10 @@ typedef bool (*AllowCodeGenerationFromStringsCallback)(Local<Context> context); ...@@ -6207,6 +6207,10 @@ typedef bool (*AllowCodeGenerationFromStringsCallback)(Local<Context> context);
// --- WASM compilation callbacks --- // --- WASM compilation callbacks ---
typedef bool (*ExtensionCallback)(const FunctionCallbackInfo<Value>&); typedef bool (*ExtensionCallback)(const FunctionCallbackInfo<Value>&);
// --- Callback for APIs defined on v8-supported objects, but implemented
// by the embedder. Example: WebAssembly.{compile|instantiate}Streaming ---
typedef void (*ApiImplementationCallback)(const FunctionCallbackInfo<Value>&);
// --- Garbage Collection Callbacks --- // --- Garbage Collection Callbacks ---
/** /**
...@@ -7477,6 +7481,8 @@ class V8_EXPORT Isolate { ...@@ -7477,6 +7481,8 @@ class V8_EXPORT Isolate {
void SetWasmInstanceCallback(ExtensionCallback callback); void SetWasmInstanceCallback(ExtensionCallback callback);
void SetWasmInstantiateCallback(ExtensionCallback callback); void SetWasmInstantiateCallback(ExtensionCallback callback);
void SetWasmCompileStreamingCallback(ApiImplementationCallback callback);
/** /**
* Check if V8 is dead and therefore unusable. This is the case after * Check if V8 is dead and therefore unusable. This is the case after
* fatal errors such as out-of-memory situations. * fatal errors such as out-of-memory situations.
......
...@@ -8877,6 +8877,9 @@ CALLBACK_SETTER(WasmInstanceCallback, ExtensionCallback, wasm_instance_callback) ...@@ -8877,6 +8877,9 @@ CALLBACK_SETTER(WasmInstanceCallback, ExtensionCallback, wasm_instance_callback)
CALLBACK_SETTER(WasmInstantiateCallback, ExtensionCallback, CALLBACK_SETTER(WasmInstantiateCallback, ExtensionCallback,
wasm_instantiate_callback) wasm_instantiate_callback)
CALLBACK_SETTER(WasmCompileStreamingCallback, ApiImplementationCallback,
wasm_compile_streaming_callback)
bool Isolate::IsDead() { bool Isolate::IsDead() {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
return isolate->IsDead(); return isolate->IsDead();
......
...@@ -407,6 +407,7 @@ typedef std::vector<HeapObject*> DebugObjectCache; ...@@ -407,6 +407,7 @@ typedef std::vector<HeapObject*> DebugObjectCache;
V(ExtensionCallback, wasm_instance_callback, &NoExtension) \ V(ExtensionCallback, wasm_instance_callback, &NoExtension) \
V(ExtensionCallback, wasm_compile_callback, &NoExtension) \ V(ExtensionCallback, wasm_compile_callback, &NoExtension) \
V(ExtensionCallback, wasm_instantiate_callback, &NoExtension) \ V(ExtensionCallback, wasm_instantiate_callback, &NoExtension) \
V(ApiImplementationCallback, wasm_compile_streaming_callback, nullptr) \
V(ExternalReferenceRedirectorPointer*, external_reference_redirector, \ V(ExternalReferenceRedirectorPointer*, external_reference_redirector, \
nullptr) \ nullptr) \
/* State for Relocatable. */ \ /* State for Relocatable. */ \
......
...@@ -160,8 +160,12 @@ void WebAssemblyCompileStreaming( ...@@ -160,8 +160,12 @@ void WebAssemblyCompileStreaming(
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
MicrotasksScope runs_microtasks(isolate, MicrotasksScope::kRunMicrotasks); MicrotasksScope runs_microtasks(isolate, MicrotasksScope::kRunMicrotasks);
if (!i_isolate->wasm_compile_callback()(args)) { if (!i_isolate->wasm_compile_callback()(args)) {
ErrorThrower thrower(i_isolate, "WebAssembly.compileStreaming()"); if (i_isolate->wasm_compile_streaming_callback() != nullptr) {
RejectResponseAPI(args, &thrower); i_isolate->wasm_compile_streaming_callback()(args);
} else {
ErrorThrower thrower(i_isolate, "WebAssembly.compileStreaming()");
RejectResponseAPI(args, &thrower);
}
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment