1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 07:57:46 +00:00

LibJS+Everywhere: Allow Cell::initialize overrides to throw OOM errors

Note that as of this commit, there aren't any such throwers, and the
call site in Heap::allocate will drop exceptions on the floor. This
commit only serves to change the declaration of the overrides, make sure
they return an empty value, and to propagate OOM errors frm their base
initialize invocations.
This commit is contained in:
Timothy Flynn 2023-01-28 12:33:35 -05:00 committed by Linus Groh
parent 1c1b902a6a
commit 2692db8699
694 changed files with 1774 additions and 1065 deletions

View file

@ -39,13 +39,15 @@ JS::ThrowCompletionOr<JS::NonnullGCPtr<JS::Object>> WebAssemblyInstanceConstruct
return heap().allocate<WebAssemblyInstanceObject>(realm, realm, result);
}
void WebAssemblyInstanceConstructor::initialize(JS::Realm& realm)
JS::ThrowCompletionOr<void> WebAssemblyInstanceConstructor::initialize(JS::Realm& realm)
{
auto& vm = this->vm();
NativeFunction::initialize(realm);
MUST_OR_THROW_OOM(NativeFunction::initialize(realm));
define_direct_property(vm.names.prototype, &Bindings::ensure_web_prototype<WebAssemblyInstancePrototype>(realm, "WebAssembly.Instance"), 0);
define_direct_property(vm.names.length, JS::Value(1), JS::Attribute::Configurable);
return {};
}
}

View file

@ -15,7 +15,7 @@ class WebAssemblyInstanceConstructor : public JS::NativeFunction {
public:
explicit WebAssemblyInstanceConstructor(JS::Realm&);
virtual void initialize(JS::Realm&) override;
virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
virtual ~WebAssemblyInstanceConstructor() override;
virtual JS::ThrowCompletionOr<JS::Value> call() override;

View file

@ -24,9 +24,9 @@ WebAssemblyInstanceObject::WebAssemblyInstanceObject(JS::Realm& realm, size_t in
{
}
void WebAssemblyInstanceObject::initialize(JS::Realm& realm)
JS::ThrowCompletionOr<void> WebAssemblyInstanceObject::initialize(JS::Realm& realm)
{
Object::initialize(realm);
MUST_OR_THROW_OOM(Object::initialize(realm));
auto& vm = this->vm();
@ -66,6 +66,8 @@ void WebAssemblyInstanceObject::initialize(JS::Realm& realm)
}
MUST(m_exports_object->set_integrity_level(IntegrityLevel::Frozen));
return {};
}
void WebAssemblyInstanceObject::visit_edges(Visitor& visitor)

View file

@ -20,7 +20,7 @@ class WebAssemblyInstanceObject final : public JS::Object {
public:
explicit WebAssemblyInstanceObject(JS::Realm&, size_t index);
virtual void initialize(JS::Realm&) override;
virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
virtual ~WebAssemblyInstanceObject() override = default;
size_t index() const { return m_index; }

View file

@ -10,10 +10,12 @@
namespace Web::Bindings {
void WebAssemblyInstancePrototype::initialize(JS::Realm& realm)
JS::ThrowCompletionOr<void> WebAssemblyInstancePrototype::initialize(JS::Realm& realm)
{
Object::initialize(realm);
MUST_OR_THROW_OOM(Object::initialize(realm));
define_native_accessor(realm, "exports", exports_getter, {}, JS::Attribute::Enumerable | JS::Attribute::Configurable);
return {};
}
JS_DEFINE_NATIVE_FUNCTION(WebAssemblyInstancePrototype::exports_getter)

View file

@ -22,7 +22,7 @@ public:
{
}
virtual void initialize(JS::Realm&) override;
virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
private:
JS_DECLARE_NATIVE_FUNCTION(exports_getter);

View file

@ -49,13 +49,15 @@ JS::ThrowCompletionOr<JS::NonnullGCPtr<JS::Object>> WebAssemblyMemoryConstructor
return vm.heap().allocate<WebAssemblyMemoryObject>(realm, realm, *address);
}
void WebAssemblyMemoryConstructor::initialize(JS::Realm& realm)
JS::ThrowCompletionOr<void> WebAssemblyMemoryConstructor::initialize(JS::Realm& realm)
{
auto& vm = this->vm();
NativeFunction::initialize(realm);
MUST_OR_THROW_OOM(NativeFunction::initialize(realm));
define_direct_property(vm.names.prototype, &Bindings::ensure_web_prototype<WebAssemblyMemoryPrototype>(realm, "WebAssembly.Memory"), 0);
define_direct_property(vm.names.length, JS::Value(1), JS::Attribute::Configurable);
return {};
}
}

View file

@ -15,7 +15,7 @@ class WebAssemblyMemoryConstructor : public JS::NativeFunction {
public:
explicit WebAssemblyMemoryConstructor(JS::Realm&);
virtual void initialize(JS::Realm&) override;
virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
virtual ~WebAssemblyMemoryConstructor() override;
virtual JS::ThrowCompletionOr<JS::Value> call() override;

View file

@ -11,11 +11,13 @@
namespace Web::Bindings {
void WebAssemblyMemoryPrototype::initialize(JS::Realm& realm)
JS::ThrowCompletionOr<void> WebAssemblyMemoryPrototype::initialize(JS::Realm& realm)
{
Object::initialize(realm);
MUST_OR_THROW_OOM(Object::initialize(realm));
define_native_accessor(realm, "buffer", buffer_getter, {}, JS::Attribute::Enumerable | JS::Attribute::Configurable);
define_native_function(realm, "grow", grow, 1, JS::Attribute::Writable | JS::Attribute::Enumerable | JS::Attribute::Configurable);
return {};
}
JS_DEFINE_NATIVE_FUNCTION(WebAssemblyMemoryPrototype::grow)

View file

@ -22,7 +22,7 @@ public:
{
}
virtual void initialize(JS::Realm&) override;
virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
private:
JS_DECLARE_NATIVE_FUNCTION(grow);

View file

@ -36,13 +36,15 @@ JS::ThrowCompletionOr<JS::NonnullGCPtr<JS::Object>> WebAssemblyModuleConstructor
return heap().allocate<WebAssemblyModuleObject>(realm, realm, result);
}
void WebAssemblyModuleConstructor::initialize(JS::Realm& realm)
JS::ThrowCompletionOr<void> WebAssemblyModuleConstructor::initialize(JS::Realm& realm)
{
auto& vm = this->vm();
NativeFunction::initialize(realm);
MUST_OR_THROW_OOM(NativeFunction::initialize(realm));
define_direct_property(vm.names.prototype, &Bindings::ensure_web_prototype<WebAssemblyModulePrototype>(realm, "WebAssembly.Module"), 0);
define_direct_property(vm.names.length, JS::Value(1), JS::Attribute::Configurable);
return {};
}
}

View file

@ -15,7 +15,7 @@ class WebAssemblyModuleConstructor : public JS::NativeFunction {
public:
explicit WebAssemblyModuleConstructor(JS::Realm&);
virtual void initialize(JS::Realm&) override;
virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
virtual ~WebAssemblyModuleConstructor() override;
virtual JS::ThrowCompletionOr<JS::Value> call() override;

View file

@ -32,9 +32,9 @@ WebAssemblyObject::WebAssemblyObject(JS::Realm& realm)
s_abstract_machine.enable_instruction_count_limit();
}
void WebAssemblyObject::initialize(JS::Realm& realm)
JS::ThrowCompletionOr<void> WebAssemblyObject::initialize(JS::Realm& realm)
{
Object::initialize(realm);
MUST_OR_THROW_OOM(Object::initialize(realm));
u8 attr = JS::Attribute::Configurable | JS::Attribute::Writable | JS::Attribute::Enumerable;
define_native_function(realm, "validate", validate, 1, attr);
@ -52,6 +52,8 @@ void WebAssemblyObject::initialize(JS::Realm& realm)
auto& table_constructor = Bindings::ensure_web_constructor<WebAssemblyTablePrototype>(realm, "WebAssembly.Table"sv);
define_direct_property("Table", &table_constructor, JS::Attribute::Writable | JS::Attribute::Configurable);
return {};
}
NonnullOwnPtrVector<WebAssemblyObject::CompiledWebAssemblyModule> WebAssemblyObject::s_compiled_modules;

View file

@ -25,7 +25,7 @@ class WebAssemblyObject final : public JS::Object {
public:
explicit WebAssemblyObject(JS::Realm&);
virtual void initialize(JS::Realm&) override;
virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
virtual ~WebAssemblyObject() override = default;
virtual void visit_edges(Cell::Visitor&) override;

View file

@ -80,13 +80,15 @@ JS::ThrowCompletionOr<JS::NonnullGCPtr<JS::Object>> WebAssemblyTableConstructor:
return vm.heap().allocate<WebAssemblyTableObject>(realm, realm, *address);
}
void WebAssemblyTableConstructor::initialize(JS::Realm& realm)
JS::ThrowCompletionOr<void> WebAssemblyTableConstructor::initialize(JS::Realm& realm)
{
auto& vm = this->vm();
NativeFunction::initialize(realm);
MUST_OR_THROW_OOM(NativeFunction::initialize(realm));
define_direct_property(vm.names.prototype, &Bindings::ensure_web_prototype<WebAssemblyTablePrototype>(realm, "WebAssembly.Table"), 0);
define_direct_property(vm.names.length, JS::Value(1), JS::Attribute::Configurable);
return {};
}
}

View file

@ -15,7 +15,7 @@ class WebAssemblyTableConstructor : public JS::NativeFunction {
public:
explicit WebAssemblyTableConstructor(JS::Realm&);
virtual void initialize(JS::Realm&) override;
virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
virtual ~WebAssemblyTableConstructor() override;
virtual JS::ThrowCompletionOr<JS::Value> call() override;

View file

@ -11,13 +11,15 @@
namespace Web::Bindings {
void WebAssemblyTablePrototype::initialize(JS::Realm& realm)
JS::ThrowCompletionOr<void> WebAssemblyTablePrototype::initialize(JS::Realm& realm)
{
Object::initialize(realm);
MUST_OR_THROW_OOM(Object::initialize(realm));
define_native_accessor(realm, "length", length_getter, {}, JS::Attribute::Enumerable | JS::Attribute::Configurable);
define_native_function(realm, "grow", grow, 1, JS::Attribute::Writable | JS::Attribute::Enumerable | JS::Attribute::Configurable);
define_native_function(realm, "get", get, 1, JS::Attribute::Writable | JS::Attribute::Enumerable | JS::Attribute::Configurable);
define_native_function(realm, "set", set, 1, JS::Attribute::Writable | JS::Attribute::Enumerable | JS::Attribute::Configurable);
return {};
}
JS_DEFINE_NATIVE_FUNCTION(WebAssemblyTablePrototype::grow)

View file

@ -22,7 +22,7 @@ public:
{
}
virtual void initialize(JS::Realm&) override;
virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
private:
JS_DECLARE_NATIVE_FUNCTION(grow);