summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Runtime
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2023-01-28 13:39:44 -0500
committerLinus Groh <mail@linusgroh.de>2023-01-29 00:02:45 +0000
commitb75b7f0c0d6980e474f4aad910c6b7d45c876518 (patch)
tree2907bdea34ff11105129d1d28c8a90118c52feb6 /Userland/Libraries/LibJS/Runtime
parent109b190a19e55f407521de14cd1f984ae61d77bf (diff)
downloadserenity-b75b7f0c0d6980e474f4aad910c6b7d45c876518.zip
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.
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime')
-rw-r--r--Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/AbstractOperations.h2
-rw-r--r--Userland/Libraries/LibJS/Runtime/AggregateError.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/Array.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/ArrayBuffer.cpp6
-rw-r--r--Userland/Libraries/LibJS/Runtime/ArrayIterator.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/AsyncFromSyncIterator.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/AsyncFunctionDriverWrapper.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/BigIntObject.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/BooleanObject.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/BoundFunction.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/DataView.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/Date.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp6
-rw-r--r--Userland/Libraries/LibJS/Runtime/Error.cpp38
-rw-r--r--Userland/Libraries/LibJS/Runtime/GeneratorObject.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/CollatorCompareFunction.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatFunction.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/Locale.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/NumberFormatFunction.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/SegmentIterator.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/Segments.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intrinsics.cpp124
-rw-r--r--Userland/Libraries/LibJS/Runtime/Map.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/MapIterator.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/NativeFunction.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/NumberObject.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/Object.cpp9
-rw-r--r--Userland/Libraries/LibJS/Runtime/Promise.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/PromiseResolvingElementFunctions.cpp8
-rw-r--r--Userland/Libraries/LibJS/Runtime/PromiseResolvingFunction.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/ProxyObject.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/RegExpObject.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/RegExpStringIterator.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/Set.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/SetIterator.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/StringIterator.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/StringObject.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/SuppressedError.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/SymbolObject.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/Temporal.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/TypedArray.cpp270
-rw-r--r--Userland/Libraries/LibJS/Runtime/WeakMap.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/WeakRef.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/WeakSet.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/WrappedFunction.cpp2
46 files changed, 272 insertions, 273 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp
index bad2a4cf74..5005043989 100644
--- a/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp
+++ b/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp
@@ -1104,7 +1104,7 @@ Object* create_mapped_arguments_object(VM& vm, FunctionObject& function, Vector<
// 7. Set obj.[[Set]] as specified in 10.4.4.4.
// 8. Set obj.[[Delete]] as specified in 10.4.4.5.
// 9. Set obj.[[Prototype]] to %Object.prototype%.
- auto object = vm.heap().allocate<ArgumentsObject>(realm, realm, environment);
+ auto object = vm.heap().allocate<ArgumentsObject>(realm, realm, environment).release_allocated_value_but_fixme_should_propagate_errors();
// 14. Let index be 0.
// 15. Repeat, while index < len,
diff --git a/Userland/Libraries/LibJS/Runtime/AbstractOperations.h b/Userland/Libraries/LibJS/Runtime/AbstractOperations.h
index a72915e651..105108c753 100644
--- a/Userland/Libraries/LibJS/Runtime/AbstractOperations.h
+++ b/Userland/Libraries/LibJS/Runtime/AbstractOperations.h
@@ -146,7 +146,7 @@ ThrowCompletionOr<NonnullGCPtr<T>> ordinary_create_from_constructor(VM& vm, Func
{
auto& realm = *vm.current_realm();
auto* prototype = TRY(get_prototype_from_constructor(vm, constructor, intrinsic_default_prototype));
- return realm.heap().allocate<T>(realm, forward<Args>(args)..., *prototype);
+ return MUST_OR_THROW_OOM(realm.heap().allocate<T>(realm, forward<Args>(args)..., *prototype));
}
// 14.1 MergeLists ( a, b ), https://tc39.es/proposal-temporal/#sec-temporal-mergelists
diff --git a/Userland/Libraries/LibJS/Runtime/AggregateError.cpp b/Userland/Libraries/LibJS/Runtime/AggregateError.cpp
index 7780e464cf..1f3a225b80 100644
--- a/Userland/Libraries/LibJS/Runtime/AggregateError.cpp
+++ b/Userland/Libraries/LibJS/Runtime/AggregateError.cpp
@@ -12,7 +12,7 @@ namespace JS {
NonnullGCPtr<AggregateError> AggregateError::create(Realm& realm)
{
- return realm.heap().allocate<AggregateError>(realm, *realm.intrinsics().aggregate_error_prototype());
+ return realm.heap().allocate<AggregateError>(realm, *realm.intrinsics().aggregate_error_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
}
AggregateError::AggregateError(Object& prototype)
diff --git a/Userland/Libraries/LibJS/Runtime/Array.cpp b/Userland/Libraries/LibJS/Runtime/Array.cpp
index 4bf4922556..02ea98bc4b 100644
--- a/Userland/Libraries/LibJS/Runtime/Array.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Array.cpp
@@ -32,7 +32,7 @@ ThrowCompletionOr<NonnullGCPtr<Array>> Array::create(Realm& realm, u64 length, O
// 3. Let A be MakeBasicObject(ยซ [[Prototype]], [[Extensible]] ยป).
// 4. Set A.[[Prototype]] to proto.
// 5. Set A.[[DefineOwnProperty]] as specified in 10.4.2.1.
- auto array = realm.heap().allocate<Array>(realm, *prototype);
+ auto array = MUST_OR_THROW_OOM(realm.heap().allocate<Array>(realm, *prototype));
// 6. Perform ! OrdinaryDefineOwnProperty(A, "length", PropertyDescriptor { [[Value]]: ๐”ฝ(length), [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }).
MUST(array->internal_define_own_property(vm.names.length, { .value = Value(length), .writable = true, .enumerable = false, .configurable = false }));
diff --git a/Userland/Libraries/LibJS/Runtime/ArrayBuffer.cpp b/Userland/Libraries/LibJS/Runtime/ArrayBuffer.cpp
index 809e1ea3a9..e86be838a3 100644
--- a/Userland/Libraries/LibJS/Runtime/ArrayBuffer.cpp
+++ b/Userland/Libraries/LibJS/Runtime/ArrayBuffer.cpp
@@ -17,17 +17,17 @@ ThrowCompletionOr<NonnullGCPtr<ArrayBuffer>> ArrayBuffer::create(Realm& realm, s
if (buffer.is_error())
return realm.vm().throw_completion<RangeError>(ErrorType::NotEnoughMemoryToAllocate, byte_length);
- return realm.heap().allocate<ArrayBuffer>(realm, buffer.release_value(), *realm.intrinsics().array_buffer_prototype());
+ return MUST_OR_THROW_OOM(realm.heap().allocate<ArrayBuffer>(realm, buffer.release_value(), *realm.intrinsics().array_buffer_prototype()));
}
NonnullGCPtr<ArrayBuffer> ArrayBuffer::create(Realm& realm, ByteBuffer buffer)
{
- return realm.heap().allocate<ArrayBuffer>(realm, move(buffer), *realm.intrinsics().array_buffer_prototype());
+ return realm.heap().allocate<ArrayBuffer>(realm, move(buffer), *realm.intrinsics().array_buffer_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
}
NonnullGCPtr<ArrayBuffer> ArrayBuffer::create(Realm& realm, ByteBuffer* buffer)
{
- return realm.heap().allocate<ArrayBuffer>(realm, buffer, *realm.intrinsics().array_buffer_prototype());
+ return realm.heap().allocate<ArrayBuffer>(realm, buffer, *realm.intrinsics().array_buffer_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
}
ArrayBuffer::ArrayBuffer(ByteBuffer buffer, Object& prototype)
diff --git a/Userland/Libraries/LibJS/Runtime/ArrayIterator.cpp b/Userland/Libraries/LibJS/Runtime/ArrayIterator.cpp
index 4b23b3c3c9..483f25f3d7 100644
--- a/Userland/Libraries/LibJS/Runtime/ArrayIterator.cpp
+++ b/Userland/Libraries/LibJS/Runtime/ArrayIterator.cpp
@@ -11,7 +11,7 @@ namespace JS {
NonnullGCPtr<ArrayIterator> ArrayIterator::create(Realm& realm, Value array, Object::PropertyKind iteration_kind)
{
- return realm.heap().allocate<ArrayIterator>(realm, array, iteration_kind, *realm.intrinsics().array_iterator_prototype());
+ return realm.heap().allocate<ArrayIterator>(realm, array, iteration_kind, *realm.intrinsics().array_iterator_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
}
ArrayIterator::ArrayIterator(Value array, Object::PropertyKind iteration_kind, Object& prototype)
diff --git a/Userland/Libraries/LibJS/Runtime/AsyncFromSyncIterator.cpp b/Userland/Libraries/LibJS/Runtime/AsyncFromSyncIterator.cpp
index 7b3d4e53b3..ad1c97f981 100644
--- a/Userland/Libraries/LibJS/Runtime/AsyncFromSyncIterator.cpp
+++ b/Userland/Libraries/LibJS/Runtime/AsyncFromSyncIterator.cpp
@@ -13,7 +13,7 @@ namespace JS {
NonnullGCPtr<AsyncFromSyncIterator> AsyncFromSyncIterator::create(Realm& realm, Iterator sync_iterator_record)
{
- return realm.heap().allocate<AsyncFromSyncIterator>(realm, realm, sync_iterator_record);
+ return realm.heap().allocate<AsyncFromSyncIterator>(realm, realm, sync_iterator_record).release_allocated_value_but_fixme_should_propagate_errors();
}
AsyncFromSyncIterator::AsyncFromSyncIterator(Realm& realm, Iterator sync_iterator_record)
diff --git a/Userland/Libraries/LibJS/Runtime/AsyncFunctionDriverWrapper.cpp b/Userland/Libraries/LibJS/Runtime/AsyncFunctionDriverWrapper.cpp
index e3afe6ec5c..acae27a191 100644
--- a/Userland/Libraries/LibJS/Runtime/AsyncFunctionDriverWrapper.cpp
+++ b/Userland/Libraries/LibJS/Runtime/AsyncFunctionDriverWrapper.cpp
@@ -15,7 +15,7 @@ namespace JS {
ThrowCompletionOr<Value> AsyncFunctionDriverWrapper::create(Realm& realm, GeneratorObject* generator_object)
{
- auto wrapper = realm.heap().allocate<AsyncFunctionDriverWrapper>(realm, realm, generator_object);
+ auto wrapper = MUST_OR_THROW_OOM(realm.heap().allocate<AsyncFunctionDriverWrapper>(realm, realm, generator_object));
return wrapper->react_to_async_task_completion(realm.vm(), js_undefined(), true);
}
diff --git a/Userland/Libraries/LibJS/Runtime/BigIntObject.cpp b/Userland/Libraries/LibJS/Runtime/BigIntObject.cpp
index 25ffe5b4fd..182d2002f1 100644
--- a/Userland/Libraries/LibJS/Runtime/BigIntObject.cpp
+++ b/Userland/Libraries/LibJS/Runtime/BigIntObject.cpp
@@ -11,7 +11,7 @@ namespace JS {
NonnullGCPtr<BigIntObject> BigIntObject::create(Realm& realm, BigInt& bigint)
{
- return realm.heap().allocate<BigIntObject>(realm, bigint, *realm.intrinsics().bigint_prototype());
+ return realm.heap().allocate<BigIntObject>(realm, bigint, *realm.intrinsics().bigint_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
}
BigIntObject::BigIntObject(BigInt& bigint, Object& prototype)
diff --git a/Userland/Libraries/LibJS/Runtime/BooleanObject.cpp b/Userland/Libraries/LibJS/Runtime/BooleanObject.cpp
index 95121a47f6..964cc3926f 100644
--- a/Userland/Libraries/LibJS/Runtime/BooleanObject.cpp
+++ b/Userland/Libraries/LibJS/Runtime/BooleanObject.cpp
@@ -11,7 +11,7 @@ namespace JS {
NonnullGCPtr<BooleanObject> BooleanObject::create(Realm& realm, bool value)
{
- return realm.heap().allocate<BooleanObject>(realm, value, *realm.intrinsics().boolean_prototype());
+ return realm.heap().allocate<BooleanObject>(realm, value, *realm.intrinsics().boolean_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
}
BooleanObject::BooleanObject(bool value, Object& prototype)
diff --git a/Userland/Libraries/LibJS/Runtime/BoundFunction.cpp b/Userland/Libraries/LibJS/Runtime/BoundFunction.cpp
index 82e34d745f..6c0bc8d7cb 100644
--- a/Userland/Libraries/LibJS/Runtime/BoundFunction.cpp
+++ b/Userland/Libraries/LibJS/Runtime/BoundFunction.cpp
@@ -26,7 +26,7 @@ ThrowCompletionOr<NonnullGCPtr<BoundFunction>> BoundFunction::create(Realm& real
// 7. Set obj.[[BoundTargetFunction]] to targetFunction.
// 8. Set obj.[[BoundThis]] to boundThis.
// 9. Set obj.[[BoundArguments]] to boundArgs.
- auto object = realm.heap().allocate<BoundFunction>(realm, realm, target_function, bound_this, move(bound_arguments), prototype);
+ auto object = MUST_OR_THROW_OOM(realm.heap().allocate<BoundFunction>(realm, realm, target_function, bound_this, move(bound_arguments), prototype));
// 10. Return obj.
return object;
diff --git a/Userland/Libraries/LibJS/Runtime/DataView.cpp b/Userland/Libraries/LibJS/Runtime/DataView.cpp
index 8abf686c46..eb3131b03f 100644
--- a/Userland/Libraries/LibJS/Runtime/DataView.cpp
+++ b/Userland/Libraries/LibJS/Runtime/DataView.cpp
@@ -10,7 +10,7 @@ namespace JS {
NonnullGCPtr<DataView> DataView::create(Realm& realm, ArrayBuffer* viewed_buffer, size_t byte_length, size_t byte_offset)
{
- return realm.heap().allocate<DataView>(realm, viewed_buffer, byte_length, byte_offset, *realm.intrinsics().data_view_prototype());
+ return realm.heap().allocate<DataView>(realm, viewed_buffer, byte_length, byte_offset, *realm.intrinsics().data_view_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
}
DataView::DataView(ArrayBuffer* viewed_buffer, size_t byte_length, size_t byte_offset, Object& prototype)
diff --git a/Userland/Libraries/LibJS/Runtime/Date.cpp b/Userland/Libraries/LibJS/Runtime/Date.cpp
index 873671a633..2c42a60fa4 100644
--- a/Userland/Libraries/LibJS/Runtime/Date.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Date.cpp
@@ -25,7 +25,7 @@ Crypto::SignedBigInteger const ns_per_day_bigint { static_cast<i64>(ns_per_day)
NonnullGCPtr<Date> Date::create(Realm& realm, double date_value)
{
- return realm.heap().allocate<Date>(realm, date_value, *realm.intrinsics().date_prototype());
+ return realm.heap().allocate<Date>(realm, date_value, *realm.intrinsics().date_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
}
Date::Date(double date_value, Object& prototype)
diff --git a/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp b/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp
index af27f64cd4..abb2790ab6 100644
--- a/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp
+++ b/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp
@@ -45,12 +45,12 @@ NonnullGCPtr<ECMAScriptFunctionObject> ECMAScriptFunctionObject::create(Realm& r
prototype = realm.intrinsics().async_generator_function_prototype();
break;
}
- return realm.heap().allocate<ECMAScriptFunctionObject>(realm, move(name), move(source_text), ecmascript_code, move(parameters), m_function_length, parent_environment, private_environment, *prototype, kind, is_strict, might_need_arguments_object, contains_direct_call_to_eval, is_arrow_function, move(class_field_initializer_name));
+ return realm.heap().allocate<ECMAScriptFunctionObject>(realm, move(name), move(source_text), ecmascript_code, move(parameters), m_function_length, parent_environment, private_environment, *prototype, kind, is_strict, might_need_arguments_object, contains_direct_call_to_eval, is_arrow_function, move(class_field_initializer_name)).release_allocated_value_but_fixme_should_propagate_errors();
}
NonnullGCPtr<ECMAScriptFunctionObject> ECMAScriptFunctionObject::create(Realm& realm, DeprecatedFlyString name, Object& prototype, DeprecatedString source_text, Statement const& ecmascript_code, Vector<FunctionParameter> parameters, i32 m_function_length, Environment* parent_environment, PrivateEnvironment* private_environment, FunctionKind kind, bool is_strict, bool might_need_arguments_object, bool contains_direct_call_to_eval, bool is_arrow_function, Variant<PropertyKey, PrivateName, Empty> class_field_initializer_name)
{
- return realm.heap().allocate<ECMAScriptFunctionObject>(realm, move(name), move(source_text), ecmascript_code, move(parameters), m_function_length, parent_environment, private_environment, prototype, kind, is_strict, might_need_arguments_object, contains_direct_call_to_eval, is_arrow_function, move(class_field_initializer_name));
+ return realm.heap().allocate<ECMAScriptFunctionObject>(realm, move(name), move(source_text), ecmascript_code, move(parameters), m_function_length, parent_environment, private_environment, prototype, kind, is_strict, might_need_arguments_object, contains_direct_call_to_eval, is_arrow_function, move(class_field_initializer_name)).release_allocated_value_but_fixme_should_propagate_errors();
}
ECMAScriptFunctionObject::ECMAScriptFunctionObject(DeprecatedFlyString name, DeprecatedString source_text, Statement const& ecmascript_code, Vector<FunctionParameter> formal_parameters, i32 function_length, Environment* parent_environment, PrivateEnvironment* private_environment, Object& prototype, FunctionKind kind, bool strict, bool might_need_arguments_object, bool contains_direct_call_to_eval, bool is_arrow_function, Variant<PropertyKey, PrivateName, Empty> class_field_initializer_name)
@@ -114,7 +114,7 @@ ThrowCompletionOr<void> ECMAScriptFunctionObject::initialize(Realm& realm)
Object* prototype = nullptr;
switch (m_kind) {
case FunctionKind::Normal:
- prototype = vm.heap().allocate<Object>(realm, *realm.intrinsics().new_ordinary_function_prototype_object_shape());
+ prototype = MUST_OR_THROW_OOM(vm.heap().allocate<Object>(realm, *realm.intrinsics().new_ordinary_function_prototype_object_shape()));
MUST(prototype->define_property_or_throw(vm.names.constructor, { .value = this, .writable = true, .enumerable = false, .configurable = true }));
break;
case FunctionKind::Generator:
diff --git a/Userland/Libraries/LibJS/Runtime/Error.cpp b/Userland/Libraries/LibJS/Runtime/Error.cpp
index 69551c1130..6d11909d54 100644
--- a/Userland/Libraries/LibJS/Runtime/Error.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Error.cpp
@@ -16,7 +16,7 @@ namespace JS {
NonnullGCPtr<Error> Error::create(Realm& realm)
{
- return realm.heap().allocate<Error>(realm, *realm.intrinsics().error_prototype());
+ return realm.heap().allocate<Error>(realm, *realm.intrinsics().error_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
}
NonnullGCPtr<Error> Error::create(Realm& realm, DeprecatedString const& message)
@@ -98,24 +98,24 @@ DeprecatedString Error::stack_string() const
return stack_string_builder.to_deprecated_string();
}
-#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
- NonnullGCPtr<ClassName> ClassName::create(Realm& realm) \
- { \
- return realm.heap().allocate<ClassName>(realm, *realm.intrinsics().snake_name##_prototype()); \
- } \
- \
- NonnullGCPtr<ClassName> ClassName::create(Realm& realm, DeprecatedString const& message) \
- { \
- auto& vm = realm.vm(); \
- auto error = ClassName::create(realm); \
- u8 attr = Attribute::Writable | Attribute::Configurable; \
- error->define_direct_property(vm.names.message, PrimitiveString::create(vm, message), attr); \
- return error; \
- } \
- \
- ClassName::ClassName(Object& prototype) \
- : Error(prototype) \
- { \
+#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
+ NonnullGCPtr<ClassName> ClassName::create(Realm& realm) \
+ { \
+ return realm.heap().allocate<ClassName>(realm, *realm.intrinsics().snake_name##_prototype()).release_allocated_value_but_fixme_should_propagate_errors(); \
+ } \
+ \
+ NonnullGCPtr<ClassName> ClassName::create(Realm& realm, DeprecatedString const& message) \
+ { \
+ auto& vm = realm.vm(); \
+ auto error = ClassName::create(realm); \
+ u8 attr = Attribute::Writable | Attribute::Configurable; \
+ error->define_direct_property(vm.names.message, PrimitiveString::create(vm, message), attr); \
+ return error; \
+ } \
+ \
+ ClassName::ClassName(Object& prototype) \
+ : Error(prototype) \
+ { \
}
JS_ENUMERATE_NATIVE_ERRORS
diff --git a/Userland/Libraries/LibJS/Runtime/GeneratorObject.cpp b/Userland/Libraries/LibJS/Runtime/GeneratorObject.cpp
index 8cba0588c4..ce2a6c4b80 100644
--- a/Userland/Libraries/LibJS/Runtime/GeneratorObject.cpp
+++ b/Userland/Libraries/LibJS/Runtime/GeneratorObject.cpp
@@ -28,7 +28,7 @@ ThrowCompletionOr<NonnullGCPtr<GeneratorObject>> GeneratorObject::create(Realm&
generating_function_prototype = TRY(generating_function->get(vm.names.prototype));
}
auto* generating_function_prototype_object = TRY(generating_function_prototype.to_object(vm));
- auto object = realm.heap().allocate<GeneratorObject>(realm, realm, *generating_function_prototype_object, move(execution_context));
+ auto object = MUST_OR_THROW_OOM(realm.heap().allocate<GeneratorObject>(realm, realm, *generating_function_prototype_object, move(execution_context)));
object->m_generating_function = generating_function;
object->m_frame = move(frame);
object->m_previous_value = initial_value;
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/CollatorCompareFunction.cpp b/Userland/Libraries/LibJS/Runtime/Intl/CollatorCompareFunction.cpp
index 2e711f43bf..1282b39208 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/CollatorCompareFunction.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/CollatorCompareFunction.cpp
@@ -13,7 +13,7 @@ namespace JS::Intl {
NonnullGCPtr<CollatorCompareFunction> CollatorCompareFunction::create(Realm& realm, Collator& collator)
{
- return realm.heap().allocate<CollatorCompareFunction>(realm, realm, collator);
+ return realm.heap().allocate<CollatorCompareFunction>(realm, realm, collator).release_allocated_value_but_fixme_should_propagate_errors();
}
CollatorCompareFunction::CollatorCompareFunction(Realm& realm, Collator& collator)
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatFunction.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatFunction.cpp
index 85e2c35262..ed51ac926b 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatFunction.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatFunction.cpp
@@ -16,7 +16,7 @@ namespace JS::Intl {
// 11.5.5 DateTime Format Functions, https://tc39.es/ecma402/#sec-datetime-format-functions
NonnullGCPtr<DateTimeFormatFunction> DateTimeFormatFunction::create(Realm& realm, DateTimeFormat& date_time_format)
{
- return realm.heap().allocate<DateTimeFormatFunction>(realm, date_time_format, *realm.intrinsics().function_prototype());
+ return realm.heap().allocate<DateTimeFormatFunction>(realm, date_time_format, *realm.intrinsics().function_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
}
DateTimeFormatFunction::DateTimeFormatFunction(DateTimeFormat& date_time_format, Object& prototype)
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/Locale.cpp b/Userland/Libraries/LibJS/Runtime/Intl/Locale.cpp
index 278e91a582..b177efc065 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/Locale.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/Locale.cpp
@@ -16,7 +16,7 @@ namespace JS::Intl {
ThrowCompletionOr<NonnullGCPtr<Locale>> Locale::create(Realm& realm, ::Locale::LocaleID locale_id)
{
- auto locale = realm.heap().allocate<Locale>(realm, *realm.intrinsics().intl_locale_prototype());
+ auto locale = MUST_OR_THROW_OOM(realm.heap().allocate<Locale>(realm, *realm.intrinsics().intl_locale_prototype()));
locale->set_locale(TRY_OR_THROW_OOM(realm.vm(), locale_id.to_string()));
for (auto& extension : locale_id.extensions) {
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/NumberFormatFunction.cpp b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormatFunction.cpp
index bd3e1fef56..7caf51606e 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/NumberFormatFunction.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormatFunction.cpp
@@ -14,7 +14,7 @@ namespace JS::Intl {
// 1.5.2 Number Format Functions, https://tc39.es/proposal-intl-numberformat-v3/out/numberformat/proposed.html#sec-number-format-functions
NonnullGCPtr<NumberFormatFunction> NumberFormatFunction::create(Realm& realm, NumberFormat& number_format)
{
- return realm.heap().allocate<NumberFormatFunction>(realm, number_format, *realm.intrinsics().function_prototype());
+ return realm.heap().allocate<NumberFormatFunction>(realm, number_format, *realm.intrinsics().function_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
}
NumberFormatFunction::NumberFormatFunction(NumberFormat& number_format, Object& prototype)
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/SegmentIterator.cpp b/Userland/Libraries/LibJS/Runtime/Intl/SegmentIterator.cpp
index 1fb4f32d73..8e23fcc6d3 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/SegmentIterator.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/SegmentIterator.cpp
@@ -19,7 +19,7 @@ NonnullGCPtr<SegmentIterator> SegmentIterator::create(Realm& realm, Segmenter& s
// 4. Set iterator.[[IteratedString]] to string.
// 5. Set iterator.[[IteratedStringNextSegmentCodeUnitIndex]] to 0.
// 6. Return iterator.
- return realm.heap().allocate<SegmentIterator>(realm, realm, segmenter, move(string), segments);
+ return realm.heap().allocate<SegmentIterator>(realm, realm, segmenter, move(string), segments).release_allocated_value_but_fixme_should_propagate_errors();
}
// 18.6 Segment Iterator Objects, https://tc39.es/ecma402/#sec-segment-iterator-objects
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/Segments.cpp b/Userland/Libraries/LibJS/Runtime/Intl/Segments.cpp
index 585b3b7229..7f892a3257 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/Segments.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/Segments.cpp
@@ -18,7 +18,7 @@ NonnullGCPtr<Segments> Segments::create(Realm& realm, Segmenter& segmenter, Utf1
// 3. Set segments.[[SegmentsSegmenter]] to segmenter.
// 4. Set segments.[[SegmentsString]] to string.
// 5. Return segments.
- return realm.heap().allocate<Segments>(realm, realm, segmenter, move(string));
+ return realm.heap().allocate<Segments>(realm, realm, segmenter, move(string)).release_allocated_value_but_fixme_should_propagate_errors();
}
// 18.5 Segments Objects, https://tc39.es/ecma402/#sec-segments-objects
diff --git a/Userland/Libraries/LibJS/Runtime/Intrinsics.cpp b/Userland/Libraries/LibJS/Runtime/Intrinsics.cpp
index feac0524d4..8e3c456749 100644
--- a/Userland/Libraries/LibJS/Runtime/Intrinsics.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intrinsics.cpp
@@ -189,26 +189,26 @@ void Intrinsics::initialize_intrinsics(Realm& realm)
#define __JS_ENUMERATE(ClassName, snake_name) \
VERIFY(!m_##snake_name##_prototype); \
- m_##snake_name##_prototype = heap().allocate<ClassName##Prototype>(realm, realm);
+ m_##snake_name##_prototype = heap().allocate<ClassName##Prototype>(realm, realm).release_allocated_value_but_fixme_should_propagate_errors();
JS_ENUMERATE_ITERATOR_PROTOTYPES
#undef __JS_ENUMERATE
// These must be initialized separately as they have no companion constructor
- m_async_from_sync_iterator_prototype = heap().allocate<AsyncFromSyncIteratorPrototype>(realm, realm);
- m_async_generator_prototype = heap().allocate<AsyncGeneratorPrototype>(realm, realm);
- m_generator_prototype = heap().allocate<GeneratorPrototype>(realm, realm);
- m_intl_segments_prototype = heap().allocate<Intl::SegmentsPrototype>(realm, realm);
+ m_async_from_sync_iterator_prototype = heap().allocate<AsyncFromSyncIteratorPrototype>(realm, realm).release_allocated_value_but_fixme_should_propagate_errors();
+ m_async_generator_prototype = heap().allocate<AsyncGeneratorPrototype>(realm, realm).release_allocated_value_but_fixme_should_propagate_errors();
+ m_generator_prototype = heap().allocate<GeneratorPrototype>(realm, realm).release_allocated_value_but_fixme_should_propagate_errors();
+ m_intl_segments_prototype = heap().allocate<Intl::SegmentsPrototype>(realm, realm).release_allocated_value_but_fixme_should_propagate_errors();
// These must be initialized before allocating...
// - AggregateErrorPrototype, which uses ErrorPrototype as its prototype
// - AggregateErrorConstructor, which uses ErrorConstructor as its prototype
// - AsyncFunctionConstructor, which uses FunctionConstructor as its prototype
- m_error_prototype = heap().allocate<ErrorPrototype>(realm, realm);
- m_error_constructor = heap().allocate<ErrorConstructor>(realm, realm);
- m_function_constructor = heap().allocate<FunctionConstructor>(realm, realm);
+ m_error_prototype = heap().allocate<ErrorPrototype>(realm, realm).release_allocated_value_but_fixme_should_propagate_errors();
+ m_error_constructor = heap().allocate<ErrorConstructor>(realm, realm).release_allocated_value_but_fixme_should_propagate_errors();
+ m_function_constructor = heap().allocate<FunctionConstructor>(realm, realm).release_allocated_value_but_fixme_should_propagate_errors();
// Not included in JS_ENUMERATE_NATIVE_OBJECTS due to missing distinct prototype
- m_proxy_constructor = heap().allocate<ProxyConstructor>(realm, realm);
+ m_proxy_constructor = heap().allocate<ProxyConstructor>(realm, realm).release_allocated_value_but_fixme_should_propagate_errors();
// Global object functions
m_eval_function = NativeFunction::create(realm, GlobalObject::eval, 1, vm.names.eval, &realm);
@@ -223,7 +223,7 @@ void Intrinsics::initialize_intrinsics(Realm& realm)
m_escape_function = NativeFunction::create(realm, GlobalObject::escape, 1, vm.names.escape, &realm);
m_unescape_function = NativeFunction::create(realm, GlobalObject::unescape, 1, vm.names.unescape, &realm);
- m_object_constructor = heap().allocate<ObjectConstructor>(realm, realm);
+ m_object_constructor = heap().allocate<ObjectConstructor>(realm, realm).release_allocated_value_but_fixme_should_propagate_errors();
// 10.2.4.1 %ThrowTypeError% ( ), https://tc39.es/ecma262/#sec-%throwtypeerror%
m_throw_type_error_function = NativeFunction::create(
@@ -266,52 +266,52 @@ constexpr inline bool IsTypedArrayConstructor = false;
JS_ENUMERATE_TYPED_ARRAYS
#undef __JS_ENUMERATE
-#define __JS_ENUMERATE_INNER(ClassName, snake_name, PrototypeName, ConstructorName, Namespace, snake_namespace) \
- void Intrinsics::initialize_##snake_namespace##snake_name() \
- { \
- auto& vm = this->vm(); \
- \
- VERIFY(!m_##snake_namespace##snake_name##_prototype); \
- VERIFY(!m_##snake_namespace##snake_name##_constructor); \
- if constexpr (IsTypedArrayConstructor<Namespace::ConstructorName>) { \
- m_##snake_namespace##snake_name##_prototype = heap().allocate<Namespace::PrototypeName>(m_realm, *typed_array_prototype()); \
- m_##snake_namespace##snake_name##_constructor = heap().allocate<Namespace::ConstructorName>(m_realm, m_realm, *typed_array_constructor()); \
- } else { \
- m_##snake_namespace##snake_name##_prototype = heap().allocate<Namespace::PrototypeName>(m_realm, m_realm); \
- m_##snake_namespace##snake_name##_constructor = heap().allocate<Namespace::ConstructorName>(m_realm, m_realm); \
- } \
- \
- /* FIXME: Add these special cases to JS_ENUMERATE_NATIVE_OBJECTS */ \
- if constexpr (IsSame<Namespace::ConstructorName, BigIntConstructor>) \
- initialize_constructor(vm, vm.names.BigInt, *m_##snake_namespace##snake_name##_constructor, m_##snake_namespace##snake_name##_prototype); \
- else if constexpr (IsSame<Namespace::ConstructorName, BooleanConstructor>) \
- initialize_constructor(vm, vm.names.Boolean, *m_##snake_namespace##snake_name##_constructor, m_##snake_namespace##snake_name##_prototype); \
- else if constexpr (IsSame<Namespace::ConstructorName, FunctionConstructor>) \
- initialize_constructor(vm, vm.names.Function, *m_##snake_namespace##snake_name##_constructor, m_##snake_namespace##snake_name##_prototype); \
- else if constexpr (IsSame<Namespace::ConstructorName, NumberConstructor>) \
- initialize_constructor(vm, vm.names.Number, *m_##snake_namespace##snake_name##_constructor, m_##snake_namespace##snake_name##_prototype); \
- else if constexpr (IsSame<Namespace::ConstructorName, RegExpConstructor>) \
- initialize_constructor(vm, vm.names.RegExp, *m_##snake_namespace##snake_name##_constructor, m_##snake_namespace##snake_name##_prototype); \
- else if constexpr (IsSame<Namespace::ConstructorName, StringConstructor>) \
- initialize_constructor(vm, vm.names.String, *m_##snake_namespace##snake_name##_constructor, m_##snake_namespace##snake_name##_prototype); \
- else if constexpr (IsSame<Namespace::ConstructorName, SymbolConstructor>) \
- initialize_constructor(vm, vm.names.Symbol, *m_##snake_namespace##snake_name##_constructor, m_##snake_namespace##snake_name##_prototype); \
- else \
- initialize_constructor(vm, vm.names.ClassName, *m_##snake_namespace##snake_name##_constructor, m_##snake_namespace##snake_name##_prototype); \
- } \
- \
- Namespace::ConstructorName* Intrinsics::snake_namespace##snake_name##_constructor() \
- { \
- if (!m_##snake_namespace##snake_name##_constructor) \
- initialize_##snake_namespace##snake_name(); \
- return m_##snake_namespace##snake_name##_constructor; \
- } \
- \
- Object* Intrinsics::snake_namespace##snake_name##_prototype() \
- { \
- if (!m_##snake_namespace##snake_name##_prototype) \
- initialize_##snake_namespace##snake_name(); \
- return m_##snake_namespace##snake_name##_prototype; \
+#define __JS_ENUMERATE_INNER(ClassName, snake_name, PrototypeName, ConstructorName, Namespace, snake_namespace) \
+ void Intrinsics::initialize_##snake_namespace##snake_name() \
+ { \
+ auto& vm = this->vm(); \
+ \
+ VERIFY(!m_##snake_namespace##snake_name##_prototype); \
+ VERIFY(!m_##snake_namespace##snake_name##_constructor); \
+ if constexpr (IsTypedArrayConstructor<Namespace::ConstructorName>) { \
+ m_##snake_namespace##snake_name##_prototype = heap().allocate<Namespace::PrototypeName>(m_realm, *typed_array_prototype()).release_allocated_value_but_fixme_should_propagate_errors(); \
+ m_##snake_namespace##snake_name##_constructor = heap().allocate<Namespace::ConstructorName>(m_realm, m_realm, *typed_array_constructor()).release_allocated_value_but_fixme_should_propagate_errors(); \
+ } else { \
+ m_##snake_namespace##snake_name##_prototype = heap().allocate<Namespace::PrototypeName>(m_realm, m_realm).release_allocated_value_but_fixme_should_propagate_errors(); \
+ m_##snake_namespace##snake_name##_constructor = heap().allocate<Namespace::ConstructorName>(m_realm, m_realm).release_allocated_value_but_fixme_should_propagate_errors(); \
+ } \
+ \
+ /* FIXME: Add these special cases to JS_ENUMERATE_NATIVE_OBJECTS */ \
+ if constexpr (IsSame<Namespace::ConstructorName, BigIntConstructor>) \
+ initialize_constructor(vm, vm.names.BigInt, *m_##snake_namespace##snake_name##_constructor, m_##snake_namespace##snake_name##_prototype); \
+ else if constexpr (IsSame<Namespace::ConstructorName, BooleanConstructor>) \
+ initialize_constructor(vm, vm.names.Boolean, *m_##snake_namespace##snake_name##_constructor, m_##snake_namespace##snake_name##_prototype); \
+ else if constexpr (IsSame<Namespace::ConstructorName, FunctionConstructor>) \
+ initialize_constructor(vm, vm.names.Function, *m_##snake_namespace##snake_name##_constructor, m_##snake_namespace##snake_name##_prototype); \
+ else if constexpr (IsSame<Namespace::ConstructorName, NumberConstructor>) \
+ initialize_constructor(vm, vm.names.Number, *m_##snake_namespace##snake_name##_constructor, m_##snake_namespace##snake_name##_prototype); \
+ else if constexpr (IsSame<Namespace::ConstructorName, RegExpConstructor>) \
+ initialize_constructor(vm, vm.names.RegExp, *m_##snake_namespace##snake_name##_constructor, m_##snake_namespace##snake_name##_prototype); \
+ else if constexpr (IsSame<Namespace::ConstructorName, StringConstructor>) \
+ initialize_constructor(vm, vm.names.String, *m_##snake_namespace##snake_name##_constructor, m_##snake_namespace##snake_name##_prototype); \
+ else if constexpr (IsSame<Namespace::ConstructorName, SymbolConstructor>) \
+ initialize_constructor(vm, vm.names.Symbol, *m_##snake_namespace##snake_name##_constructor, m_##snake_namespace##snake_name##_prototype); \
+ else \
+ initialize_constructor(vm, vm.names.ClassName, *m_##snake_namespace##snake_name##_constructor, m_##snake_namespace##snake_name##_prototype); \
+ } \
+ \
+ Namespace::ConstructorName* Intrinsics::snake_namespace##snake_name##_constructor() \
+ { \
+ if (!m_##snake_namespace##snake_name##_constructor) \
+ initialize_##snake_namespace##snake_name(); \
+ return m_##snake_namespace##snake_name##_constructor; \
+ } \
+ \
+ Object* Intrinsics::snake_namespace##snake_name##_prototype() \
+ { \
+ if (!m_##snake_namespace##snake_name##_prototype) \
+ initialize_##snake_namespace##snake_name(); \
+ return m_##snake_namespace##snake_name##_prototype; \
}
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
@@ -331,12 +331,12 @@ JS_ENUMERATE_TEMPORAL_OBJECTS
#undef __JS_ENUMERATE_INNER
-#define __JS_ENUMERATE(ClassName, snake_name) \
- ClassName* Intrinsics::snake_name##_object() \
- { \
- if (!m_##snake_name##_object) \
- m_##snake_name##_object = heap().allocate<ClassName>(m_realm, m_realm); \
- return m_##snake_name##_object; \
+#define __JS_ENUMERATE(ClassName, snake_name) \
+ ClassName* Intrinsics::snake_name##_object() \
+ { \
+ if (!m_##snake_name##_object) \
+ m_##snake_name##_object = heap().allocate<ClassName>(m_realm, m_realm).release_allocated_value_but_fixme_should_propagate_errors(); \
+ return m_##snake_name##_object; \
}
JS_ENUMERATE_BUILTIN_NAMESPACE_OBJECTS
#undef __JS_ENUMERATE
diff --git a/Userland/Libraries/LibJS/Runtime/Map.cpp b/Userland/Libraries/LibJS/Runtime/Map.cpp
index bc29064bf6..e685db97fa 100644
--- a/Userland/Libraries/LibJS/Runtime/Map.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Map.cpp
@@ -10,7 +10,7 @@ namespace JS {
NonnullGCPtr<Map> Map::create(Realm& realm)
{
- return realm.heap().allocate<Map>(realm, *realm.intrinsics().map_prototype());
+ return realm.heap().allocate<Map>(realm, *realm.intrinsics().map_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
}
Map::Map(Object& prototype)
diff --git a/Userland/Libraries/LibJS/Runtime/MapIterator.cpp b/Userland/Libraries/LibJS/Runtime/MapIterator.cpp
index ef66637bd5..2410bb6f7c 100644
--- a/Userland/Libraries/LibJS/Runtime/MapIterator.cpp
+++ b/Userland/Libraries/LibJS/Runtime/MapIterator.cpp
@@ -11,7 +11,7 @@ namespace JS {
NonnullGCPtr<MapIterator> MapIterator::create(Realm& realm, Map& map, Object::PropertyKind iteration_kind)
{
- return realm.heap().allocate<MapIterator>(realm, map, iteration_kind, *realm.intrinsics().map_iterator_prototype());
+ return realm.heap().allocate<MapIterator>(realm, map, iteration_kind, *realm.intrinsics().map_iterator_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
}
MapIterator::MapIterator(Map& map, Object::PropertyKind iteration_kind, Object& prototype)
diff --git a/Userland/Libraries/LibJS/Runtime/NativeFunction.cpp b/Userland/Libraries/LibJS/Runtime/NativeFunction.cpp
index bb8427e2fc..87f78c6f38 100644
--- a/Userland/Libraries/LibJS/Runtime/NativeFunction.cpp
+++ b/Userland/Libraries/LibJS/Runtime/NativeFunction.cpp
@@ -36,7 +36,7 @@ NonnullGCPtr<NativeFunction> NativeFunction::create(Realm& allocating_realm, Saf
// 7. Set func.[[Extensible]] to true.
// 8. Set func.[[Realm]] to realm.
// 9. Set func.[[InitialName]] to null.
- auto function = allocating_realm.heap().allocate<NativeFunction>(allocating_realm, move(behaviour), prototype.value(), *realm.value());
+ auto function = allocating_realm.heap().allocate<NativeFunction>(allocating_realm, move(behaviour), prototype.value(), *realm.value()).release_allocated_value_but_fixme_should_propagate_errors();
// 10. Perform SetFunctionLength(func, length).
function->set_function_length(length);
@@ -53,7 +53,7 @@ NonnullGCPtr<NativeFunction> NativeFunction::create(Realm& allocating_realm, Saf
NonnullGCPtr<NativeFunction> NativeFunction::create(Realm& realm, DeprecatedFlyString const& name, SafeFunction<ThrowCompletionOr<Value>(VM&)> function)
{
- return realm.heap().allocate<NativeFunction>(realm, name, move(function), *realm.intrinsics().function_prototype());
+ return realm.heap().allocate<NativeFunction>(realm, name, move(function), *realm.intrinsics().function_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
}
NativeFunction::NativeFunction(SafeFunction<ThrowCompletionOr<Value>(VM&)> native_function, Object* prototype, Realm& realm)
diff --git a/Userland/Libraries/LibJS/Runtime/NumberObject.cpp b/Userland/Libraries/LibJS/Runtime/NumberObject.cpp
index 72cfc01548..9a17e3c386 100644
--- a/Userland/Libraries/LibJS/Runtime/NumberObject.cpp
+++ b/Userland/Libraries/LibJS/Runtime/NumberObject.cpp
@@ -11,7 +11,7 @@ namespace JS {
NonnullGCPtr<NumberObject> NumberObject::create(Realm& realm, double value)
{
- return realm.heap().allocate<NumberObject>(realm, value, *realm.intrinsics().number_prototype());
+ return realm.heap().allocate<NumberObject>(realm, value, *realm.intrinsics().number_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
}
NumberObject::NumberObject(double value, Object& prototype)
diff --git a/Userland/Libraries/LibJS/Runtime/Object.cpp b/Userland/Libraries/LibJS/Runtime/Object.cpp
index 28a463e702..839e331316 100644
--- a/Userland/Libraries/LibJS/Runtime/Object.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Object.cpp
@@ -30,11 +30,10 @@ static HashMap<Object const*, HashMap<DeprecatedFlyString, Object::IntrinsicAcce
NonnullGCPtr<Object> Object::create(Realm& realm, Object* prototype)
{
if (!prototype)
- return realm.heap().allocate<Object>(realm, *realm.intrinsics().empty_object_shape());
- else if (prototype == realm.intrinsics().object_prototype())
- return realm.heap().allocate<Object>(realm, *realm.intrinsics().new_object_shape());
- else
- return realm.heap().allocate<Object>(realm, ConstructWithPrototypeTag::Tag, *prototype);
+ return realm.heap().allocate<Object>(realm, *realm.intrinsics().empty_object_shape()).release_allocated_value_but_fixme_should_propagate_errors();
+ if (prototype == realm.intrinsics().object_prototype())
+ return realm.heap().allocate<Object>(realm, *realm.intrinsics().new_object_shape()).release_allocated_value_but_fixme_should_propagate_errors();
+ return realm.heap().allocate<Object>(realm, ConstructWithPrototypeTag::Tag, *prototype).release_allocated_value_but_fixme_should_propagate_errors();
}
Object::Object(GlobalObjectTag, Realm& realm)
diff --git a/Userland/Libraries/LibJS/Runtime/Promise.cpp b/Userland/Libraries/LibJS/Runtime/Promise.cpp
index 316ad4f987..108c6e457c 100644
--- a/Userland/Libraries/LibJS/Runtime/Promise.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Promise.cpp
@@ -44,7 +44,7 @@ ThrowCompletionOr<Object*> promise_resolve(VM& vm, Object& constructor, Value va
NonnullGCPtr<Promise> Promise::create(Realm& realm)
{
- return realm.heap().allocate<Promise>(realm, *realm.intrinsics().promise_prototype());
+ return realm.heap().allocate<Promise>(realm, *realm.intrinsics().promise_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
}
// 27.2 Promise Objects, https://tc39.es/ecma262/#sec-promise-objects
diff --git a/Userland/Libraries/LibJS/Runtime/PromiseResolvingElementFunctions.cpp b/Userland/Libraries/LibJS/Runtime/PromiseResolvingElementFunctions.cpp
index 0ba3dd2cdd..908b3aa405 100644
--- a/Userland/Libraries/LibJS/Runtime/PromiseResolvingElementFunctions.cpp
+++ b/Userland/Libraries/LibJS/Runtime/PromiseResolvingElementFunctions.cpp
@@ -57,7 +57,7 @@ void PromiseResolvingElementFunction::visit_edges(Cell::Visitor& visitor)
NonnullGCPtr<PromiseAllResolveElementFunction> PromiseAllResolveElementFunction::create(Realm& realm, size_t index, PromiseValueList& values, NonnullGCPtr<PromiseCapability> capability, RemainingElements& remaining_elements)
{
- return realm.heap().allocate<PromiseAllResolveElementFunction>(realm, index, values, capability, remaining_elements, *realm.intrinsics().function_prototype());
+ return realm.heap().allocate<PromiseAllResolveElementFunction>(realm, index, values, capability, remaining_elements, *realm.intrinsics().function_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
}
PromiseAllResolveElementFunction::PromiseAllResolveElementFunction(size_t index, PromiseValueList& values, NonnullGCPtr<PromiseCapability> capability, RemainingElements& remaining_elements, Object& prototype)
@@ -89,7 +89,7 @@ ThrowCompletionOr<Value> PromiseAllResolveElementFunction::resolve_element()
NonnullGCPtr<PromiseAllSettledResolveElementFunction> PromiseAllSettledResolveElementFunction::create(Realm& realm, size_t index, PromiseValueList& values, NonnullGCPtr<PromiseCapability> capability, RemainingElements& remaining_elements)
{
- return realm.heap().allocate<PromiseAllSettledResolveElementFunction>(realm, index, values, capability, remaining_elements, *realm.intrinsics().function_prototype());
+ return realm.heap().allocate<PromiseAllSettledResolveElementFunction>(realm, index, values, capability, remaining_elements, *realm.intrinsics().function_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
}
PromiseAllSettledResolveElementFunction::PromiseAllSettledResolveElementFunction(size_t index, PromiseValueList& values, NonnullGCPtr<PromiseCapability> capability, RemainingElements& remaining_elements, Object& prototype)
@@ -130,7 +130,7 @@ ThrowCompletionOr<Value> PromiseAllSettledResolveElementFunction::resolve_elemen
NonnullGCPtr<PromiseAllSettledRejectElementFunction> PromiseAllSettledRejectElementFunction::create(Realm& realm, size_t index, PromiseValueList& values, NonnullGCPtr<PromiseCapability> capability, RemainingElements& remaining_elements)
{
- return realm.heap().allocate<PromiseAllSettledRejectElementFunction>(realm, index, values, capability, remaining_elements, *realm.intrinsics().function_prototype());
+ return realm.heap().allocate<PromiseAllSettledRejectElementFunction>(realm, index, values, capability, remaining_elements, *realm.intrinsics().function_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
}
PromiseAllSettledRejectElementFunction::PromiseAllSettledRejectElementFunction(size_t index, PromiseValueList& values, NonnullGCPtr<PromiseCapability> capability, RemainingElements& remaining_elements, Object& prototype)
@@ -171,7 +171,7 @@ ThrowCompletionOr<Value> PromiseAllSettledRejectElementFunction::resolve_element
NonnullGCPtr<PromiseAnyRejectElementFunction> PromiseAnyRejectElementFunction::create(Realm& realm, size_t index, PromiseValueList& errors, NonnullGCPtr<PromiseCapability> capability, RemainingElements& remaining_elements)
{
- return realm.heap().allocate<PromiseAnyRejectElementFunction>(realm, index, errors, capability, remaining_elements, *realm.intrinsics().function_prototype());
+ return realm.heap().allocate<PromiseAnyRejectElementFunction>(realm, index, errors, capability, remaining_elements, *realm.intrinsics().function_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
}
PromiseAnyRejectElementFunction::PromiseAnyRejectElementFunction(size_t index, PromiseValueList& errors, NonnullGCPtr<PromiseCapability> capability, RemainingElements& remaining_elements, Object& prototype)
diff --git a/Userland/Libraries/LibJS/Runtime/PromiseResolvingFunction.cpp b/Userland/Libraries/LibJS/Runtime/PromiseResolvingFunction.cpp
index e1d7c2ce2f..f519ac73cf 100644
--- a/Userland/Libraries/LibJS/Runtime/PromiseResolvingFunction.cpp
+++ b/Userland/Libraries/LibJS/Runtime/PromiseResolvingFunction.cpp
@@ -13,7 +13,7 @@ namespace JS {
NonnullGCPtr<PromiseResolvingFunction> PromiseResolvingFunction::create(Realm& realm, Promise& promise, AlreadyResolved& already_resolved, FunctionType function)
{
- return realm.heap().allocate<PromiseResolvingFunction>(realm, promise, already_resolved, move(function), *realm.intrinsics().function_prototype());
+ return realm.heap().allocate<PromiseResolvingFunction>(realm, promise, already_resolved, move(function), *realm.intrinsics().function_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
}
PromiseResolvingFunction::PromiseResolvingFunction(Promise& promise, AlreadyResolved& already_resolved, FunctionType native_function, Object& prototype)
diff --git a/Userland/Libraries/LibJS/Runtime/ProxyObject.cpp b/Userland/Libraries/LibJS/Runtime/ProxyObject.cpp
index a71a76d8a3..186daca8cd 100644
--- a/Userland/Libraries/LibJS/Runtime/ProxyObject.cpp
+++ b/Userland/Libraries/LibJS/Runtime/ProxyObject.cpp
@@ -17,7 +17,7 @@ namespace JS {
NonnullGCPtr<ProxyObject> ProxyObject::create(Realm& realm, Object& target, Object& handler)
{
- return realm.heap().allocate<ProxyObject>(realm, target, handler, *realm.intrinsics().object_prototype());
+ return realm.heap().allocate<ProxyObject>(realm, target, handler, *realm.intrinsics().object_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
}
ProxyObject::ProxyObject(Object& target, Object& handler, Object& prototype)
diff --git a/Userland/Libraries/LibJS/Runtime/RegExpObject.cpp b/Userland/Libraries/LibJS/Runtime/RegExpObject.cpp
index cbbca774ba..74b52e3000 100644
--- a/Userland/Libraries/LibJS/Runtime/RegExpObject.cpp
+++ b/Userland/Libraries/LibJS/Runtime/RegExpObject.cpp
@@ -130,12 +130,12 @@ ThrowCompletionOr<DeprecatedString> parse_regex_pattern(VM& vm, StringView patte
NonnullGCPtr<RegExpObject> RegExpObject::create(Realm& realm)
{
- return realm.heap().allocate<RegExpObject>(realm, *realm.intrinsics().regexp_prototype());
+ return realm.heap().allocate<RegExpObject>(realm, *realm.intrinsics().regexp_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
}
NonnullGCPtr<RegExpObject> RegExpObject::create(Realm& realm, Regex<ECMA262> regex, DeprecatedString pattern, DeprecatedString flags)
{
- return realm.heap().allocate<RegExpObject>(realm, move(regex), move(pattern), move(flags), *realm.intrinsics().regexp_prototype());
+ return realm.heap().allocate<RegExpObject>(realm, move(regex), move(pattern), move(flags), *realm.intrinsics().regexp_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
}
RegExpObject::RegExpObject(Object& prototype)
diff --git a/Userland/Libraries/LibJS/Runtime/RegExpStringIterator.cpp b/Userland/Libraries/LibJS/Runtime/RegExpStringIterator.cpp
index 0419110055..49a360dd70 100644
--- a/Userland/Libraries/LibJS/Runtime/RegExpStringIterator.cpp
+++ b/Userland/Libraries/LibJS/Runtime/RegExpStringIterator.cpp
@@ -12,7 +12,7 @@ namespace JS {
// 22.2.7.1 CreateRegExpStringIterator ( R, S, global, fullUnicode ), https://tc39.es/ecma262/#sec-createregexpstringiterator
NonnullGCPtr<RegExpStringIterator> RegExpStringIterator::create(Realm& realm, Object& regexp_object, Utf16String string, bool global, bool unicode)
{
- return realm.heap().allocate<RegExpStringIterator>(realm, *realm.intrinsics().regexp_string_iterator_prototype(), regexp_object, move(string), global, unicode);
+ return realm.heap().allocate<RegExpStringIterator>(realm, *realm.intrinsics().regexp_string_iterator_prototype(), regexp_object, move(string), global, unicode).release_allocated_value_but_fixme_should_propagate_errors();
}
RegExpStringIterator::RegExpStringIterator(Object& prototype, Object& regexp_object, Utf16String string, bool global, bool unicode)
diff --git a/Userland/Libraries/LibJS/Runtime/Set.cpp b/Userland/Libraries/LibJS/Runtime/Set.cpp
index f971acc571..40c951415e 100644
--- a/Userland/Libraries/LibJS/Runtime/Set.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Set.cpp
@@ -10,7 +10,7 @@ namespace JS {
NonnullGCPtr<Set> Set::create(Realm& realm)
{
- return realm.heap().allocate<Set>(realm, *realm.intrinsics().set_prototype());
+ return realm.heap().allocate<Set>(realm, *realm.intrinsics().set_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
}
Set::Set(Object& prototype)
diff --git a/Userland/Libraries/LibJS/Runtime/SetIterator.cpp b/Userland/Libraries/LibJS/Runtime/SetIterator.cpp
index f75f17e626..5fd1a8dfc9 100644
--- a/Userland/Libraries/LibJS/Runtime/SetIterator.cpp
+++ b/Userland/Libraries/LibJS/Runtime/SetIterator.cpp
@@ -11,7 +11,7 @@ namespace JS {
NonnullGCPtr<SetIterator> SetIterator::create(Realm& realm, Set& set, Object::PropertyKind iteration_kind)
{
- return realm.heap().allocate<SetIterator>(realm, set, iteration_kind, *realm.intrinsics().set_iterator_prototype());
+ return realm.heap().allocate<SetIterator>(realm, set, iteration_kind, *realm.intrinsics().set_iterator_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
}
SetIterator::SetIterator(Set& set, Object::PropertyKind iteration_kind, Object& prototype)
diff --git a/Userland/Libraries/LibJS/Runtime/StringIterator.cpp b/Userland/Libraries/LibJS/Runtime/StringIterator.cpp
index 03dd0e3dbf..532c57bb85 100644
--- a/Userland/Libraries/LibJS/Runtime/StringIterator.cpp
+++ b/Userland/Libraries/LibJS/Runtime/StringIterator.cpp
@@ -12,7 +12,7 @@ namespace JS {
NonnullGCPtr<StringIterator> StringIterator::create(Realm& realm, String string)
{
- return realm.heap().allocate<StringIterator>(realm, move(string), *realm.intrinsics().string_iterator_prototype());
+ return realm.heap().allocate<StringIterator>(realm, move(string), *realm.intrinsics().string_iterator_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
}
StringIterator::StringIterator(String string, Object& prototype)
diff --git a/Userland/Libraries/LibJS/Runtime/StringObject.cpp b/Userland/Libraries/LibJS/Runtime/StringObject.cpp
index 7778cd909a..9205d6b679 100644
--- a/Userland/Libraries/LibJS/Runtime/StringObject.cpp
+++ b/Userland/Libraries/LibJS/Runtime/StringObject.cpp
@@ -17,7 +17,7 @@ namespace JS {
// 10.4.3.4 StringCreate ( value, prototype ), https://tc39.es/ecma262/#sec-stringcreate
NonnullGCPtr<StringObject> StringObject::create(Realm& realm, PrimitiveString& primitive_string, Object& prototype)
{
- return realm.heap().allocate<StringObject>(realm, primitive_string, prototype);
+ return realm.heap().allocate<StringObject>(realm, primitive_string, prototype).release_allocated_value_but_fixme_should_propagate_errors();
}
StringObject::StringObject(PrimitiveString& string, Object& prototype)
diff --git a/Userland/Libraries/LibJS/Runtime/SuppressedError.cpp b/Userland/Libraries/LibJS/Runtime/SuppressedError.cpp
index b067f5b985..a7edd888a9 100644
--- a/Userland/Libraries/LibJS/Runtime/SuppressedError.cpp
+++ b/Userland/Libraries/LibJS/Runtime/SuppressedError.cpp
@@ -12,7 +12,7 @@ namespace JS {
NonnullGCPtr<SuppressedError> SuppressedError::create(Realm& realm)
{
- return *realm.heap().allocate<SuppressedError>(realm, *realm.intrinsics().suppressed_error_prototype());
+ return *realm.heap().allocate<SuppressedError>(realm, *realm.intrinsics().suppressed_error_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
}
SuppressedError::SuppressedError(Object& prototype)
diff --git a/Userland/Libraries/LibJS/Runtime/SymbolObject.cpp b/Userland/Libraries/LibJS/Runtime/SymbolObject.cpp
index b59a83401b..2e006d74a9 100644
--- a/Userland/Libraries/LibJS/Runtime/SymbolObject.cpp
+++ b/Userland/Libraries/LibJS/Runtime/SymbolObject.cpp
@@ -12,7 +12,7 @@ namespace JS {
NonnullGCPtr<SymbolObject> SymbolObject::create(Realm& realm, Symbol& primitive_symbol)
{
- return realm.heap().allocate<SymbolObject>(realm, primitive_symbol, *realm.intrinsics().symbol_prototype());
+ return realm.heap().allocate<SymbolObject>(realm, primitive_symbol, *realm.intrinsics().symbol_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
}
SymbolObject::SymbolObject(Symbol& symbol, Object& prototype)
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Temporal.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/Temporal.cpp
index 82fe3dc23a..48cb124bf3 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/Temporal.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/Temporal.cpp
@@ -36,7 +36,7 @@ ThrowCompletionOr<void> Temporal::initialize(Realm& realm)
define_direct_property(*vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, "Temporal"), Attribute::Configurable);
u8 attr = Attribute::Writable | Attribute::Configurable;
- define_direct_property(vm.names.Now, heap().allocate<Now>(realm, realm), attr);
+ define_direct_property(vm.names.Now, MUST_OR_THROW_OOM(heap().allocate<Now>(realm, realm)), attr);
define_intrinsic_accessor(vm.names.Calendar, attr, [](auto& realm) -> Value { return realm.intrinsics().temporal_calendar_constructor(); });
define_intrinsic_accessor(vm.names.Duration, attr, [](auto& realm) -> Value { return realm.intrinsics().temporal_duration_constructor(); });
define_intrinsic_accessor(vm.names.Instant, attr, [](auto& realm) -> Value { return realm.intrinsics().temporal_instant_constructor(); });
diff --git a/Userland/Libraries/LibJS/Runtime/TypedArray.cpp b/Userland/Libraries/LibJS/Runtime/TypedArray.cpp
index 148a61bab3..ccd176bb02 100644
--- a/Userland/Libraries/LibJS/Runtime/TypedArray.cpp
+++ b/Userland/Libraries/LibJS/Runtime/TypedArray.cpp
@@ -420,141 +420,141 @@ void TypedArrayBase::visit_edges(Visitor& visitor)
visitor.visit(m_viewed_array_buffer);
}
-#define JS_DEFINE_TYPED_ARRAY(ClassName, snake_name, PrototypeName, ConstructorName, Type) \
- ThrowCompletionOr<NonnullGCPtr<ClassName>> ClassName::create(Realm& realm, u32 length, FunctionObject& new_target) \
- { \
- auto* prototype = TRY(get_prototype_from_constructor(realm.vm(), new_target, &Intrinsics::snake_name##_prototype)); \
- auto array_buffer = TRY(ArrayBuffer::create(realm, length * sizeof(UnderlyingBufferDataType))); \
- return realm.heap().allocate<ClassName>(realm, *prototype, length, *array_buffer); \
- } \
- \
- ThrowCompletionOr<NonnullGCPtr<ClassName>> ClassName::create(Realm& realm, u32 length) \
- { \
- auto array_buffer = TRY(ArrayBuffer::create(realm, length * sizeof(UnderlyingBufferDataType))); \
- return create(realm, length, *array_buffer); \
- } \
- \
- NonnullGCPtr<ClassName> ClassName::create(Realm& realm, u32 length, ArrayBuffer& array_buffer) \
- { \
- return realm.heap().allocate<ClassName>(realm, *realm.intrinsics().snake_name##_prototype(), length, array_buffer); \
- } \
- \
- ClassName::ClassName(Object& prototype, u32 length, ArrayBuffer& array_buffer) \
- : TypedArray(prototype, \
- reinterpret_cast<TypedArrayBase::IntrinsicConstructor>(&Intrinsics::snake_name##_constructor), length, array_buffer) \
- { \
- if constexpr (#ClassName##sv.is_one_of("BigInt64Array", "BigUint64Array")) \
- m_content_type = ContentType::BigInt; \
- else \
- m_content_type = ContentType::Number; \
- } \
- \
- ClassName::~ClassName() \
- { \
- } \
- \
- DeprecatedFlyString const& ClassName::element_name() const \
- { \
- return vm().names.ClassName.as_string(); \
- } \
- \
- PrototypeName::PrototypeName(Object& prototype) \
- : Object(ConstructWithPrototypeTag::Tag, prototype) \
- { \
- } \
- \
- PrototypeName::~PrototypeName() \
- { \
- } \
- \
- ThrowCompletionOr<void> PrototypeName::initialize(Realm& realm) \
- { \
- auto& vm = this->vm(); \
- MUST_OR_THROW_OOM(Base::initialize(realm)); \
- define_direct_property(vm.names.BYTES_PER_ELEMENT, Value((i32)sizeof(Type)), 0); \
- \
- return {}; \
- } \
- \
- ConstructorName::ConstructorName(Realm& realm, Object& prototype) \
- : TypedArrayConstructor(realm.vm().names.ClassName.as_string(), prototype) \
- { \
- } \
- \
- ConstructorName::~ConstructorName() \
- { \
- } \
- \
- ThrowCompletionOr<void> ConstructorName::initialize(Realm& realm) \
- { \
- auto& vm = this->vm(); \
- MUST_OR_THROW_OOM(NativeFunction::initialize(realm)); \
- \
- /* 23.2.6.2 TypedArray.prototype, https://tc39.es/ecma262/#sec-typedarray.prototype */ \
- define_direct_property(vm.names.prototype, realm.intrinsics().snake_name##_prototype(), 0); \
- \
- /* 23.2.6.1 TypedArray.BYTES_PER_ELEMENT, https://tc39.es/ecma262/#sec-typedarray.bytes_per_element */ \
- define_direct_property(vm.names.BYTES_PER_ELEMENT, Value((i32)sizeof(Type)), 0); \
- \
- define_direct_property(vm.names.length, Value(3), Attribute::Configurable); \
- \
- return {}; \
- } \
- \
- /* 23.2.5.1 TypedArray ( ...args ), https://tc39.es/ecma262/#sec-typedarray */ \
- ThrowCompletionOr<Value> ConstructorName::call() \
- { \
- auto& vm = this->vm(); \
- return vm.throw_completion<TypeError>(ErrorType::ConstructorWithoutNew, vm.names.ClassName); \
- } \
- \
- /* 23.2.5.1 TypedArray ( ...args ), https://tc39.es/ecma262/#sec-typedarray */ \
- ThrowCompletionOr<NonnullGCPtr<Object>> ConstructorName::construct(FunctionObject& new_target) \
- { \
- auto& vm = this->vm(); \
- auto& realm = *vm.current_realm(); \
- \
- if (vm.argument_count() == 0) \
- return TRY(ClassName::create(realm, 0, new_target)); \
- \
- auto first_argument = vm.argument(0); \
- if (first_argument.is_object()) { \
- auto typed_array = TRY(ClassName::create(realm, 0, new_target)); \
- if (first_argument.as_object().is_typed_array()) { \
- auto& arg_typed_array = static_cast<TypedArrayBase&>(first_argument.as_object()); \
- TRY(initialize_typed_array_from_typed_array(vm, *typed_array, arg_typed_array)); \
- } else if (is<ArrayBuffer>(first_argument.as_object())) { \
- auto& array_buffer = static_cast<ArrayBuffer&>(first_argument.as_object()); \
- TRY(initialize_typed_array_from_array_buffer(vm, *typed_array, array_buffer, \
- vm.argument(1), vm.argument(2))); \
- } else { \
- auto iterator = TRY(first_argument.get_method(vm, *vm.well_known_symbol_iterator())); \
- if (iterator) { \
- auto values = TRY(iterable_to_list(vm, first_argument, iterator)); \
- TRY(initialize_typed_array_from_list(vm, *typed_array, values)); \
- } else { \
- TRY(initialize_typed_array_from_array_like(vm, *typed_array, first_argument.as_object())); \
- } \
- } \
- return typed_array; \
- } \
- \
- auto array_length_or_error = first_argument.to_index(vm); \
- if (array_length_or_error.is_error()) { \
- auto error = array_length_or_error.release_error(); \
- if (error.value()->is_object() && is<RangeError>(error.value()->as_object())) { \
- /* Re-throw more specific RangeError */ \
- return vm.throw_completion<RangeError>(ErrorType::InvalidLength, "typed array"); \
- } \
- return error; \
- } \
- auto array_length = array_length_or_error.release_value(); \
- if (array_length > NumericLimits<i32>::max() / sizeof(Type)) \
- return vm.throw_completion<RangeError>(ErrorType::InvalidLength, "typed array"); \
- /* FIXME: What is the best/correct behavior here? */ \
- if (Checked<u32>::multiplication_would_overflow(array_length, sizeof(Type))) \
- return vm.throw_completion<RangeError>(ErrorType::InvalidLength, "typed array"); \
- return TRY(ClassName::create(realm, array_length, new_target)); \
+#define JS_DEFINE_TYPED_ARRAY(ClassName, snake_name, PrototypeName, ConstructorName, Type) \
+ ThrowCompletionOr<NonnullGCPtr<ClassName>> ClassName::create(Realm& realm, u32 length, FunctionObject& new_target) \
+ { \
+ auto* prototype = TRY(get_prototype_from_constructor(realm.vm(), new_target, &Intrinsics::snake_name##_prototype)); \
+ auto array_buffer = TRY(ArrayBuffer::create(realm, length * sizeof(UnderlyingBufferDataType))); \
+ return MUST_OR_THROW_OOM(realm.heap().allocate<ClassName>(realm, *prototype, length, *array_buffer)); \
+ } \
+ \
+ ThrowCompletionOr<NonnullGCPtr<ClassName>> ClassName::create(Realm& realm, u32 length) \
+ { \
+ auto array_buffer = TRY(ArrayBuffer::create(realm, length * sizeof(UnderlyingBufferDataType))); \
+ return create(realm, length, *array_buffer); \
+ } \
+ \
+ NonnullGCPtr<ClassName> ClassName::create(Realm& realm, u32 length, ArrayBuffer& array_buffer) \
+ { \
+ return realm.heap().allocate<ClassName>(realm, *realm.intrinsics().snake_name##_prototype(), length, array_buffer).release_allocated_value_but_fixme_should_propagate_errors(); \
+ } \
+ \
+ ClassName::ClassName(Object& prototype, u32 length, ArrayBuffer& array_buffer) \
+ : TypedArray(prototype, \
+ reinterpret_cast<TypedArrayBase::IntrinsicConstructor>(&Intrinsics::snake_name##_constructor), length, array_buffer) \
+ { \
+ if constexpr (#ClassName##sv.is_one_of("BigInt64Array", "BigUint64Array")) \
+ m_content_type = ContentType::BigInt; \
+ else \
+ m_content_type = ContentType::Number; \
+ } \
+ \
+ ClassName::~ClassName() \
+ { \
+ } \
+ \
+ DeprecatedFlyString const& ClassName::element_name() const \
+ { \
+ return vm().names.ClassName.as_string(); \
+ } \
+ \
+ PrototypeName::PrototypeName(Object& prototype) \
+ : Object(ConstructWithPrototypeTag::Tag, prototype) \
+ { \
+ } \
+ \
+ PrototypeName::~PrototypeName() \
+ { \
+ } \
+ \
+ ThrowCompletionOr<void> PrototypeName::initialize(Realm& realm) \
+ { \
+ auto& vm = this->vm(); \
+ MUST_OR_THROW_OOM(Base::initialize(realm)); \
+ define_direct_property(vm.names.BYTES_PER_ELEMENT, Value((i32)sizeof(Type)), 0); \
+ \
+ return {}; \
+ } \
+ \
+ ConstructorName::ConstructorName(Realm& realm, Object& prototype) \
+ : TypedArrayConstructor(realm.vm().names.ClassName.as_string(), prototype) \
+ { \
+ } \
+ \
+ ConstructorName::~ConstructorName() \
+ { \
+ } \
+ \
+ ThrowCompletionOr<void> ConstructorName::initialize(Realm& realm) \
+ { \
+ auto& vm = this->vm(); \
+ MUST_OR_THROW_OOM(NativeFunction::initialize(realm)); \
+ \
+ /* 23.2.6.2 TypedArray.prototype, https://tc39.es/ecma262/#sec-typedarray.prototype */ \
+ define_direct_property(vm.names.prototype, realm.intrinsics().snake_name##_prototype(), 0); \
+ \
+ /* 23.2.6.1 TypedArray.BYTES_PER_ELEMENT, https://tc39.es/ecma262/#sec-typedarray.bytes_per_element */ \
+ define_direct_property(vm.names.BYTES_PER_ELEMENT, Value((i32)sizeof(Type)), 0); \
+ \
+ define_direct_property(vm.names.length, Value(3), Attribute::Configurable); \
+ \
+ return {}; \
+ } \
+ \
+ /* 23.2.5.1 TypedArray ( ...args ), https://tc39.es/ecma262/#sec-typedarray */ \
+ ThrowCompletionOr<Value> ConstructorName::call() \
+ { \
+ auto& vm = this->vm(); \
+ return vm.throw_completion<TypeError>(ErrorType::ConstructorWithoutNew, vm.names.ClassName); \
+ } \
+ \
+ /* 23.2.5.1 TypedArray ( ...args ), https://tc39.es/ecma262/#sec-typedarray */ \
+ ThrowCompletionOr<NonnullGCPtr<Object>> ConstructorName::construct(FunctionObject& new_target) \
+ { \
+ auto& vm = this->vm(); \
+ auto& realm = *vm.current_realm(); \
+ \
+ if (vm.argument_count() == 0) \
+ return TRY(ClassName::create(realm, 0, new_target)); \
+ \
+ auto first_argument = vm.argument(0); \
+ if (first_argument.is_object()) { \
+ auto typed_array = TRY(ClassName::create(realm, 0, new_target)); \
+ if (first_argument.as_object().is_typed_array()) { \
+ auto& arg_typed_array = static_cast<TypedArrayBase&>(first_argument.as_object()); \
+ TRY(initialize_typed_array_from_typed_array(vm, *typed_array, arg_typed_array)); \
+ } else if (is<ArrayBuffer>(first_argument.as_object())) { \
+ auto& array_buffer = static_cast<ArrayBuffer&>(first_argument.as_object()); \
+ TRY(initialize_typed_array_from_array_buffer(vm, *typed_array, array_buffer, \
+ vm.argument(1), vm.argument(2))); \
+ } else { \
+ auto iterator = TRY(first_argument.get_method(vm, *vm.well_known_symbol_iterator())); \
+ if (iterator) { \
+ auto values = TRY(iterable_to_list(vm, first_argument, iterator)); \
+ TRY(initialize_typed_array_from_list(vm, *typed_array, values)); \
+ } else { \
+ TRY(initialize_typed_array_from_array_like(vm, *typed_array, first_argument.as_object())); \
+ } \
+ } \
+ return typed_array; \
+ } \
+ \
+ auto array_length_or_error = first_argument.to_index(vm); \
+ if (array_length_or_error.is_error()) { \
+ auto error = array_length_or_error.release_error(); \
+ if (error.value()->is_object() && is<RangeError>(error.value()->as_object())) { \
+ /* Re-throw more specific RangeError */ \
+ return vm.throw_completion<RangeError>(ErrorType::InvalidLength, "typed array"); \
+ } \
+ return error; \
+ } \
+ auto array_length = array_length_or_error.release_value(); \
+ if (array_length > NumericLimits<i32>::max() / sizeof(Type)) \
+ return vm.throw_completion<RangeError>(ErrorType::InvalidLength, "typed array"); \
+ /* FIXME: What is the best/correct behavior here? */ \
+ if (Checked<u32>::multiplication_would_overflow(array_length, sizeof(Type))) \
+ return vm.throw_completion<RangeError>(ErrorType::InvalidLength, "typed array"); \
+ return TRY(ClassName::create(realm, array_length, new_target)); \
}
#undef __JS_ENUMERATE
diff --git a/Userland/Libraries/LibJS/Runtime/WeakMap.cpp b/Userland/Libraries/LibJS/Runtime/WeakMap.cpp
index 8bcb04ade3..b2d7173b19 100644
--- a/Userland/Libraries/LibJS/Runtime/WeakMap.cpp
+++ b/Userland/Libraries/LibJS/Runtime/WeakMap.cpp
@@ -10,7 +10,7 @@ namespace JS {
NonnullGCPtr<WeakMap> WeakMap::create(Realm& realm)
{
- return realm.heap().allocate<WeakMap>(realm, *realm.intrinsics().weak_map_prototype());
+ return realm.heap().allocate<WeakMap>(realm, *realm.intrinsics().weak_map_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
}
WeakMap::WeakMap(Object& prototype)
diff --git a/Userland/Libraries/LibJS/Runtime/WeakRef.cpp b/Userland/Libraries/LibJS/Runtime/WeakRef.cpp
index 9f80170eb5..eae13f6e63 100644
--- a/Userland/Libraries/LibJS/Runtime/WeakRef.cpp
+++ b/Userland/Libraries/LibJS/Runtime/WeakRef.cpp
@@ -10,12 +10,12 @@ namespace JS {
NonnullGCPtr<WeakRef> WeakRef::create(Realm& realm, Object& value)
{
- return realm.heap().allocate<WeakRef>(realm, value, *realm.intrinsics().weak_ref_prototype());
+ return realm.heap().allocate<WeakRef>(realm, value, *realm.intrinsics().weak_ref_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
}
NonnullGCPtr<WeakRef> WeakRef::create(Realm& realm, Symbol& value)
{
- return realm.heap().allocate<WeakRef>(realm, value, *realm.intrinsics().weak_ref_prototype());
+ return realm.heap().allocate<WeakRef>(realm, value, *realm.intrinsics().weak_ref_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
}
WeakRef::WeakRef(Object& value, Object& prototype)
diff --git a/Userland/Libraries/LibJS/Runtime/WeakSet.cpp b/Userland/Libraries/LibJS/Runtime/WeakSet.cpp
index ceaf10f6cf..a288695a3f 100644
--- a/Userland/Libraries/LibJS/Runtime/WeakSet.cpp
+++ b/Userland/Libraries/LibJS/Runtime/WeakSet.cpp
@@ -10,7 +10,7 @@ namespace JS {
NonnullGCPtr<WeakSet> WeakSet::create(Realm& realm)
{
- return realm.heap().allocate<WeakSet>(realm, *realm.intrinsics().weak_set_prototype());
+ return realm.heap().allocate<WeakSet>(realm, *realm.intrinsics().weak_set_prototype()).release_allocated_value_but_fixme_should_propagate_errors();
}
WeakSet::WeakSet(Object& prototype)
diff --git a/Userland/Libraries/LibJS/Runtime/WrappedFunction.cpp b/Userland/Libraries/LibJS/Runtime/WrappedFunction.cpp
index 8c220ba39d..45106de2e8 100644
--- a/Userland/Libraries/LibJS/Runtime/WrappedFunction.cpp
+++ b/Userland/Libraries/LibJS/Runtime/WrappedFunction.cpp
@@ -22,7 +22,7 @@ ThrowCompletionOr<NonnullGCPtr<WrappedFunction>> WrappedFunction::create(Realm&
// 5. Set wrapped.[[WrappedTargetFunction]] to Target.
// 6. Set wrapped.[[Realm]] to callerRealm.
auto& prototype = *caller_realm.intrinsics().function_prototype();
- auto wrapped = vm.heap().allocate<WrappedFunction>(realm, caller_realm, target, prototype);
+ auto wrapped = MUST_OR_THROW_OOM(vm.heap().allocate<WrappedFunction>(realm, caller_realm, target, prototype));
// 7. Let result be CopyNameAndLength(wrapped, Target).
auto result = copy_name_and_length(vm, *wrapped, target);