mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 06:37:35 +00:00
LibJS: Make Cell::initialize() return void
Stop worrying about tiny OOMs. Work towards #20405
This commit is contained in:
parent
fde26c53f0
commit
18c54d8d40
804 changed files with 1330 additions and 2171 deletions
|
@ -38,19 +38,19 @@ Instance::Instance(JS::Realm& realm, size_t index)
|
|||
{
|
||||
}
|
||||
|
||||
JS::ThrowCompletionOr<void> Instance::initialize(JS::Realm& realm)
|
||||
void Instance::initialize(JS::Realm& realm)
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
|
||||
MUST_OR_THROW_OOM(Base::initialize(realm));
|
||||
Base::initialize(realm);
|
||||
set_prototype(&Bindings::ensure_web_prototype<Bindings::InstancePrototype>(realm, "WebAssembly.Instance"sv));
|
||||
|
||||
auto& instance = *Detail::s_instantiated_modules[m_index];
|
||||
auto& cache = Detail::s_module_caches.at(m_index);
|
||||
|
||||
for (auto& export_ : instance.exports()) {
|
||||
TRY(export_.value().visit(
|
||||
[&](Wasm::FunctionAddress const& address) -> JS::ThrowCompletionOr<void> {
|
||||
export_.value().visit(
|
||||
[&](Wasm::FunctionAddress const& address) {
|
||||
Optional<JS::GCPtr<JS::FunctionObject>> object = cache.function_instances.get(address);
|
||||
if (!object.has_value()) {
|
||||
object = Detail::create_native_function(vm, address, export_.name());
|
||||
|
@ -58,36 +58,31 @@ JS::ThrowCompletionOr<void> Instance::initialize(JS::Realm& realm)
|
|||
}
|
||||
|
||||
m_exports->define_direct_property(export_.name(), *object, JS::default_attributes);
|
||||
return {};
|
||||
},
|
||||
[&](Wasm::MemoryAddress const& address) -> JS::ThrowCompletionOr<void> {
|
||||
[&](Wasm::MemoryAddress const& address) {
|
||||
Optional<JS::GCPtr<Memory>> object = cache.memory_instances.get(address);
|
||||
if (!object.has_value()) {
|
||||
object = MUST_OR_THROW_OOM(heap().allocate<Memory>(realm, realm, address));
|
||||
object = MUST(heap().allocate<Memory>(realm, realm, address));
|
||||
cache.memory_instances.set(address, *object);
|
||||
}
|
||||
|
||||
m_exports->define_direct_property(export_.name(), *object, JS::default_attributes);
|
||||
return {};
|
||||
},
|
||||
[&](Wasm::TableAddress const& address) -> JS::ThrowCompletionOr<void> {
|
||||
[&](Wasm::TableAddress const& address) {
|
||||
Optional<JS::GCPtr<Table>> object = cache.table_instances.get(address);
|
||||
if (!object.has_value()) {
|
||||
object = MUST_OR_THROW_OOM(heap().allocate<Table>(realm, realm, address));
|
||||
object = MUST(heap().allocate<Table>(realm, realm, address));
|
||||
cache.table_instances.set(address, *object);
|
||||
}
|
||||
|
||||
m_exports->define_direct_property(export_.name(), *object, JS::default_attributes);
|
||||
return {};
|
||||
},
|
||||
[&](auto const&) -> JS::ThrowCompletionOr<void> {
|
||||
[&](auto const&) {
|
||||
// FIXME: Implement other exports!
|
||||
return {};
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
MUST(m_exports->set_integrity_level(IntegrityLevel::Frozen));
|
||||
return {};
|
||||
}
|
||||
|
||||
void Instance::visit_edges(Visitor& visitor)
|
||||
|
|
|
@ -27,7 +27,7 @@ public:
|
|||
private:
|
||||
Instance(JS::Realm&, size_t index);
|
||||
|
||||
virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual void visit_edges(Visitor&) override;
|
||||
|
||||
JS::NonnullGCPtr<Object> m_exports;
|
||||
|
|
|
@ -39,12 +39,10 @@ Memory::Memory(JS::Realm& realm, Wasm::MemoryAddress address)
|
|||
{
|
||||
}
|
||||
|
||||
JS::ThrowCompletionOr<void> Memory::initialize(JS::Realm& realm)
|
||||
void Memory::initialize(JS::Realm& realm)
|
||||
{
|
||||
MUST_OR_THROW_OOM(Base::initialize(realm));
|
||||
Base::initialize(realm);
|
||||
set_prototype(&Bindings::ensure_web_prototype<Bindings::MemoryPrototype>(realm, "WebAssembly.Memory"sv));
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
// https://webassembly.github.io/spec/js-api/#dom-memory-grow
|
||||
|
|
|
@ -36,7 +36,7 @@ public:
|
|||
private:
|
||||
Memory(JS::Realm&, Wasm::MemoryAddress);
|
||||
|
||||
virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
|
||||
WebIDL::ExceptionOr<void> reset_the_memory_buffer();
|
||||
static WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::ArrayBuffer>> create_a_memory_buffer(JS::VM&, JS::Realm&, Wasm::MemoryAddress);
|
||||
|
|
|
@ -28,12 +28,10 @@ Module::Module(JS::Realm& realm, size_t index)
|
|||
{
|
||||
}
|
||||
|
||||
JS::ThrowCompletionOr<void> Module::initialize(JS::Realm& realm)
|
||||
void Module::initialize(JS::Realm& realm)
|
||||
{
|
||||
MUST_OR_THROW_OOM(Base::initialize(realm));
|
||||
Base::initialize(realm);
|
||||
set_prototype(&Bindings::ensure_web_prototype<Bindings::ModulePrototype>(realm, "WebAssembly.Module"sv));
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
Wasm::Module const& Module::module() const
|
||||
|
|
|
@ -28,7 +28,7 @@ public:
|
|||
private:
|
||||
Module(JS::Realm&, size_t index);
|
||||
|
||||
virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
|
||||
size_t m_index { 0 };
|
||||
};
|
||||
|
|
|
@ -61,12 +61,10 @@ Table::Table(JS::Realm& realm, Wasm::TableAddress address)
|
|||
{
|
||||
}
|
||||
|
||||
JS::ThrowCompletionOr<void> Table::initialize(JS::Realm& realm)
|
||||
void Table::initialize(JS::Realm& realm)
|
||||
{
|
||||
MUST_OR_THROW_OOM(Base::initialize(realm));
|
||||
Base::initialize(realm);
|
||||
set_prototype(&Bindings::ensure_web_prototype<Bindings::TablePrototype>(realm, "WebAssembly.Table"sv));
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
// https://webassembly.github.io/spec/js-api/#dom-table-grow
|
||||
|
|
|
@ -42,7 +42,7 @@ public:
|
|||
private:
|
||||
Table(JS::Realm&, Wasm::TableAddress);
|
||||
|
||||
virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
|
||||
Wasm::TableAddress m_address;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue