Serenity Operating System
1/*
2 * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
3 *
4 * SPDX-License-Identifier: BSD-2-Clause
5 */
6
7#include <LibWeb/Bindings/Intrinsics.h>
8#include <LibWeb/DOM/Node.h>
9#include <LibWeb/DOM/NodeList.h>
10
11namespace Web::DOM {
12
13NodeList::NodeList(JS::Realm& realm)
14 : LegacyPlatformObject(realm)
15{
16}
17
18NodeList::~NodeList() = default;
19
20JS::ThrowCompletionOr<void> NodeList::initialize(JS::Realm& realm)
21{
22 MUST_OR_THROW_OOM(Base::initialize(realm));
23 set_prototype(&Bindings::ensure_web_prototype<Bindings::NodeListPrototype>(realm, "NodeList"));
24
25 return {};
26}
27
28WebIDL::ExceptionOr<JS::Value> NodeList::item_value(size_t index) const
29{
30 auto* node = item(index);
31 if (!node)
32 return JS::js_undefined();
33 return const_cast<Node*>(node);
34}
35
36bool NodeList::is_supported_property_index(u32 index) const
37{
38 return index < length();
39}
40
41}