1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 14:37:46 +00:00

LibJS+LibWeb: Refactor GetIterator to use GetIteratorFromMethod

This is an editorial change in the ECMA-262 spec. See:
956e5af

This splits the GetIterator AO into two AOs, to remove some recursion
and to (soon) remove optional parameters.
This commit is contained in:
Timothy Flynn 2023-07-18 14:40:02 -04:00 committed by Andreas Kling
parent b918dcd4db
commit 5703833116
5 changed files with 111 additions and 71 deletions

View file

@ -179,8 +179,8 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::from)
array = MUST(Array::create(realm, 0));
}
// c. Let iteratorRecord be ? GetIterator(items, sync, usingIterator).
auto iterator = TRY(get_iterator(vm, items, IteratorHint::Sync, using_iterator));
// c. Let iteratorRecord be ? GetIteratorFromMethod(items, usingIterator).
auto iterator = TRY(get_iterator_from_method(vm, items, *using_iterator));
// d. Let k be 0.
// e. Repeat,
@ -356,12 +356,14 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::from_async)
// h. If usingAsyncIterator is not undefined, then
if (using_async_iterator) {
// i. Set iteratorRecord to ? GetIterator(asyncItems, async, usingAsyncIterator).
iterator_record = TRY(get_iterator(vm, async_items, IteratorHint::Async, using_async_iterator));
// FIXME: The Array.from proposal is out of date - it should be using GetIteratorFromMethod.
iterator_record = TRY(get_iterator_from_method(vm, async_items, *using_async_iterator));
}
// i. Else if usingSyncIterator is not undefined, then
else if (using_sync_iterator) {
// i. Set iteratorRecord to ? CreateAsyncFromSyncIterator(GetIterator(asyncItems, sync, usingSyncIterator)).
iterator_record = create_async_from_sync_iterator(vm, TRY(get_iterator(vm, async_items, IteratorHint::Sync, using_sync_iterator)));
// FIXME: The Array.from proposal is out of date - it should be using GetIteratorFromMethod.
iterator_record = create_async_from_sync_iterator(vm, TRY(get_iterator_from_method(vm, async_items, *using_sync_iterator)));
}
// j. If iteratorRecord is not undefined, then