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

[wasm] Remove support for overloading async APIs.

This wraps up the move to explicit APIs, i.e.
instantiateStreaming/compileStreaming.

Bug: 
Cq-Include-Trybots: master.tryserver.chromium.linux:linux_chromium_rel_ng
Change-Id: Icc8280b2b3ad35acb90cc0beebe3acd7581179d7
Reviewed-on: https://chromium-review.googlesource.com/525141
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Commit-Queue: Brad Nelson <bradnelson@chromium.org>
Reviewed-by: 's avatarBrad Nelson <bradnelson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#45719}
parent da449677
......@@ -7474,12 +7474,11 @@ class V8_EXPORT Isolate {
AllowCodeGenerationFromStringsCallback callback);
/**
* Embedder over{ride|load} injection points for wasm APIs.
* Embedder over{ride|load} injection points for wasm APIs. The expectation
* is that the embedder sets them at most once.
*/
void SetWasmModuleCallback(ExtensionCallback callback);
void SetWasmCompileCallback(ExtensionCallback callback);
void SetWasmInstanceCallback(ExtensionCallback callback);
void SetWasmInstantiateCallback(ExtensionCallback callback);
void SetWasmCompileStreamingCallback(ApiImplementationCallback callback);
......
......@@ -8872,10 +8872,7 @@ void Isolate::SetAllowCodeGenerationFromStringsCallback(
}
CALLBACK_SETTER(WasmModuleCallback, ExtensionCallback, wasm_module_callback)
CALLBACK_SETTER(WasmCompileCallback, ExtensionCallback, wasm_compile_callback)
CALLBACK_SETTER(WasmInstanceCallback, ExtensionCallback, wasm_instance_callback)
CALLBACK_SETTER(WasmInstantiateCallback, ExtensionCallback,
wasm_instantiate_callback)
CALLBACK_SETTER(WasmCompileStreamingCallback, ApiImplementationCallback,
wasm_compile_streaming_callback)
......
......@@ -405,8 +405,6 @@ typedef std::vector<HeapObject*> DebugObjectCache;
V(AllowCodeGenerationFromStringsCallback, allow_code_gen_callback, nullptr) \
V(ExtensionCallback, wasm_module_callback, &NoExtension) \
V(ExtensionCallback, wasm_instance_callback, &NoExtension) \
V(ExtensionCallback, wasm_compile_callback, &NoExtension) \
V(ExtensionCallback, wasm_instantiate_callback, &NoExtension) \
V(ApiImplementationCallback, wasm_compile_streaming_callback, nullptr) \
V(ExternalReferenceRedirectorPointer*, external_reference_redirector, \
nullptr) \
......
......@@ -71,61 +71,18 @@ void ThrowRangeException(v8::Isolate* isolate, const char* message) {
isolate->ThrowException(NewRangeException(isolate, message));
}
void RejectPromiseWithRangeError(
const v8::FunctionCallbackInfo<v8::Value>& args, const char* message) {
v8::Isolate* isolate = args.GetIsolate();
v8::HandleScope scope(isolate);
v8::Local<v8::Context> context = isolate->GetCurrentContext();
v8::Local<v8::Promise::Resolver> resolver;
if (!v8::Promise::Resolver::New(context).ToLocal(&resolver)) return;
v8::ReturnValue<v8::Value> return_value = args.GetReturnValue();
return_value.Set(resolver->GetPromise());
auto maybe = resolver->Reject(context, NewRangeException(isolate, message));
CHECK(!maybe.IsNothing());
return;
}
bool WasmModuleOverride(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (IsWasmCompileAllowed(args.GetIsolate(), args[0], false)) return false;
ThrowRangeException(args.GetIsolate(), "Sync compile not allowed");
return true;
}
bool WasmCompileOverride(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (IsWasmCompileAllowed(args.GetIsolate(), args[0], true)) return false;
RejectPromiseWithRangeError(args, "Async compile not allowed");
return true;
}
bool WasmInstanceOverride(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (IsWasmInstantiateAllowed(args.GetIsolate(), args[0], false)) return false;
ThrowRangeException(args.GetIsolate(), "Sync instantiate not allowed");
return true;
}
bool WasmInstantiateOverride(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (IsWasmInstantiateAllowed(args.GetIsolate(), args[0], true)) return false;
RejectPromiseWithRangeError(args, "Async instantiate not allowed");
return true;
}
bool GetWasmFromArray(const v8::FunctionCallbackInfo<v8::Value>& args) {
CHECK(args.Length() == 1);
v8::Local<v8::Context> context = args.GetIsolate()->GetCurrentContext();
v8::Local<v8::Value> module =
v8::Local<v8::Object>::Cast(args[0])->Get(context, 0).ToLocalChecked();
v8::Local<v8::Promise::Resolver> resolver =
v8::Promise::Resolver::New(context).ToLocalChecked();
args.GetReturnValue().Set(resolver->GetPromise());
USE(resolver->Resolve(context, module));
return true;
}
bool NoExtension(const v8::FunctionCallbackInfo<v8::Value>&) { return false; }
} // namespace
namespace v8 {
......@@ -473,16 +430,6 @@ RUNTIME_FUNCTION(Runtime_ClearFunctionFeedback) {
return isolate->heap()->undefined_value();
}
RUNTIME_FUNCTION(Runtime_SetWasmCompileFromPromiseOverload) {
isolate->set_wasm_compile_callback(GetWasmFromArray);
return isolate->heap()->undefined_value();
}
RUNTIME_FUNCTION(Runtime_ResetWasmOverloads) {
isolate->set_wasm_compile_callback(NoExtension);
return isolate->heap()->undefined_value();
}
RUNTIME_FUNCTION(Runtime_CheckWasmWrapperElision) {
// This only supports the case where the function being exported
// calls an intermediate function, and the intermediate function
......@@ -556,7 +503,6 @@ RUNTIME_FUNCTION(Runtime_SetWasmCompileControls) {
ctrl.AllowAnySizeForAsync = allow_async;
ctrl.MaxWasmBufferSize = static_cast<uint32_t>(block_size->value());
v8_isolate->SetWasmModuleCallback(WasmModuleOverride);
v8_isolate->SetWasmCompileCallback(WasmCompileOverride);
return isolate->heap()->undefined_value();
}
......@@ -565,7 +511,6 @@ RUNTIME_FUNCTION(Runtime_SetWasmInstantiateControls) {
v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate);
CHECK(args.length() == 0);
v8_isolate->SetWasmInstanceCallback(WasmInstanceOverride);
v8_isolate->SetWasmInstantiateCallback(WasmInstantiateOverride);
return isolate->heap()->undefined_value();
}
......
......@@ -629,8 +629,6 @@ namespace internal {
F(ValidateWasmOrphanedInstance, 1, 1) \
F(SetWasmCompileControls, 2, 1) \
F(SetWasmInstantiateControls, 0, 1) \
F(SetWasmCompileFromPromiseOverload, 0, 1) \
F(ResetWasmOverloads, 0, 1) \
F(HeapObjectVerify, 1, 1) \
F(WasmNumInterpretedCalls, 1, 1) \
F(RedirectToWasmInterpreter, 2, 1)
......
......@@ -137,36 +137,13 @@ i::MaybeHandle<i::JSReceiver> GetValueAsImports(Local<Value> arg,
return i::Handle<i::JSReceiver>::cast(v8::Utils::OpenHandle(*obj));
}
void RejectResponseAPI(const v8::FunctionCallbackInfo<v8::Value>& args,
ErrorThrower* thrower) {
v8::Isolate* isolate = args.GetIsolate();
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
HandleScope scope(isolate);
Local<Context> context = isolate->GetCurrentContext();
ASSIGN(Promise::Resolver, resolver, Promise::Resolver::New(context));
Local<Promise> module_promise = resolver->GetPromise();
args.GetReturnValue().Set(module_promise);
thrower->TypeError(
"Argument 0 must be provided and must be a Response or Response promise");
auto maybe = resolver->Reject(context, Utils::ToLocal(thrower->Reify()));
CHECK_IMPLIES(!maybe.FromMaybe(false), i_isolate->has_scheduled_exception());
}
void WebAssemblyCompileStreaming(
const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Isolate* isolate = args.GetIsolate();
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
MicrotasksScope runs_microtasks(isolate, MicrotasksScope::kRunMicrotasks);
if (!i_isolate->wasm_compile_callback()(args)) {
if (i_isolate->wasm_compile_streaming_callback() != nullptr) {
i_isolate->wasm_compile_streaming_callback()(args);
} else {
ErrorThrower thrower(i_isolate, "WebAssembly.compileStreaming()");
RejectResponseAPI(args, &thrower);
}
}
DCHECK_NOT_NULL(i_isolate->wasm_compile_streaming_callback());
i_isolate->wasm_compile_streaming_callback()(args);
}
// WebAssembly.compile(bytes) -> Promise
......@@ -928,12 +905,15 @@ void WasmJs::Install(Isolate* isolate) {
JSObject::AddProperty(webassembly, factory->to_string_tag_symbol(),
v8_str(isolate, "WebAssembly"), ro_attributes);
InstallFunc(isolate, webassembly, "compile", WebAssemblyCompile, 1);
InstallFunc(isolate, webassembly, "compileStreaming",
WebAssemblyCompileStreaming, 1);
InstallFunc(isolate, webassembly, "validate", WebAssemblyValidate, 1);
InstallFunc(isolate, webassembly, "instantiate", WebAssemblyInstantiate, 1);
InstallFunc(isolate, webassembly, "instantiateStreaming",
WebAssemblyInstantiateStreaming, 1);
if (isolate->wasm_compile_streaming_callback() != nullptr) {
InstallFunc(isolate, webassembly, "compileStreaming",
WebAssemblyCompileStreaming, 1);
InstallFunc(isolate, webassembly, "instantiateStreaming",
WebAssemblyInstantiateStreaming, 1);
}
// Setup Module
Handle<JSFunction> module_constructor =
......
......@@ -2,12 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --allow-natives-syntax
load("test/mjsunit/wasm/wasm-constants.js");
load("test/mjsunit/wasm/wasm-module-builder.js");
%ResetWasmOverloads();
let buffer = (() => {
let builder = new WasmModuleBuilder();
builder.addFunction("f", kSig_i_v)
......@@ -19,35 +16,18 @@ let buffer = (() => {
var module = new WebAssembly.Module(buffer);
var wrapper = [module];
assertPromiseResult(
WebAssembly.instantiateStreaming(wrapper),
assertUnreachable,
e => assertTrue(e instanceof TypeError));
assertPromiseResult(
WebAssembly.compileStreaming(wrapper),
assertUnreachable,
e => assertTrue(e instanceof TypeError));
assertPromiseResult(
(() => {
%SetWasmCompileFromPromiseOverload();
return WebAssembly.compileStreaming(wrapper);
})(),
module => {
assertTrue(module instanceof WebAssembly.Module);
%ResetWasmOverloads();
},
assertUnreachable);
assertPromiseResult(
(() => {
%SetWasmCompileFromPromiseOverload();
return WebAssembly.instantiateStreaming(wrapper);
})(),
pair => {
assertTrue(pair.instance instanceof WebAssembly.Instance);
assertTrue(pair.module instanceof WebAssembly.Module);
%ResetWasmOverloads();
},
assertUnreachable);
try {
assertPromiseResult(
WebAssembly.instantiateStreaming(wrapper),
assertUnreachable, assertUnreachable);
} catch (e) {
assertTrue(e instanceof TypeError);
}
try {
assertPromiseResult(
WebAssembly.compileStreaming(wrapper),
assertUnreachable, assertUnreachable);
} catch (e) {
assertTrue(e instanceof TypeError);
}
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