mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:48:11 +00:00
LibJS: Implement proper Iterator records
Instead of using plain objects as Iterator records, causes confusion about the object itself actually being its [[Iterator]] slot, and requires non-standard type conversion shenanigans fpr the [[NextValue]] and [[Done]] internal slots, implement a proper Iterator record struct and use it throughout. Also annotate the remaining Iterator AOs with spec comments while we're here.
This commit is contained in:
parent
e141f1e976
commit
09a11fa6ea
17 changed files with 337 additions and 209 deletions
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2020, Linus Groh <linusg@serenityos.org>
|
||||
* Copyright (c) 2020-2022, Linus Groh <linusg@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -114,10 +114,10 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::from)
|
|||
while (true) {
|
||||
if (k >= MAX_ARRAY_LIKE_INDEX) {
|
||||
auto error = vm.throw_completion<TypeError>(global_object, ErrorType::ArrayMaxSize);
|
||||
return TRY(iterator_close(*iterator, move(error)));
|
||||
return TRY(iterator_close(global_object, iterator, move(error)));
|
||||
}
|
||||
|
||||
auto* next = TRY(iterator_step(global_object, *iterator));
|
||||
auto* next = TRY(iterator_step(global_object, iterator));
|
||||
if (!next) {
|
||||
TRY(array->set(vm.names.length, Value(k), Object::ShouldThrowExceptions::Yes));
|
||||
return array;
|
||||
|
@ -129,7 +129,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::from)
|
|||
if (map_fn) {
|
||||
auto mapped_value_or_error = vm.call(*map_fn, this_arg, next_value, Value(k));
|
||||
if (mapped_value_or_error.is_error())
|
||||
return TRY(iterator_close(*iterator, mapped_value_or_error.release_error()));
|
||||
return TRY(iterator_close(global_object, iterator, mapped_value_or_error.release_error()));
|
||||
mapped_value = mapped_value_or_error.release_value();
|
||||
} else {
|
||||
mapped_value = next_value;
|
||||
|
@ -137,7 +137,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::from)
|
|||
|
||||
auto result_or_error = array->create_data_property_or_throw(k, mapped_value);
|
||||
if (result_or_error.is_error())
|
||||
return TRY(iterator_close(*iterator, result_or_error.release_error()));
|
||||
return TRY(iterator_close(global_object, iterator, result_or_error.release_error()));
|
||||
|
||||
++k;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue