[wasm] Fix error message for async instantiation
This fixes the error message generated for compile errors during asynchronous instantiation. It shows "WebAssembly.instantiate()" now instead of "WebAssembly.compile()". R=mstarzinger@chromium.org Bug: v8:9266 Change-Id: Ieae478d1c4f6843fbc17e15debb6c49f72059d99 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1617940 Commit-Queue: Clemens Hammacher <clemensh@chromium.org> Reviewed-by: Andreas Haas <ahaas@chromium.org> Reviewed-by: Michael Starzinger <mstarzinger@chromium.org> Cr-Commit-Position: refs/heads/master@{#61654}
This commit is contained in:
parent
617b7266bf
commit
9a6f52f519
@ -364,11 +364,11 @@ void WasmEngine::AsyncInstantiate(
|
|||||||
void WasmEngine::AsyncCompile(
|
void WasmEngine::AsyncCompile(
|
||||||
Isolate* isolate, const WasmFeatures& enabled,
|
Isolate* isolate, const WasmFeatures& enabled,
|
||||||
std::shared_ptr<CompilationResultResolver> resolver,
|
std::shared_ptr<CompilationResultResolver> resolver,
|
||||||
const ModuleWireBytes& bytes, bool is_shared) {
|
const ModuleWireBytes& bytes, bool is_shared,
|
||||||
const char* const kAPIMethodName = "WebAssembly.compile()";
|
const char* api_method_name_for_errors) {
|
||||||
if (!FLAG_wasm_async_compilation) {
|
if (!FLAG_wasm_async_compilation) {
|
||||||
// Asynchronous compilation disabled; fall back on synchronous compilation.
|
// Asynchronous compilation disabled; fall back on synchronous compilation.
|
||||||
ErrorThrower thrower(isolate, kAPIMethodName);
|
ErrorThrower thrower(isolate, api_method_name_for_errors);
|
||||||
MaybeHandle<WasmModuleObject> module_object;
|
MaybeHandle<WasmModuleObject> module_object;
|
||||||
if (is_shared) {
|
if (is_shared) {
|
||||||
// Make a copy of the wire bytes to avoid concurrent modification.
|
// Make a copy of the wire bytes to avoid concurrent modification.
|
||||||
@ -391,9 +391,9 @@ void WasmEngine::AsyncCompile(
|
|||||||
|
|
||||||
if (FLAG_wasm_test_streaming) {
|
if (FLAG_wasm_test_streaming) {
|
||||||
std::shared_ptr<StreamingDecoder> streaming_decoder =
|
std::shared_ptr<StreamingDecoder> streaming_decoder =
|
||||||
StartStreamingCompilation(isolate, enabled,
|
StartStreamingCompilation(
|
||||||
handle(isolate->context(), isolate),
|
isolate, enabled, handle(isolate->context(), isolate),
|
||||||
kAPIMethodName, std::move(resolver));
|
api_method_name_for_errors, std::move(resolver));
|
||||||
streaming_decoder->OnBytesReceived(bytes.module_bytes());
|
streaming_decoder->OnBytesReceived(bytes.module_bytes());
|
||||||
streaming_decoder->Finish();
|
streaming_decoder->Finish();
|
||||||
return;
|
return;
|
||||||
@ -403,9 +403,10 @@ void WasmEngine::AsyncCompile(
|
|||||||
std::unique_ptr<byte[]> copy(new byte[bytes.length()]);
|
std::unique_ptr<byte[]> copy(new byte[bytes.length()]);
|
||||||
memcpy(copy.get(), bytes.start(), bytes.length());
|
memcpy(copy.get(), bytes.start(), bytes.length());
|
||||||
|
|
||||||
AsyncCompileJob* job = CreateAsyncCompileJob(
|
AsyncCompileJob* job =
|
||||||
isolate, enabled, std::move(copy), bytes.length(),
|
CreateAsyncCompileJob(isolate, enabled, std::move(copy), bytes.length(),
|
||||||
handle(isolate->context(), isolate), kAPIMethodName, std::move(resolver));
|
handle(isolate->context(), isolate),
|
||||||
|
api_method_name_for_errors, std::move(resolver));
|
||||||
job->Start();
|
job->Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,7 +88,8 @@ class V8_EXPORT_PRIVATE WasmEngine {
|
|||||||
// be shared across threads, i.e. could be concurrently modified.
|
// be shared across threads, i.e. could be concurrently modified.
|
||||||
void AsyncCompile(Isolate* isolate, const WasmFeatures& enabled,
|
void AsyncCompile(Isolate* isolate, const WasmFeatures& enabled,
|
||||||
std::shared_ptr<CompilationResultResolver> resolver,
|
std::shared_ptr<CompilationResultResolver> resolver,
|
||||||
const ModuleWireBytes& bytes, bool is_shared);
|
const ModuleWireBytes& bytes, bool is_shared,
|
||||||
|
const char* api_method_name_for_errors);
|
||||||
|
|
||||||
// Begin an asynchronous instantiation of the given WASM module.
|
// Begin an asynchronous instantiation of the given WASM module.
|
||||||
void AsyncInstantiate(Isolate* isolate,
|
void AsyncInstantiate(Isolate* isolate,
|
||||||
|
@ -503,11 +503,12 @@ bool EnforceUint32(T argument_name, Local<v8::Value> v, Local<Context> context,
|
|||||||
|
|
||||||
// WebAssembly.compile(bytes) -> Promise
|
// WebAssembly.compile(bytes) -> Promise
|
||||||
void WebAssemblyCompile(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
void WebAssemblyCompile(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
||||||
|
constexpr const char* kAPIMethodName = "WebAssembly.compile()";
|
||||||
v8::Isolate* isolate = args.GetIsolate();
|
v8::Isolate* isolate = args.GetIsolate();
|
||||||
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
||||||
|
|
||||||
HandleScope scope(isolate);
|
HandleScope scope(isolate);
|
||||||
ScheduledErrorThrower thrower(i_isolate, "WebAssembly.compile()");
|
ScheduledErrorThrower thrower(i_isolate, kAPIMethodName);
|
||||||
|
|
||||||
if (!i::wasm::IsWasmCodegenAllowed(i_isolate, i_isolate->native_context())) {
|
if (!i::wasm::IsWasmCodegenAllowed(i_isolate, i_isolate->native_context())) {
|
||||||
thrower.CompileError("Wasm code generation disallowed by embedder");
|
thrower.CompileError("Wasm code generation disallowed by embedder");
|
||||||
@ -531,7 +532,8 @@ void WebAssemblyCompile(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||||||
// Asynchronous compilation handles copying wire bytes if necessary.
|
// Asynchronous compilation handles copying wire bytes if necessary.
|
||||||
auto enabled_features = i::wasm::WasmFeaturesFromIsolate(i_isolate);
|
auto enabled_features = i::wasm::WasmFeaturesFromIsolate(i_isolate);
|
||||||
i_isolate->wasm_engine()->AsyncCompile(i_isolate, enabled_features,
|
i_isolate->wasm_engine()->AsyncCompile(i_isolate, enabled_features,
|
||||||
std::move(resolver), bytes, is_shared);
|
std::move(resolver), bytes, is_shared,
|
||||||
|
kAPIMethodName);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WasmStreamingCallbackForTesting(
|
void WasmStreamingCallbackForTesting(
|
||||||
@ -907,12 +909,13 @@ void WebAssemblyInstantiateStreaming(
|
|||||||
// WebAssembly.instantiate(bytes, imports) ->
|
// WebAssembly.instantiate(bytes, imports) ->
|
||||||
// {module: WebAssembly.Module, instance: WebAssembly.Instance}
|
// {module: WebAssembly.Module, instance: WebAssembly.Instance}
|
||||||
void WebAssemblyInstantiate(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
void WebAssemblyInstantiate(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
||||||
|
constexpr const char* kAPIMethodName = "WebAssembly.instantiate()";
|
||||||
v8::Isolate* isolate = args.GetIsolate();
|
v8::Isolate* isolate = args.GetIsolate();
|
||||||
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
||||||
i_isolate->CountUsage(
|
i_isolate->CountUsage(
|
||||||
v8::Isolate::UseCounterFeature::kWebAssemblyInstantiation);
|
v8::Isolate::UseCounterFeature::kWebAssemblyInstantiation);
|
||||||
|
|
||||||
ScheduledErrorThrower thrower(i_isolate, "WebAssembly.instantiate()");
|
ScheduledErrorThrower thrower(i_isolate, kAPIMethodName);
|
||||||
|
|
||||||
HandleScope scope(isolate);
|
HandleScope scope(isolate);
|
||||||
|
|
||||||
@ -981,7 +984,7 @@ void WebAssemblyInstantiate(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||||||
auto enabled_features = i::wasm::WasmFeaturesFromIsolate(i_isolate);
|
auto enabled_features = i::wasm::WasmFeaturesFromIsolate(i_isolate);
|
||||||
i_isolate->wasm_engine()->AsyncCompile(i_isolate, enabled_features,
|
i_isolate->wasm_engine()->AsyncCompile(i_isolate, enabled_features,
|
||||||
std::move(compilation_resolver), bytes,
|
std::move(compilation_resolver), bytes,
|
||||||
is_shared);
|
is_shared, kAPIMethodName);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GetIntegerProperty(v8::Isolate* isolate, ErrorThrower* thrower,
|
bool GetIntegerProperty(v8::Isolate* isolate, ErrorThrower* thrower,
|
||||||
|
@ -189,10 +189,11 @@ Handle<WasmInstanceObject> CompileAndInstantiateAsync(
|
|||||||
SharedEngineIsolate& isolate, ZoneBuffer* buffer) {
|
SharedEngineIsolate& isolate, ZoneBuffer* buffer) {
|
||||||
Handle<Object> maybe_instance = handle(Smi::kZero, isolate.isolate());
|
Handle<Object> maybe_instance = handle(Smi::kZero, isolate.isolate());
|
||||||
auto enabled_features = WasmFeaturesFromIsolate(isolate.isolate());
|
auto enabled_features = WasmFeaturesFromIsolate(isolate.isolate());
|
||||||
|
constexpr const char* kAPIMethodName = "Test.CompileAndInstantiateAsync";
|
||||||
isolate.isolate()->wasm_engine()->AsyncCompile(
|
isolate.isolate()->wasm_engine()->AsyncCompile(
|
||||||
isolate.isolate(), enabled_features,
|
isolate.isolate(), enabled_features,
|
||||||
base::make_unique<MockCompilationResolver>(isolate, &maybe_instance),
|
base::make_unique<MockCompilationResolver>(isolate, &maybe_instance),
|
||||||
ModuleWireBytes(buffer->begin(), buffer->end()), true);
|
ModuleWireBytes(buffer->begin(), buffer->end()), true, kAPIMethodName);
|
||||||
while (!maybe_instance->IsWasmInstanceObject()) PumpMessageLoop(isolate);
|
while (!maybe_instance->IsWasmInstanceObject()) PumpMessageLoop(isolate);
|
||||||
Handle<WasmInstanceObject> instance =
|
Handle<WasmInstanceObject> instance =
|
||||||
Handle<WasmInstanceObject>::cast(maybe_instance);
|
Handle<WasmInstanceObject>::cast(maybe_instance);
|
||||||
|
@ -69,10 +69,11 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
|||||||
|
|
||||||
bool done = false;
|
bool done = false;
|
||||||
auto enabled_features = i::wasm::WasmFeaturesFromIsolate(i_isolate);
|
auto enabled_features = i::wasm::WasmFeaturesFromIsolate(i_isolate);
|
||||||
|
constexpr const char* kAPIMethodName = "WasmAsyncFuzzer.compile";
|
||||||
i_isolate->wasm_engine()->AsyncCompile(
|
i_isolate->wasm_engine()->AsyncCompile(
|
||||||
i_isolate, enabled_features,
|
i_isolate, enabled_features,
|
||||||
std::make_shared<AsyncFuzzerResolver>(i_isolate, &done),
|
std::make_shared<AsyncFuzzerResolver>(i_isolate, &done),
|
||||||
ModuleWireBytes(data, data + size), false);
|
ModuleWireBytes(data, data + size), false, kAPIMethodName);
|
||||||
|
|
||||||
// Wait for the promise to resolve.
|
// Wait for the promise to resolve.
|
||||||
while (!done) {
|
while (!done) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
*%(basename)s:9: CompileError: WebAssembly.compile(): Compiling function #0:"f" failed: expected 1 elements on the stack for fallthru to @1, found 0 @+24
|
*%(basename)s:9: CompileError: WebAssembly.instantiate(): Compiling function #0:"f" failed: expected 1 elements on the stack for fallthru to @1, found 0 @+24
|
||||||
let rethrow = e => setTimeout(_ => {throw e}, 0);
|
let rethrow = e => setTimeout(_ => {throw e}, 0);
|
||||||
^
|
^
|
||||||
CompileError: WebAssembly.compile(): Compiling function #0:"f" failed: expected 1 elements on the stack for fallthru to @1, found 0 @+24
|
CompileError: WebAssembly.instantiate(): Compiling function #0:"f" failed: expected 1 elements on the stack for fallthru to @1, found 0 @+24
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user