mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 06:07:34 +00:00
LibJS: Make Heap::allocate<T>() infallible
Stop worrying about tiny OOMs. Work towards #20449. While going through these, I also changed the function signature in many places where returning ThrowCompletionOr<T> is no longer necessary.
This commit is contained in:
parent
980e7164fe
commit
72c9f56c66
337 changed files with 1229 additions and 1251 deletions
|
@ -23,7 +23,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMMatrix>> DOMMatrix::construct_impl(JS::R
|
|||
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, TRY_OR_THROW_OOM(vm, String::formatted("Sequence must contain exactly 6 or 16 elements, got {} element(s)", double_sequence->size())) };
|
||||
}
|
||||
|
||||
return realm.heap().allocate<DOMMatrix>(realm, realm, init).release_allocated_value_but_fixme_should_propagate_errors();
|
||||
return realm.heap().allocate<DOMMatrix>(realm, realm, init);
|
||||
}
|
||||
|
||||
// https://drafts.fxtf.org/geometry/#create-a-dommatrix-from-the-2d-dictionary
|
||||
|
@ -42,12 +42,12 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMMatrix>> DOMMatrix::create_from_dom_matr
|
|||
|
||||
// 2. Return the result of invoking create a 2d matrix of type DOMMatrixReadOnly or DOMMatrix as appropriate, with a sequence of numbers,
|
||||
// the values being the 6 elements m11, m12, m21, m22, m41 and m42 of other in the given order.
|
||||
return realm.heap().allocate<DOMMatrix>(realm, realm, init.m11.value(), init.m12.value(), init.m21.value(), init.m22.value(), init.m41.value(), init.m42.value()).release_allocated_value_but_fixme_should_propagate_errors();
|
||||
return realm.heap().allocate<DOMMatrix>(realm, realm, init.m11.value(), init.m12.value(), init.m21.value(), init.m22.value(), init.m41.value(), init.m42.value());
|
||||
}
|
||||
|
||||
JS::NonnullGCPtr<DOMMatrix> DOMMatrix::create_from_dom_matrix_read_only(JS::Realm& realm, DOMMatrixReadOnly const& read_only_matrix)
|
||||
{
|
||||
return realm.heap().allocate<DOMMatrix>(realm, realm, read_only_matrix).release_allocated_value_but_fixme_should_propagate_errors();
|
||||
return realm.heap().allocate<DOMMatrix>(realm, realm, read_only_matrix);
|
||||
}
|
||||
|
||||
DOMMatrix::DOMMatrix(JS::Realm& realm, double m11, double m12, double m21, double m22, double m41, double m42)
|
||||
|
|
|
@ -24,7 +24,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMMatrixReadOnly>> DOMMatrixReadOnly::cons
|
|||
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, TRY_OR_THROW_OOM(vm, String::formatted("Sequence must contain exactly 6 or 16 elements, got {} element(s)", double_sequence->size())) };
|
||||
}
|
||||
|
||||
return realm.heap().allocate<DOMMatrixReadOnly>(realm, realm, init).release_allocated_value_but_fixme_should_propagate_errors();
|
||||
return realm.heap().allocate<DOMMatrixReadOnly>(realm, realm, init);
|
||||
}
|
||||
|
||||
// https://drafts.fxtf.org/geometry/#create-a-dommatrixreadonly-from-the-2d-dictionary
|
||||
|
@ -43,7 +43,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMMatrixReadOnly>> DOMMatrixReadOnly::crea
|
|||
|
||||
// 2. Return the result of invoking create a 2d matrix of type DOMMatrixReadOnly or DOMMatrix as appropriate, with a sequence of numbers,
|
||||
// the values being the 6 elements m11, m12, m21, m22, m41 and m42 of other in the given order.
|
||||
return realm.heap().allocate<DOMMatrixReadOnly>(realm, realm, init.m11.value(), init.m12.value(), init.m21.value(), init.m22.value(), init.m41.value(), init.m42.value()).release_allocated_value_but_fixme_should_propagate_errors();
|
||||
return realm.heap().allocate<DOMMatrixReadOnly>(realm, realm, init.m11.value(), init.m12.value(), init.m21.value(), init.m22.value(), init.m41.value(), init.m42.value());
|
||||
}
|
||||
|
||||
DOMMatrixReadOnly::DOMMatrixReadOnly(JS::Realm& realm, double m11, double m12, double m21, double m22, double m41, double m42)
|
||||
|
|
|
@ -13,7 +13,7 @@ namespace Web::Geometry {
|
|||
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMPoint>> DOMPoint::construct_impl(JS::Realm& realm, double x, double y, double z, double w)
|
||||
{
|
||||
return MUST_OR_THROW_OOM(realm.heap().allocate<DOMPoint>(realm, realm, x, y, z, w));
|
||||
return realm.heap().allocate<DOMPoint>(realm, realm, x, y, z, w);
|
||||
}
|
||||
|
||||
DOMPoint::DOMPoint(JS::Realm& realm, double x, double y, double z, double w)
|
||||
|
|
|
@ -13,7 +13,7 @@ namespace Web::Geometry {
|
|||
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMPointReadOnly>> DOMPointReadOnly::construct_impl(JS::Realm& realm, double x, double y, double z, double w)
|
||||
{
|
||||
return MUST_OR_THROW_OOM(realm.heap().allocate<DOMPointReadOnly>(realm, realm, x, y, z, w));
|
||||
return realm.heap().allocate<DOMPointReadOnly>(realm, realm, x, y, z, w);
|
||||
}
|
||||
|
||||
DOMPointReadOnly::DOMPointReadOnly(JS::Realm& realm, double x, double y, double z, double w)
|
||||
|
|
|
@ -12,19 +12,19 @@ namespace Web::Geometry {
|
|||
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMRect>> DOMRect::construct_impl(JS::Realm& realm, double x, double y, double width, double height)
|
||||
{
|
||||
return MUST_OR_THROW_OOM(realm.heap().allocate<DOMRect>(realm, realm, x, y, width, height));
|
||||
return create(realm, Gfx::FloatRect { x, y, width, height });
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMRect>> DOMRect::create(JS::Realm& realm, Gfx::FloatRect const& rect)
|
||||
JS::NonnullGCPtr<DOMRect> DOMRect::create(JS::Realm& realm, Gfx::FloatRect const& rect)
|
||||
{
|
||||
return construct_impl(realm, rect.x(), rect.y(), rect.width(), rect.height());
|
||||
return realm.heap().allocate<DOMRect>(realm, realm, rect.x(), rect.y(), rect.width(), rect.height());
|
||||
}
|
||||
|
||||
// https://drafts.fxtf.org/geometry/#create-a-domrect-from-the-dictionary
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMRect>> DOMRect::from_rect(JS::VM& vm, Geometry::DOMRectInit const& other)
|
||||
JS::NonnullGCPtr<DOMRect> DOMRect::from_rect(JS::VM& vm, Geometry::DOMRectInit const& other)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
return MUST_OR_THROW_OOM(realm.heap().allocate<DOMRect>(realm, realm, other.x, other.y, other.width, other.height));
|
||||
return realm.heap().allocate<DOMRect>(realm, realm, other.x, other.y, other.width, other.height);
|
||||
}
|
||||
|
||||
DOMRect::DOMRect(JS::Realm& realm, double x, double y, double width, double height)
|
||||
|
|
|
@ -16,8 +16,8 @@ class DOMRect final : public DOMRectReadOnly {
|
|||
|
||||
public:
|
||||
static WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMRect>> construct_impl(JS::Realm&, double x = 0, double y = 0, double width = 0, double height = 0);
|
||||
static WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMRect>> create(JS::Realm&, Gfx::FloatRect const&);
|
||||
static WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMRect>> from_rect(JS::VM&, DOMRectInit const&);
|
||||
[[nodiscard]] static JS::NonnullGCPtr<DOMRect> create(JS::Realm&, Gfx::FloatRect const&);
|
||||
[[nodiscard]] static JS::NonnullGCPtr<DOMRect> from_rect(JS::VM&, DOMRectInit const&);
|
||||
|
||||
virtual ~DOMRect() override;
|
||||
|
||||
|
|
|
@ -12,12 +12,12 @@
|
|||
|
||||
namespace Web::Geometry {
|
||||
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMRectList>> DOMRectList::create(JS::Realm& realm, Vector<JS::Handle<DOMRect>> rect_handles)
|
||||
JS::NonnullGCPtr<DOMRectList> DOMRectList::create(JS::Realm& realm, Vector<JS::Handle<DOMRect>> rect_handles)
|
||||
{
|
||||
Vector<JS::NonnullGCPtr<DOMRect>> rects;
|
||||
for (auto& rect : rect_handles)
|
||||
rects.append(*rect);
|
||||
return MUST_OR_THROW_OOM(realm.heap().allocate<DOMRectList>(realm, realm, move(rects)));
|
||||
return realm.heap().allocate<DOMRectList>(realm, realm, move(rects));
|
||||
}
|
||||
|
||||
DOMRectList::DOMRectList(JS::Realm& realm, Vector<JS::NonnullGCPtr<DOMRect>> rects)
|
||||
|
|
|
@ -18,7 +18,7 @@ class DOMRectList final : public Bindings::LegacyPlatformObject {
|
|||
WEB_PLATFORM_OBJECT(DOMRectList, Bindings::LegacyPlatformObject);
|
||||
|
||||
public:
|
||||
static WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMRectList>> create(JS::Realm&, Vector<JS::Handle<DOMRect>>);
|
||||
[[nodiscard]] static JS::NonnullGCPtr<DOMRectList> create(JS::Realm&, Vector<JS::Handle<DOMRect>>);
|
||||
|
||||
virtual ~DOMRectList() override;
|
||||
|
||||
|
|
|
@ -12,14 +12,14 @@ namespace Web::Geometry {
|
|||
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMRectReadOnly>> DOMRectReadOnly::construct_impl(JS::Realm& realm, double x, double y, double width, double height)
|
||||
{
|
||||
return MUST_OR_THROW_OOM(realm.heap().allocate<DOMRectReadOnly>(realm, realm, x, y, width, height));
|
||||
return realm.heap().allocate<DOMRectReadOnly>(realm, realm, x, y, width, height);
|
||||
}
|
||||
|
||||
// https://drafts.fxtf.org/geometry/#create-a-domrect-from-the-dictionary
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMRectReadOnly>> DOMRectReadOnly::from_rect(JS::VM& vm, Geometry::DOMRectInit const& other)
|
||||
JS::NonnullGCPtr<DOMRectReadOnly> DOMRectReadOnly::from_rect(JS::VM& vm, Geometry::DOMRectInit const& other)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
return MUST_OR_THROW_OOM(realm.heap().allocate<DOMRectReadOnly>(realm, realm, other.x, other.y, other.width, other.height));
|
||||
return realm.heap().allocate<DOMRectReadOnly>(realm, realm, other.x, other.y, other.width, other.height);
|
||||
}
|
||||
|
||||
DOMRectReadOnly::DOMRectReadOnly(JS::Realm& realm, double x, double y, double width, double height)
|
||||
|
|
|
@ -26,7 +26,7 @@ class DOMRectReadOnly : public Bindings::PlatformObject {
|
|||
|
||||
public:
|
||||
static WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMRectReadOnly>> construct_impl(JS::Realm&, double x = 0, double y = 0, double width = 0, double height = 0);
|
||||
static WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMRectReadOnly>> from_rect(JS::VM&, DOMRectInit const&);
|
||||
[[nodiscard]] static JS::NonnullGCPtr<DOMRectReadOnly> from_rect(JS::VM&, DOMRectInit const&);
|
||||
|
||||
virtual ~DOMRectReadOnly() override;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue