Commit 5f105141 authored by Andreas Haas's avatar Andreas Haas Committed by Commit Bot

[wasm] During instantiation, pending_exceptions dominate new exceptions

For async instantiation of WebAssembly code we had the assumption that
a pending exceptions (an exception which comes from
execution JS code) and an ErrorThrower error cannot occur at the same
time. This assumption turned out to be wrong. With this CL we handle
this case by prefering pending_exceptions over ErrorThrower errors.

In addition I extended the tests for failing instantiation to also
exercise async instantiation, and I added a regression test.

R=clemensh@chromium.org

Bug: chromium:870646
Change-Id: I4cb54ff8642ad4ea193b20f79905c9f6508c2b2e
Reviewed-on: https://chromium-review.googlesource.com/1163511Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54940}
parent 65624c9e
...@@ -76,7 +76,7 @@ MaybeHandle<WasmInstanceObject> WasmEngine::SyncInstantiate( ...@@ -76,7 +76,7 @@ MaybeHandle<WasmInstanceObject> WasmEngine::SyncInstantiate(
void WasmEngine::AsyncInstantiate( void WasmEngine::AsyncInstantiate(
Isolate* isolate, std::unique_ptr<InstantiationResultResolver> resolver, Isolate* isolate, std::unique_ptr<InstantiationResultResolver> resolver,
Handle<WasmModuleObject> module_object, MaybeHandle<JSReceiver> imports) { Handle<WasmModuleObject> module_object, MaybeHandle<JSReceiver> imports) {
ErrorThrower thrower(isolate, nullptr); ErrorThrower thrower(isolate, "WebAssembly Instantiation");
// Instantiate a TryCatch so that caught exceptions won't progagate out. // Instantiate a TryCatch so that caught exceptions won't progagate out.
// They will still be set as pending exceptions on the isolate. // They will still be set as pending exceptions on the isolate.
// TODO(clemensh): Avoid TryCatch, use Execution::TryCall internally to invoke // TODO(clemensh): Avoid TryCatch, use Execution::TryCall internally to invoke
...@@ -93,19 +93,18 @@ void WasmEngine::AsyncInstantiate( ...@@ -93,19 +93,18 @@ void WasmEngine::AsyncInstantiate(
return; return;
} }
// We either have a pending exception (if the start function threw), or an if (isolate->has_pending_exception()) {
// exception in the ErrorThrower. // The JS code executed during instantiation has thrown an exception.
DCHECK_EQ(1, isolate->has_pending_exception() + thrower.error()); // We have to move the exception to the promise chain.
if (thrower.error()) {
resolver->OnInstantiationFailed(thrower.Reify());
} else {
// The start function has thrown an exception. We have to move the
// exception to the promise chain.
Handle<Object> exception(isolate->pending_exception(), isolate); Handle<Object> exception(isolate->pending_exception(), isolate);
isolate->clear_pending_exception(); isolate->clear_pending_exception();
DCHECK(*isolate->external_caught_exception_address()); DCHECK(*isolate->external_caught_exception_address());
*isolate->external_caught_exception_address() = false; *isolate->external_caught_exception_address() = false;
resolver->OnInstantiationFailed(exception); resolver->OnInstantiationFailed(exception);
thrower.Reset();
} else {
DCHECK(thrower.error());
resolver->OnInstantiationFailed(thrower.Reify());
} }
} }
......
...@@ -667,7 +667,7 @@ void WebAssemblyInstantiate(const v8::FunctionCallbackInfo<v8::Value>& args) { ...@@ -667,7 +667,7 @@ void WebAssemblyInstantiate(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Isolate::UseCounterFeature::kWebAssemblyInstantiation); v8::Isolate::UseCounterFeature::kWebAssemblyInstantiation);
MicrotasksScope runs_microtasks(isolate, MicrotasksScope::kRunMicrotasks); MicrotasksScope runs_microtasks(isolate, MicrotasksScope::kRunMicrotasks);
ScheduledErrorThrower thrower(i_isolate, "WebAssembly.instantiate()"); ScheduledErrorThrower thrower(i_isolate, "WebAssembly Instantiation");
HandleScope scope(isolate); HandleScope scope(isolate);
......
This diff is collapsed.
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