mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 15:17:36 +00:00
LibJS: Replace GlobalObject with VM in Iterator AOs [Part 7/19]
This commit is contained in:
parent
ae9e031f56
commit
ccdfa2320c
30 changed files with 171 additions and 182 deletions
|
@ -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);
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue