1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 03:17:34 +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

@ -18,13 +18,15 @@ AudioConstructor::AudioConstructor(JS::Realm& realm)
{
}
void AudioConstructor::initialize(JS::Realm& realm)
JS::ThrowCompletionOr<void> AudioConstructor::initialize(JS::Realm& realm)
{
auto& vm = this->vm();
NativeFunction::initialize(realm);
MUST_OR_THROW_OOM(NativeFunction::initialize(realm));
define_direct_property(vm.names.prototype, &ensure_web_prototype<Bindings::HTMLAudioElementPrototype>(realm, "HTMLAudioElement"), 0);
define_direct_property(vm.names.length, JS::Value(0), JS::Attribute::Configurable);
return {};
}
JS::ThrowCompletionOr<JS::Value> AudioConstructor::call()

View file

@ -14,7 +14,7 @@ namespace Web::Bindings {
class AudioConstructor final : public JS::NativeFunction {
public:
explicit AudioConstructor(JS::Realm&);
virtual void initialize(JS::Realm&) override;
virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
virtual ~AudioConstructor() override = default;
virtual JS::ThrowCompletionOr<JS::Value> call() override;

View file

@ -18,12 +18,14 @@ CSSNamespace::CSSNamespace(JS::Realm& realm)
{
}
void CSSNamespace::initialize(JS::Realm& realm)
JS::ThrowCompletionOr<void> CSSNamespace::initialize(JS::Realm& realm)
{
Object::initialize(realm);
MUST_OR_THROW_OOM(Object::initialize(realm));
u8 attr = JS::Attribute::Enumerable;
define_native_function(realm, "escape", escape, 1, attr);
define_native_function(realm, "supports", supports, 2, attr);
return {};
}
// https://www.w3.org/TR/cssom-1/#dom-css-escape

View file

@ -17,7 +17,7 @@ class CSSNamespace final : public JS::Object {
public:
explicit CSSNamespace(JS::Realm&);
virtual void initialize(JS::Realm&) override;
virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
virtual ~CSSNamespace() override = default;
private:

View file

@ -18,13 +18,15 @@ ImageConstructor::ImageConstructor(JS::Realm& realm)
{
}
void ImageConstructor::initialize(JS::Realm& realm)
JS::ThrowCompletionOr<void> ImageConstructor::initialize(JS::Realm& realm)
{
auto& vm = this->vm();
NativeFunction::initialize(realm);
MUST_OR_THROW_OOM(NativeFunction::initialize(realm));
define_direct_property(vm.names.prototype, &ensure_web_prototype<Bindings::HTMLImageElementPrototype>(realm, "HTMLImageElement"), 0);
define_direct_property(vm.names.length, JS::Value(0), JS::Attribute::Configurable);
return {};
}
JS::ThrowCompletionOr<JS::Value> ImageConstructor::call()

View file

@ -14,7 +14,7 @@ namespace Web::Bindings {
class ImageConstructor final : public JS::NativeFunction {
public:
explicit ImageConstructor(JS::Realm&);
virtual void initialize(JS::Realm&) override;
virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
virtual ~ImageConstructor() override = default;
virtual JS::ThrowCompletionOr<JS::Value> call() override;

View file

@ -20,13 +20,15 @@ OptionConstructor::OptionConstructor(JS::Realm& realm)
{
}
void OptionConstructor::initialize(JS::Realm& realm)
JS::ThrowCompletionOr<void> OptionConstructor::initialize(JS::Realm& realm)
{
auto& vm = this->vm();
NativeFunction::initialize(realm);
MUST_OR_THROW_OOM(NativeFunction::initialize(realm));
define_direct_property(vm.names.prototype, &ensure_web_prototype<Bindings::HTMLOptionElementPrototype>(realm, "HTMLOptionElement"), 0);
define_direct_property(vm.names.length, JS::Value(0), JS::Attribute::Configurable);
return {};
}
JS::ThrowCompletionOr<JS::Value> OptionConstructor::call()

View file

@ -14,7 +14,7 @@ namespace Web::Bindings {
class OptionConstructor final : public JS::NativeFunction {
public:
explicit OptionConstructor(JS::Realm&);
virtual void initialize(JS::Realm&) override;
virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
virtual ~OptionConstructor() override = default;
virtual JS::ThrowCompletionOr<JS::Value> call() override;

View file

@ -27,13 +27,15 @@ JS::ThrowCompletionOr<JS::NonnullGCPtr<JS::Object>> WindowConstructor::construct
return vm().throw_completion<JS::TypeError>(JS::ErrorType::NotAConstructor, "Window");
}
void WindowConstructor::initialize(JS::Realm& realm)
JS::ThrowCompletionOr<void> WindowConstructor::initialize(JS::Realm& realm)
{
auto& vm = this->vm();
NativeFunction::initialize(realm);
MUST_OR_THROW_OOM(NativeFunction::initialize(realm));
define_direct_property(vm.names.prototype, &ensure_web_prototype<Bindings::WindowPrototype>(realm, "Window"), 0);
define_direct_property(vm.names.length, JS::Value(0), JS::Attribute::Configurable);
return {};
}
}

View file

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

View file

@ -14,10 +14,12 @@ WindowPrototype::WindowPrototype(JS::Realm& realm)
{
}
void WindowPrototype::initialize(JS::Realm& realm)
JS::ThrowCompletionOr<void> WindowPrototype::initialize(JS::Realm& realm)
{
Base::initialize(realm);
MUST_OR_THROW_OOM(Base::initialize(realm));
set_prototype(&Bindings::ensure_web_prototype<Bindings::EventTargetPrototype>(realm, "EventTarget"));
return {};
}
}

View file

@ -19,7 +19,7 @@ public:
explicit WindowPrototype(JS::Realm& realm);
private:
virtual void initialize(JS::Realm&) override;
virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
};
}