mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 01:37:36 +00:00
LibJS+Everywhere: Propagate Cell::initialize errors from Heap::allocate
Callers that are already in a fallible context will now TRY to allocate cells. Callers in infallible contexts get a FIXME.
This commit is contained in:
parent
109b190a19
commit
b75b7f0c0d
178 changed files with 565 additions and 565 deletions
|
@ -36,7 +36,7 @@ JS::ThrowCompletionOr<JS::NonnullGCPtr<JS::Object>> WebAssemblyInstanceConstruct
|
|||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "WebAssembly.Module");
|
||||
auto& module_object = static_cast<WebAssemblyModuleObject&>(*module_argument);
|
||||
auto result = TRY(WebAssemblyObject::instantiate_module(vm, module_object.module()));
|
||||
return heap().allocate<WebAssemblyInstanceObject>(realm, realm, result);
|
||||
return MUST_OR_THROW_OOM(heap().allocate<WebAssemblyInstanceObject>(realm, realm, result));
|
||||
}
|
||||
|
||||
JS::ThrowCompletionOr<void> WebAssemblyInstanceConstructor::initialize(JS::Realm& realm)
|
||||
|
|
|
@ -35,34 +35,38 @@ JS::ThrowCompletionOr<void> WebAssemblyInstanceObject::initialize(JS::Realm& rea
|
|||
auto& instance = this->instance();
|
||||
auto& cache = this->cache();
|
||||
for (auto& export_ : instance.exports()) {
|
||||
export_.value().visit(
|
||||
[&](Wasm::FunctionAddress const& address) {
|
||||
TRY(export_.value().visit(
|
||||
[&](Wasm::FunctionAddress const& address) -> JS::ThrowCompletionOr<void> {
|
||||
Optional<JS::FunctionObject*> object = cache.function_instances.get(address);
|
||||
if (!object.has_value()) {
|
||||
object = create_native_function(vm, address, export_.name());
|
||||
cache.function_instances.set(address, *object);
|
||||
}
|
||||
m_exports_object->define_direct_property(export_.name(), *object, JS::default_attributes);
|
||||
return {};
|
||||
},
|
||||
[&](Wasm::MemoryAddress const& address) {
|
||||
[&](Wasm::MemoryAddress const& address) -> JS::ThrowCompletionOr<void> {
|
||||
Optional<WebAssemblyMemoryObject*> object = cache.memory_instances.get(address);
|
||||
if (!object.has_value()) {
|
||||
object = heap().allocate<Web::Bindings::WebAssemblyMemoryObject>(realm, realm, address);
|
||||
object = MUST_OR_THROW_OOM(heap().allocate<Web::Bindings::WebAssemblyMemoryObject>(realm, realm, address));
|
||||
cache.memory_instances.set(address, *object);
|
||||
}
|
||||
m_exports_object->define_direct_property(export_.name(), *object, JS::default_attributes);
|
||||
return {};
|
||||
},
|
||||
[&](Wasm::TableAddress const& address) {
|
||||
[&](Wasm::TableAddress const& address) -> JS::ThrowCompletionOr<void> {
|
||||
Optional<WebAssemblyTableObject*> object = cache.table_instances.get(address);
|
||||
if (!object.has_value()) {
|
||||
object = heap().allocate<Web::Bindings::WebAssemblyTableObject>(realm, realm, address);
|
||||
object = MUST_OR_THROW_OOM(heap().allocate<Web::Bindings::WebAssemblyTableObject>(realm, realm, address));
|
||||
cache.table_instances.set(address, *object);
|
||||
}
|
||||
m_exports_object->define_direct_property(export_.name(), *object, JS::default_attributes);
|
||||
return {};
|
||||
},
|
||||
[&](auto const&) {
|
||||
[&](auto const&) -> JS::ThrowCompletionOr<void> {
|
||||
// FIXME: Implement other exports!
|
||||
});
|
||||
return {};
|
||||
}));
|
||||
}
|
||||
|
||||
MUST(m_exports_object->set_integrity_level(IntegrityLevel::Frozen));
|
||||
|
|
|
@ -46,7 +46,7 @@ JS::ThrowCompletionOr<JS::NonnullGCPtr<JS::Object>> WebAssemblyMemoryConstructor
|
|||
if (!address.has_value())
|
||||
return vm.throw_completion<JS::TypeError>("Wasm Memory allocation failed");
|
||||
|
||||
return vm.heap().allocate<WebAssemblyMemoryObject>(realm, realm, *address);
|
||||
return MUST_OR_THROW_OOM(vm.heap().allocate<WebAssemblyMemoryObject>(realm, realm, *address));
|
||||
}
|
||||
|
||||
JS::ThrowCompletionOr<void> WebAssemblyMemoryConstructor::initialize(JS::Realm& realm)
|
||||
|
|
|
@ -33,7 +33,7 @@ JS::ThrowCompletionOr<JS::NonnullGCPtr<JS::Object>> WebAssemblyModuleConstructor
|
|||
auto* buffer_object = TRY(vm.argument(0).to_object(vm));
|
||||
auto result = TRY(parse_module(vm, buffer_object));
|
||||
|
||||
return heap().allocate<WebAssemblyModuleObject>(realm, realm, result);
|
||||
return MUST_OR_THROW_OOM(heap().allocate<WebAssemblyModuleObject>(realm, realm, result));
|
||||
}
|
||||
|
||||
JS::ThrowCompletionOr<void> WebAssemblyModuleConstructor::initialize(JS::Realm& realm)
|
||||
|
|
|
@ -157,7 +157,7 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyObject::compile)
|
|||
if (result.is_error())
|
||||
promise->reject(*result.release_error().value());
|
||||
else
|
||||
promise->fulfill(vm.heap().allocate<WebAssemblyModuleObject>(realm, realm, result.release_value()));
|
||||
promise->fulfill(MUST_OR_THROW_OOM(vm.heap().allocate<WebAssemblyModuleObject>(realm, realm, result.release_value())));
|
||||
return promise;
|
||||
}
|
||||
|
||||
|
@ -337,10 +337,10 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyObject::instantiate)
|
|||
if (result.is_error()) {
|
||||
promise->reject(*result.release_error().value());
|
||||
} else {
|
||||
auto instance_object = vm.heap().allocate<WebAssemblyInstanceObject>(realm, realm, result.release_value());
|
||||
auto instance_object = MUST_OR_THROW_OOM(vm.heap().allocate<WebAssemblyInstanceObject>(realm, realm, result.release_value()));
|
||||
if (should_return_module) {
|
||||
auto object = JS::Object::create(realm, nullptr);
|
||||
object->define_direct_property("module", vm.heap().allocate<WebAssemblyModuleObject>(realm, realm, s_compiled_modules.size() - 1), JS::default_attributes);
|
||||
object->define_direct_property("module", MUST_OR_THROW_OOM(vm.heap().allocate<WebAssemblyModuleObject>(realm, realm, s_compiled_modules.size() - 1)), JS::default_attributes);
|
||||
object->define_direct_property("instance", instance_object, JS::default_attributes);
|
||||
promise->fulfill(object);
|
||||
} else {
|
||||
|
@ -355,7 +355,7 @@ JS::Value to_js_value(JS::VM& vm, Wasm::Value& wasm_value)
|
|||
auto& realm = *vm.current_realm();
|
||||
switch (wasm_value.type().kind()) {
|
||||
case Wasm::ValueType::I64:
|
||||
return realm.heap().allocate<JS::BigInt>(realm, ::Crypto::SignedBigInteger { wasm_value.to<i64>().value() });
|
||||
return realm.heap().allocate<JS::BigInt>(realm, ::Crypto::SignedBigInteger { wasm_value.to<i64>().value() }).release_allocated_value_but_fixme_should_propagate_errors();
|
||||
case Wasm::ValueType::I32:
|
||||
return JS::Value(wasm_value.to<i32>().value());
|
||||
case Wasm::ValueType::F64:
|
||||
|
|
|
@ -77,7 +77,7 @@ JS::ThrowCompletionOr<JS::NonnullGCPtr<JS::Object>> WebAssemblyTableConstructor:
|
|||
for (auto& element : table.elements())
|
||||
element = reference;
|
||||
|
||||
return vm.heap().allocate<WebAssemblyTableObject>(realm, realm, *address);
|
||||
return MUST_OR_THROW_OOM(vm.heap().allocate<WebAssemblyTableObject>(realm, realm, *address));
|
||||
}
|
||||
|
||||
JS::ThrowCompletionOr<void> WebAssemblyTableConstructor::initialize(JS::Realm& realm)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue