mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:47:35 +00:00
LibJS: Convert MapIterator.prototype to be a PrototypeObject
This commit is contained in:
parent
77efecadf7
commit
f5c988b3ce
2 changed files with 14 additions and 17 deletions
|
@ -9,13 +9,12 @@
|
||||||
#include <LibJS/Runtime/Error.h>
|
#include <LibJS/Runtime/Error.h>
|
||||||
#include <LibJS/Runtime/GlobalObject.h>
|
#include <LibJS/Runtime/GlobalObject.h>
|
||||||
#include <LibJS/Runtime/IteratorOperations.h>
|
#include <LibJS/Runtime/IteratorOperations.h>
|
||||||
#include <LibJS/Runtime/MapIterator.h>
|
|
||||||
#include <LibJS/Runtime/MapIteratorPrototype.h>
|
#include <LibJS/Runtime/MapIteratorPrototype.h>
|
||||||
|
|
||||||
namespace JS {
|
namespace JS {
|
||||||
|
|
||||||
MapIteratorPrototype::MapIteratorPrototype(GlobalObject& global_object)
|
MapIteratorPrototype::MapIteratorPrototype(GlobalObject& global_object)
|
||||||
: Object(*global_object.iterator_prototype())
|
: PrototypeObject(*global_object.iterator_prototype())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,26 +34,23 @@ MapIteratorPrototype::~MapIteratorPrototype()
|
||||||
// 24.1.5.2.1 %MapIteratorPrototype%.next ( ), https://tc39.es/ecma262/#sec-%mapiteratorprototype%.next
|
// 24.1.5.2.1 %MapIteratorPrototype%.next ( ), https://tc39.es/ecma262/#sec-%mapiteratorprototype%.next
|
||||||
JS_DEFINE_NATIVE_FUNCTION(MapIteratorPrototype::next)
|
JS_DEFINE_NATIVE_FUNCTION(MapIteratorPrototype::next)
|
||||||
{
|
{
|
||||||
auto this_value = vm.this_value(global_object);
|
auto* map_iterator = typed_this_value(global_object);
|
||||||
if (!this_value.is_object() || !is<MapIterator>(this_value.as_object())) {
|
if (vm.exception())
|
||||||
vm.throw_exception<TypeError>(global_object, ErrorType::NotAnObjectOfType, "Map Iterator");
|
|
||||||
return {};
|
return {};
|
||||||
}
|
|
||||||
|
|
||||||
auto& map_iterator = static_cast<MapIterator&>(this_value.as_object());
|
if (map_iterator->done())
|
||||||
if (map_iterator.done())
|
|
||||||
return create_iterator_result_object(global_object, js_undefined(), true);
|
return create_iterator_result_object(global_object, js_undefined(), true);
|
||||||
|
|
||||||
auto& map = map_iterator.map();
|
auto& map = map_iterator->map();
|
||||||
if (map_iterator.m_iterator == map.entries().end()) {
|
if (map_iterator->m_iterator == map.entries().end()) {
|
||||||
map_iterator.m_done = true;
|
map_iterator->m_done = true;
|
||||||
return create_iterator_result_object(global_object, js_undefined(), true);
|
return create_iterator_result_object(global_object, js_undefined(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto iteration_kind = map_iterator.iteration_kind();
|
auto iteration_kind = map_iterator->iteration_kind();
|
||||||
|
|
||||||
auto entry = *map_iterator.m_iterator;
|
auto entry = *map_iterator->m_iterator;
|
||||||
++map_iterator.m_iterator;
|
++map_iterator->m_iterator;
|
||||||
if (iteration_kind == Object::PropertyKind::Key)
|
if (iteration_kind == Object::PropertyKind::Key)
|
||||||
return create_iterator_result_object(global_object, entry.key, false);
|
return create_iterator_result_object(global_object, entry.key, false);
|
||||||
else if (iteration_kind == Object::PropertyKind::Value)
|
else if (iteration_kind == Object::PropertyKind::Value)
|
||||||
|
|
|
@ -6,12 +6,13 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <LibJS/Runtime/Object.h>
|
#include <LibJS/Runtime/MapIterator.h>
|
||||||
|
#include <LibJS/Runtime/PrototypeObject.h>
|
||||||
|
|
||||||
namespace JS {
|
namespace JS {
|
||||||
|
|
||||||
class MapIteratorPrototype final : public Object {
|
class MapIteratorPrototype final : public PrototypeObject<MapIteratorPrototype, MapIterator> {
|
||||||
JS_OBJECT(MapIteratorPrototype, Object)
|
JS_PROTOTYPE_OBJECT(MapIteratorPrototype, MapIterator, MapIterator);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MapIteratorPrototype(GlobalObject&);
|
MapIteratorPrototype(GlobalObject&);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue