summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2022-01-25 15:06:40 -0500
committerLinus Groh <mail@linusgroh.de>2022-01-25 22:09:13 +0000
commit59ca435172aa0bb60b7723b9bcb8d46132dcb2c8 (patch)
tree08f59fc5e40ff6832597d4e517ce32b9ce1e4275 /Userland/Libraries
parent67e02f6ca60b110ba642bb3b325cd6fd208da582 (diff)
downloadserenity-59ca435172aa0bb60b7723b9bcb8d46132dcb2c8.zip
LibJS: Use new construct AO overload where easily applicable
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibJS/Runtime/ArrayBufferPrototype.cpp5
-rw-r--r--Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp18
-rw-r--r--Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/DatePrototype.cpp7
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp7
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormat.cpp5
-rw-r--r--Userland/Libraries/LibJS/Runtime/NumberPrototype.cpp6
-rw-r--r--Userland/Libraries/LibJS/Runtime/PromiseReaction.cpp5
-rw-r--r--Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp10
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp4
10 files changed, 16 insertions, 55 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/ArrayBufferPrototype.cpp b/Userland/Libraries/LibJS/Runtime/ArrayBufferPrototype.cpp
index 3ce1636e20..1ba8237ec8 100644
--- a/Userland/Libraries/LibJS/Runtime/ArrayBufferPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/ArrayBufferPrototype.cpp
@@ -63,10 +63,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayBufferPrototype::slice)
auto new_length = max(final - first, 0.0);
auto* constructor = TRY(species_constructor(global_object, *array_buffer_object, *global_object.array_buffer_constructor()));
-
- MarkedValueList arguments(vm.heap());
- arguments.append(Value(new_length));
- auto* new_array_buffer = TRY(construct(global_object, *constructor, move(arguments)));
+ auto* new_array_buffer = TRY(construct(global_object, *constructor, Value(new_length)));
if (!is<ArrayBuffer>(new_array_buffer))
return vm.throw_completion<TypeError>(global_object, ErrorType::SpeciesConstructorDidNotCreate, "an ArrayBuffer");
diff --git a/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp b/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp
index 0f457e4c04..ff5e032812 100644
--- a/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp
+++ b/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp
@@ -148,13 +148,10 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::from)
auto length = TRY(length_of_array_like(global_object, *array_like));
Object* array;
- if (constructor.is_constructor()) {
- MarkedValueList arguments(vm.heap());
- arguments.empend(length);
- array = TRY(JS::construct(global_object, constructor.as_function(), move(arguments)));
- } else {
+ if (constructor.is_constructor())
+ array = TRY(JS::construct(global_object, constructor.as_function(), Value(length)));
+ else
array = TRY(Array::create(global_object, length));
- }
for (size_t k = 0; k < length; ++k) {
auto k_value = TRY(array_like->get(k));
@@ -183,13 +180,10 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::of)
{
auto this_value = vm.this_value(global_object);
Object* array;
- if (this_value.is_constructor()) {
- MarkedValueList arguments(vm.heap());
- arguments.empend(vm.argument_count());
- array = TRY(JS::construct(global_object, this_value.as_function(), move(arguments)));
- } else {
+ if (this_value.is_constructor())
+ array = TRY(JS::construct(global_object, this_value.as_function(), Value(vm.argument_count())));
+ else
array = TRY(Array::create(global_object, vm.argument_count()));
- }
for (size_t k = 0; k < vm.argument_count(); ++k)
TRY(array->create_data_property_or_throw(k, vm.argument(k)));
TRY(array->set(vm.names.length, Value(vm.argument_count()), Object::ShouldThrowExceptions::Yes));
diff --git a/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp b/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp
index f914c88834..7a7b96a426 100644
--- a/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp
@@ -142,9 +142,7 @@ static ThrowCompletionOr<Object*> array_species_create(GlobalObject& global_obje
if (!constructor.is_constructor())
return vm.throw_completion<TypeError>(global_object, ErrorType::NotAConstructor, constructor.to_string_without_side_effects());
- MarkedValueList arguments(vm.heap());
- arguments.append(Value(length));
- return TRY(construct(global_object, constructor.as_function(), move(arguments)));
+ return TRY(construct(global_object, constructor.as_function(), Value(length)));
}
// 23.1.3.8 Array.prototype.filter ( callbackfn [ , thisArg ] ), https://tc39.es/ecma262/#sec-array.prototype.filter
diff --git a/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp b/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp
index 99b87fe38c..c2ed435de4 100644
--- a/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp
@@ -21,7 +21,6 @@
#include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/Intl/DateTimeFormat.h>
#include <LibJS/Runtime/Intl/DateTimeFormatConstructor.h>
-#include <LibJS/Runtime/MarkedValueList.h>
#include <LibJS/Runtime/Temporal/Instant.h>
#include <LibJS/Runtime/Value.h>
#include <LibTimeZone/TimeZone.h>
@@ -890,11 +889,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_json)
static ThrowCompletionOr<Intl::DateTimeFormat*> construct_date_time_format(GlobalObject& global_object, Value locales, Value options)
{
- MarkedValueList arguments { global_object.vm().heap() };
- arguments.append(locales);
- arguments.append(options);
-
- auto* date_time_format = TRY(construct(global_object, *global_object.intl_date_time_format_constructor(), move(arguments)));
+ auto* date_time_format = TRY(construct(global_object, *global_object.intl_date_time_format_constructor(), locales, options));
return static_cast<Intl::DateTimeFormat*>(date_time_format);
}
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp
index 6b9eedc1c4..fc46ee611b 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp
@@ -12,7 +12,6 @@
#include <LibJS/Runtime/Intl/DateTimeFormat.h>
#include <LibJS/Runtime/Intl/NumberFormat.h>
#include <LibJS/Runtime/Intl/NumberFormatConstructor.h>
-#include <LibJS/Runtime/MarkedValueList.h>
#include <LibJS/Runtime/NativeFunction.h>
#include <LibJS/Runtime/Temporal/TimeZone.h>
#include <LibJS/Runtime/Utf16String.h>
@@ -828,11 +827,7 @@ ThrowCompletionOr<Vector<PatternPartition>> format_date_time_pattern(GlobalObjec
auto const& data_locale = date_time_format.data_locale();
auto construct_number_format = [&](auto* options) -> ThrowCompletionOr<NumberFormat*> {
- MarkedValueList arguments { vm.heap() };
- arguments.append(js_string(vm, locale));
- arguments.append(options);
-
- auto* number_format = TRY(construct(global_object, *global_object.intl_number_format_constructor(), move(arguments)));
+ auto* number_format = TRY(construct(global_object, *global_object.intl_number_format_constructor(), js_string(vm, locale), options));
return static_cast<NumberFormat*>(number_format);
};
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormat.cpp
index 01988e7245..26f3a9a2a0 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormat.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormat.cpp
@@ -110,11 +110,8 @@ ThrowCompletionOr<RelativeTimeFormat*> initialize_relative_time_format(GlobalObj
// 18. Set relativeTimeFormat.[[Numeric]] to numeric.
relative_time_format.set_numeric(numeric.as_string().string());
- MarkedValueList arguments { vm.heap() };
- arguments.append(js_string(vm, locale));
-
// 19. Let relativeTimeFormat.[[NumberFormat]] be ! Construct(%NumberFormat%, « locale »).
- auto* number_format = MUST(construct(global_object, *global_object.intl_number_format_constructor(), move(arguments)));
+ auto* number_format = MUST(construct(global_object, *global_object.intl_number_format_constructor(), js_string(vm, locale)));
relative_time_format.set_number_format(static_cast<NumberFormat*>(number_format));
// 20. Let relativeTimeFormat.[[PluralRules]] be ! Construct(%PluralRules%, « locale »).
diff --git a/Userland/Libraries/LibJS/Runtime/NumberPrototype.cpp b/Userland/Libraries/LibJS/Runtime/NumberPrototype.cpp
index 0c828888af..64505754d8 100644
--- a/Userland/Libraries/LibJS/Runtime/NumberPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/NumberPrototype.cpp
@@ -290,12 +290,8 @@ JS_DEFINE_NATIVE_FUNCTION(NumberPrototype::to_locale_string)
// 1. Let x be ? thisNumberValue(this value).
auto number_value = TRY(this_number_value(global_object, vm.this_value(global_object)));
- MarkedValueList arguments { vm.heap() };
- arguments.append(locales);
- arguments.append(options);
-
// 2. Let numberFormat be ? Construct(%NumberFormat%, « locales, options »).
- auto* number_format = static_cast<Intl::NumberFormat*>(TRY(construct(global_object, *global_object.intl_number_format_constructor(), move(arguments))));
+ auto* number_format = static_cast<Intl::NumberFormat*>(TRY(construct(global_object, *global_object.intl_number_format_constructor(), locales, options)));
// 3. Return ? FormatNumeric(numberFormat, x).
// Note: Our implementation of FormatNumeric does not throw.
diff --git a/Userland/Libraries/LibJS/Runtime/PromiseReaction.cpp b/Userland/Libraries/LibJS/Runtime/PromiseReaction.cpp
index 31b7915af6..42858cc16b 100644
--- a/Userland/Libraries/LibJS/Runtime/PromiseReaction.cpp
+++ b/Userland/Libraries/LibJS/Runtime/PromiseReaction.cpp
@@ -6,7 +6,6 @@
#include <LibJS/Runtime/AbstractOperations.h>
#include <LibJS/Runtime/Error.h>
-#include <LibJS/Runtime/MarkedValueList.h>
#include <LibJS/Runtime/NativeFunction.h>
#include <LibJS/Runtime/PromiseReaction.h>
@@ -59,9 +58,7 @@ ThrowCompletionOr<PromiseCapability> new_promise_capability(GlobalObject& global
executor->define_direct_property(vm.names.name, js_string(vm, String::empty()), Attribute::Configurable);
// 6. Let promise be ? Construct(C, « executor »).
- MarkedValueList arguments(vm.heap());
- arguments.append(executor);
- auto* promise = TRY(construct(global_object, constructor.as_function(), move(arguments)));
+ auto* promise = TRY(construct(global_object, constructor.as_function(), executor));
// 7. If IsCallable(promiseCapability.[[Resolve]]) is false, throw a TypeError exception.
if (!promise_capability_functions.resolve.is_function())
diff --git a/Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp b/Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp
index 444bac067d..dc600fc787 100644
--- a/Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp
@@ -600,10 +600,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_match_all)
bool full_unicode = flags.contains('u');
// 6. Let matcher be ? Construct(C, « R, flags »).
- MarkedValueList arguments(vm.heap());
- arguments.append(regexp_object);
- arguments.append(js_string(vm, move(flags)));
- auto* matcher = TRY(construct(global_object, *constructor, move(arguments)));
+ auto* matcher = TRY(construct(global_object, *constructor, regexp_object, js_string(vm, move(flags))));
// 7. Let lastIndex be ? ToLength(? Get(R, "lastIndex")).
auto last_index_value = TRY(regexp_object->get(vm.names.lastIndex));
@@ -894,10 +891,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_split)
auto new_flags = flags.find('y').has_value() ? move(flags) : String::formatted("{}y", flags);
// 10. Let splitter be ? Construct(C, « rx, newFlags »).
- MarkedValueList arguments(vm.heap());
- arguments.append(regexp_object);
- arguments.append(js_string(vm, move(new_flags)));
- auto* splitter = TRY(construct(global_object, *constructor, move(arguments)));
+ auto* splitter = TRY(construct(global_object, *constructor, regexp_object, js_string(vm, move(new_flags))));
// 11. Let A be ! ArrayCreate(0).
auto* array = MUST(Array::create(global_object, 0));
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp
index 61195355a6..7f2b397533 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp
@@ -70,9 +70,7 @@ ThrowCompletionOr<Calendar*> get_builtin_calendar(GlobalObject& global_object, S
return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidCalendarIdentifier, identifier);
// 2. Return ? Construct(%Temporal.Calendar%, « id »).
- MarkedValueList arguments(vm.heap());
- arguments.append(js_string(vm, identifier));
- return static_cast<Calendar*>(TRY(construct(global_object, *global_object.temporal_calendar_constructor(), move(arguments))));
+ return static_cast<Calendar*>(TRY(construct(global_object, *global_object.temporal_calendar_constructor(), js_string(vm, identifier))));
}
// 12.1.4 GetISO8601Calendar ( ), https://tc39.es/proposal-temporal/#sec-temporal-getiso8601calendar