summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/Bindings/HTMLCollectionWrapperCustom.cpp
blob: 5c51e06203aa4124067039f3c0cf52cbf88e2519 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*
 * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#include <AK/ScopeGuard.h>
#include <LibWeb/Bindings/HTMLCollectionWrapper.h>
#include <LibWeb/Bindings/NodeWrapper.h>
#include <LibWeb/Bindings/NodeWrapperFactory.h>
#include <LibWeb/DOM/Element.h>

namespace Web::Bindings {

JS::Value HTMLCollectionWrapper::internal_get(JS::PropertyName const& property_name, JS::Value receiver) const
{
    if (property_name.is_symbol())
        return Base::internal_get(property_name, receiver);
    DOM::Element* item = nullptr;
    if (property_name.is_string())
        item = const_cast<DOM::HTMLCollection&>(impl()).named_item(property_name.to_string());
    else if (property_name.is_number())
        item = const_cast<DOM::HTMLCollection&>(impl()).item(property_name.as_number());
    if (!item)
        return Base::internal_get(property_name, receiver);
    return wrap(global_object(), *item);
}

}