Commit c7436e30 authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[wasm] Fix exceptions in {WasmModuleObject::DeserializeOrCompile}.

This makes sure an exception raised while compiling a module via the
embedder API is properly returned as a "scheduled exception" and hence
propagates to surrounding {v8::TryCatch} scopes.

R=clemensh@chromium.org
TEST=cctest/test-api/WasmModuleObjectCompileFailure
BUG=v8:8908

Change-Id: I52b21fbe5a4548aa346fd6c9b5bac061613db487
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1507673
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#60092}
parent acadb202
......@@ -7365,16 +7365,22 @@ MaybeLocal<WasmModuleObject> WasmModuleObject::Compile(Isolate* isolate,
const uint8_t* start,
size_t length) {
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
i::wasm::ErrorThrower thrower(i_isolate, "WasmModuleObject::Compile()");
if (!i::wasm::IsWasmCodegenAllowed(i_isolate, i_isolate->native_context())) {
return MaybeLocal<WasmModuleObject>();
}
i::MaybeHandle<i::JSObject> maybe_compiled;
{
i::wasm::ErrorThrower thrower(i_isolate, "WasmModuleObject::Compile()");
auto enabled_features = i::wasm::WasmFeaturesFromIsolate(i_isolate);
i::MaybeHandle<i::JSObject> maybe_compiled =
i_isolate->wasm_engine()->SyncCompile(
maybe_compiled = i_isolate->wasm_engine()->SyncCompile(
i_isolate, enabled_features, &thrower,
i::wasm::ModuleWireBytes(start, start + length));
if (maybe_compiled.is_null()) return MaybeLocal<WasmModuleObject>();
}
CHECK_EQ(maybe_compiled.is_null(), i_isolate->has_pending_exception());
if (maybe_compiled.is_null()) {
i_isolate->OptionalRescheduleException(false);
return MaybeLocal<WasmModuleObject>();
}
return Local<WasmModuleObject>::Cast(
Utils::ToLocal(maybe_compiled.ToHandleChecked()));
}
......
......@@ -27792,6 +27792,26 @@ TEST(WasmI64AtomicWaitCallback) {
} // namespace internal
} // namespace v8
// TODO(mstarzinger): Move this into a test-api-wasm.cc file when this large
// test file is being split up into chunks.
TEST(WasmModuleObjectCompileFailure) {
LocalContext env;
v8::Isolate* isolate = env->GetIsolate();
v8::HandleScope scope(isolate);
{
v8::TryCatch try_catch(isolate);
uint8_t buffer[] = {0xDE, 0xAD, 0xBE, 0xEF};
v8::MemorySpan<const uint8_t> serialized_module;
v8::MemorySpan<const uint8_t> wire_bytes = {buffer, arraysize(buffer)};
v8::MaybeLocal<v8::WasmModuleObject> maybe_module =
v8::WasmModuleObject::DeserializeOrCompile(isolate, serialized_module,
wire_bytes);
CHECK(maybe_module.IsEmpty());
CHECK(try_catch.HasCaught());
}
}
TEST(BigIntAPI) {
LocalContext env;
v8::Isolate* isolate = env->GetIsolate();
......
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