LibJS: Convert SetIterator.prototype to be a PrototypeObject
This commit is contained in:
parent
75d5c17aec
commit
f195cb41a8
Notes:
sideshowbarker
2024-07-18 04:13:34 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/f195cb41a8f Pull-request: https://github.com/SerenityOS/serenity/pull/9973 Reviewed-by: https://github.com/linusg ✅
2 changed files with 14 additions and 17 deletions
Userland/Libraries/LibJS/Runtime
|
@ -9,13 +9,12 @@
|
|||
#include <LibJS/Runtime/Error.h>
|
||||
#include <LibJS/Runtime/GlobalObject.h>
|
||||
#include <LibJS/Runtime/IteratorOperations.h>
|
||||
#include <LibJS/Runtime/SetIterator.h>
|
||||
#include <LibJS/Runtime/SetIteratorPrototype.h>
|
||||
|
||||
namespace JS {
|
||||
|
||||
SetIteratorPrototype::SetIteratorPrototype(GlobalObject& global_object)
|
||||
: Object(*global_object.iterator_prototype())
|
||||
: PrototypeObject(*global_object.iterator_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -37,27 +36,24 @@ SetIteratorPrototype::~SetIteratorPrototype()
|
|||
// 24.2.5.2.1 %SetIteratorPrototype%.next ( ), https://tc39.es/ecma262/#sec-%setiteratorprototype%.next
|
||||
JS_DEFINE_NATIVE_FUNCTION(SetIteratorPrototype::next)
|
||||
{
|
||||
auto this_value = vm.this_value(global_object);
|
||||
if (!this_value.is_object() || !is<SetIterator>(this_value.as_object())) {
|
||||
vm.throw_exception<TypeError>(global_object, ErrorType::NotAnObjectOfType, "Set Iterator");
|
||||
auto* set_iterator = typed_this_value(global_object);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
}
|
||||
|
||||
auto& set_iterator = static_cast<SetIterator&>(this_value.as_object());
|
||||
if (set_iterator.done())
|
||||
if (set_iterator->done())
|
||||
return create_iterator_result_object(global_object, js_undefined(), true);
|
||||
|
||||
auto& set = set_iterator.set();
|
||||
if (set_iterator.m_iterator == set.values().end()) {
|
||||
set_iterator.m_done = true;
|
||||
auto& set = set_iterator->set();
|
||||
if (set_iterator->m_iterator == set.values().end()) {
|
||||
set_iterator->m_done = true;
|
||||
return create_iterator_result_object(global_object, js_undefined(), true);
|
||||
}
|
||||
|
||||
auto iteration_kind = set_iterator.iteration_kind();
|
||||
auto iteration_kind = set_iterator->iteration_kind();
|
||||
VERIFY(iteration_kind != Object::PropertyKind::Key);
|
||||
|
||||
auto value = *set_iterator.m_iterator;
|
||||
++set_iterator.m_iterator;
|
||||
auto value = *set_iterator->m_iterator;
|
||||
++set_iterator->m_iterator;
|
||||
if (iteration_kind == Object::PropertyKind::Value)
|
||||
return create_iterator_result_object(global_object, value, false);
|
||||
|
||||
|
|
|
@ -6,12 +6,13 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <LibJS/Runtime/Object.h>
|
||||
#include <LibJS/Runtime/PrototypeObject.h>
|
||||
#include <LibJS/Runtime/SetIterator.h>
|
||||
|
||||
namespace JS {
|
||||
|
||||
class SetIteratorPrototype final : public Object {
|
||||
JS_OBJECT(SetIteratorPrototype, Object)
|
||||
class SetIteratorPrototype final : public PrototypeObject<SetIteratorPrototype, SetIterator> {
|
||||
JS_PROTOTYPE_OBJECT(SetIteratorPrototype, SetIterator, SetIterator);
|
||||
|
||||
public:
|
||||
SetIteratorPrototype(GlobalObject&);
|
||||
|
|
Loading…
Add table
Reference in a new issue