summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/Bindings
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-04-22 21:11:20 +0200
committerAndreas Kling <kling@serenityos.org>2021-04-22 21:21:46 +0200
commite4df1b223ffcd5437d419342dd3848e9f11f0d63 (patch)
treef3f3afb762dfc67f70edf8e36c06332ef74af602 /Userland/Libraries/LibWeb/Bindings
parent49f3d88baf6fff825c2bf4f3253b3d4916c5274b (diff)
downloadserenity-e4df1b223ffcd5437d419342dd3848e9f11f0d63.zip
LibWeb: Implement a slow but functional HTMLCollection :^)
HTMLCollection is an awkward legacy interface from the DOM spec. It provides a live view of a DOM subtree, with some kind of filtering that determines which elements are part of the collection. We now return HTMLCollection objects from these APIs: - getElementsByClassName() - getElementsByName() - getElementsByTagName() This initial implementation does not do any kind of caching, since that is quite a tricky problem, and there will be plenty of time for tricky problems later on when the engine is more mature.
Diffstat (limited to 'Userland/Libraries/LibWeb/Bindings')
-rw-r--r--Userland/Libraries/LibWeb/Bindings/HTMLCollectionWrapperCustom.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/Bindings/HTMLCollectionWrapperCustom.cpp b/Userland/Libraries/LibWeb/Bindings/HTMLCollectionWrapperCustom.cpp
new file mode 100644
index 0000000000..dae42548f1
--- /dev/null
+++ b/Userland/Libraries/LibWeb/Bindings/HTMLCollectionWrapperCustom.cpp
@@ -0,0 +1,31 @@
+/*
+ * 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::get(JS::PropertyName const& name, JS::Value receiver, bool without_side_effects) const
+{
+ auto* item = const_cast<DOM::HTMLCollection&>(impl()).named_item(name.to_string());
+ if (!item)
+ return Base::get(name, receiver, without_side_effects);
+ return JS::Value { wrap(global_object(), *item) };
+}
+
+JS::Value HTMLCollectionWrapper::get_by_index(u32 property_index) const
+{
+ auto* item = const_cast<DOM::HTMLCollection&>(impl()).item(property_index);
+ if (!item)
+ return Base::get_by_index(property_index);
+ return wrap(global_object(), *item);
+}
+
+}