summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Runtime/Temporal
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2022-08-21 15:56:27 +0100
committerLinus Groh <mail@linusgroh.de>2022-08-23 13:58:30 +0100
commitccdfa2320cb93ed299d12107f1f991b7e358fb7f (patch)
tree17964244fb1a6c40627271525edbfb8e0f8118e2 /Userland/Libraries/LibJS/Runtime/Temporal
parentae9e031f567937db0119ac4d649ae5ccf24e41f7 (diff)
downloadserenity-ccdfa2320cb93ed299d12107f1f991b7e358fb7f.zip
LibJS: Replace GlobalObject with VM in Iterator AOs [Part 7/19]
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime/Temporal')
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp11
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp12
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp11
3 files changed, 14 insertions, 20 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp
index f092f2fbcf..06eef65264 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp
@@ -41,11 +41,8 @@ static Optional<OptionType> to_option_type(Value value)
// 13.1 IterableToListOfType ( items, elementTypes ), https://tc39.es/proposal-temporal/#sec-iterabletolistoftype
ThrowCompletionOr<MarkedVector<Value>> iterable_to_list_of_type(VM& vm, Value items, Vector<OptionType> const& element_types)
{
- auto& realm = *vm.current_realm();
- auto& global_object = realm.global_object();
-
// 1. Let iteratorRecord be ? GetIterator(items, sync).
- auto iterator_record = TRY(get_iterator(global_object, items, IteratorHint::Sync));
+ auto iterator_record = TRY(get_iterator(vm, items, IteratorHint::Sync));
// 2. Let values be a new empty List.
MarkedVector<Value> values(vm.heap());
@@ -55,19 +52,19 @@ ThrowCompletionOr<MarkedVector<Value>> iterable_to_list_of_type(VM& vm, Value it
// 4. Repeat, while next is not false,
while (next) {
// a. Set next to ? IteratorStep(iteratorRecord).
- auto* iterator_result = TRY(iterator_step(global_object, iterator_record));
+ auto* iterator_result = TRY(iterator_step(vm, iterator_record));
next = iterator_result;
// b. If next is not false, then
if (next) {
// i. Let nextValue be ? IteratorValue(next).
- auto next_value = TRY(iterator_value(global_object, *iterator_result));
+ auto next_value = TRY(iterator_value(vm, *iterator_result));
// ii. If Type(nextValue) is not an element of elementTypes, then
if (auto type = to_option_type(next_value); !type.has_value() || !element_types.contains_slow(*type)) {
// 1. Let completion be ThrowCompletion(a newly created TypeError object).
auto completion = vm.throw_completion<TypeError>(ErrorType::IterableToListOfTypeInvalidValue, next_value.to_string_without_side_effects());
// 2. Return ? IteratorClose(iteratorRecord, completion).
- return iterator_close(global_object, iterator_record, move(completion));
+ return iterator_close(vm, iterator_record, move(completion));
}
// iii. Append nextValue to the end of the List values.
values.append(next_value);
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp
index a44a4d08de..7b2394584e 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp
@@ -513,7 +513,7 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::fields)
VERIFY(calendar->identifier() == "iso8601"sv);
// 4. Let iteratorRecord be ? GetIterator(fields, sync).
- auto iterator_record = TRY(get_iterator(global_object, fields, IteratorHint::Sync));
+ auto iterator_record = TRY(get_iterator(vm, fields, IteratorHint::Sync));
// 5. Let fieldNames be a new empty List.
auto field_names = MarkedVector<Value> { vm.heap() };
@@ -522,14 +522,14 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::fields)
// 7. Repeat, while next is not false,
while (true) {
// a. Set next to ? IteratorStep(iteratorRecord).
- auto* next = TRY(iterator_step(global_object, iterator_record));
+ auto* next = TRY(iterator_step(vm, iterator_record));
// b. If next is not false, then
if (!next)
break;
// i. Let nextValue be ? IteratorValue(next).
- auto next_value = TRY(iterator_value(global_object, *next));
+ auto next_value = TRY(iterator_value(vm, *next));
// ii. If Type(nextValue) is not String, then
if (!next_value.is_string()) {
@@ -537,7 +537,7 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::fields)
auto completion = vm.throw_completion<TypeError>(ErrorType::TemporalInvalidCalendarFieldValue, next_value.to_string_without_side_effects());
// 2. Return ? IteratorClose(iteratorRecord, completion).
- return TRY(iterator_close(global_object, iterator_record, move(completion)));
+ return TRY(iterator_close(vm, iterator_record, move(completion)));
}
// iii. If fieldNames contains nextValue, then
@@ -546,7 +546,7 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::fields)
auto completion = vm.throw_completion<RangeError>(ErrorType::TemporalDuplicateCalendarField, next_value.as_string().string());
// 2. Return ? IteratorClose(iteratorRecord, completion).
- return TRY(iterator_close(global_object, iterator_record, move(completion)));
+ return TRY(iterator_close(vm, iterator_record, move(completion)));
}
// iv. If nextValue is not one of "year", "month", "monthCode", "day", "hour", "minute", "second", "millisecond", "microsecond", "nanosecond", then
@@ -555,7 +555,7 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::fields)
auto completion = vm.throw_completion<RangeError>(ErrorType::TemporalInvalidCalendarFieldName, next_value.as_string().string());
// 2. Return ? IteratorClose(iteratorRecord, completion).
- return TRY(iterator_close(global_object, iterator_record, move(completion)));
+ return TRY(iterator_close(vm, iterator_record, move(completion)));
}
// v. Append nextValue to the end of the List fieldNames.
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp
index f170653eae..6c0ae363c6 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp
@@ -665,16 +665,13 @@ ThrowCompletionOr<Instant*> disambiguate_possible_instants(VM& vm, MarkedVector<
// 11.6.16 GetPossibleInstantsFor ( timeZone, dateTime ), https://tc39.es/proposal-temporal/#sec-temporal-getpossibleinstantsfor
ThrowCompletionOr<MarkedVector<Instant*>> get_possible_instants_for(VM& vm, Value time_zone, PlainDateTime& date_time)
{
- auto& realm = *vm.current_realm();
- auto& global_object = realm.global_object();
-
// 1. Assert: dateTime has an [[InitializedTemporalDateTime]] internal slot.
// 2. Let possibleInstants be ? Invoke(timeZone, "getPossibleInstantsFor", ยซ dateTime ยป).
auto possible_instants = TRY(time_zone.invoke(vm, vm.names.getPossibleInstantsFor, &date_time));
// 3. Let iteratorRecord be ? GetIterator(possibleInstants, sync).
- auto iterator = TRY(get_iterator(global_object, possible_instants, IteratorHint::Sync));
+ auto iterator = TRY(get_iterator(vm, possible_instants, IteratorHint::Sync));
// 4. Let list be a new empty List.
auto list = MarkedVector<Instant*> { vm.heap() };
@@ -685,12 +682,12 @@ ThrowCompletionOr<MarkedVector<Instant*>> get_possible_instants_for(VM& vm, Valu
// 6. Repeat, while next is not false,
do {
// a. Set next to ? IteratorStep(iteratorRecord).
- next = TRY(iterator_step(global_object, iterator));
+ next = TRY(iterator_step(vm, iterator));
// b. If next is not false, then
if (next) {
// i. Let nextValue be ? IteratorValue(next).
- auto next_value = TRY(iterator_value(global_object, *next));
+ auto next_value = TRY(iterator_value(vm, *next));
// ii. If Type(nextValue) is not Object or nextValue does not have an [[InitializedTemporalInstant]] internal slot, then
if (!next_value.is_object() || !is<Instant>(next_value.as_object())) {
@@ -698,7 +695,7 @@ ThrowCompletionOr<MarkedVector<Instant*>> get_possible_instants_for(VM& vm, Valu
auto completion = vm.throw_completion<TypeError>(ErrorType::NotAnObjectOfType, "Temporal.Instant");
// 2. Return ? IteratorClose(iteratorRecord, completion).
- return iterator_close(global_object, iterator, move(completion));
+ return iterator_close(vm, iterator, move(completion));
}
// iii. Append nextValue to the end of the List list.