test-wasm: Convert WebAssemblyModule::create() to ThrowCompletionOr

This exposed a missing exception check in parseWebAssemblyModule(),
which could throw but still return a normal completion (which currently
works as we check VM::exception() at the right point, but breaks when
moving everything to exceptions).
This commit is contained in:
Linus Groh 2021-12-31 14:59:11 +01:00
parent faad7a3ed1
commit a6476ad61f
Notes: sideshowbarker 2024-07-17 21:52:54 +09:00

View File

@ -38,22 +38,21 @@ public:
Wasm::Module& module() { return *m_module; }
Wasm::ModuleInstance& module_instance() { return *m_module_instance; }
static WebAssemblyModule* create(JS::GlobalObject& global_object, Wasm::Module module, HashMap<Wasm::Linker::Name, Wasm::ExternValue> const& imports)
static JS::ThrowCompletionOr<WebAssemblyModule*> create(JS::GlobalObject& global_object, Wasm::Module module, HashMap<Wasm::Linker::Name, Wasm::ExternValue> const& imports)
{
auto instance = global_object.heap().allocate<WebAssemblyModule>(global_object, *global_object.object_prototype());
auto& vm = global_object.vm();
auto* instance = global_object.heap().allocate<WebAssemblyModule>(global_object, *global_object.object_prototype());
instance->m_module = move(module);
Wasm::Linker linker(*instance->m_module);
linker.link(imports);
linker.link(spec_test_namespace());
auto link_result = linker.finish();
if (link_result.is_error()) {
global_object.vm().throw_exception<JS::TypeError>(global_object, "Link failed");
} else {
if (auto result = machine().instantiate(*instance->m_module, link_result.release_value()); result.is_error())
global_object.vm().throw_exception<JS::TypeError>(global_object, result.release_error().error);
else
instance->m_module_instance = result.release_value();
}
if (link_result.is_error())
return vm.throw_completion<JS::TypeError>(global_object, "Link failed");
auto result = machine().instantiate(*instance->m_module, link_result.release_value());
if (result.is_error())
return vm.throw_completion<JS::TypeError>(global_object, result.release_error().error);
instance->m_module_instance = result.release_value();
return instance;
}
void initialize(JS::GlobalObject&) override;
@ -125,7 +124,7 @@ TESTJS_GLOBAL_FUNCTION(parse_webassembly_module, parseWebAssemblyModule)
}
}
return JS::Value(WebAssemblyModule::create(global_object, result.release_value(), imports));
return JS::Value(TRY(WebAssemblyModule::create(global_object, result.release_value(), imports)));
}
TESTJS_GLOBAL_FUNCTION(compare_typed_arrays, compareTypedArrays)