summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorLuke Wilde <lukew@serenityos.org>2021-09-26 14:53:28 +0100
committerAndreas Kling <kling@serenityos.org>2021-09-26 18:59:56 +0200
commit41ae0c021690326ac8be278174803cb5d3fc3dfc (patch)
tree2f44e3d446167c3c445bae8e2b614f9d664b258d /Userland
parente06762f312676695da5a17e86708c234204a382b (diff)
downloadserenity-41ae0c021690326ac8be278174803cb5d3fc3dfc.zip
LibWeb: Add support for IDL legacy platform objects
A legacy platform object is a non-global platform object that implements a special operation. A special operation is a getter, setter and/or deleter. This is particularly used for old collection types, such as HTMLCollection, NodeList, etc. This will be used to make these spec-compliant and remove their custom wrappers. Additionally, it will be used to implement collections that we don't have yet, such as DOMStringMap.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibWeb/Bindings/IDLAbstractOperations.cpp53
-rw-r--r--Userland/Libraries/LibWeb/Bindings/IDLAbstractOperations.h15
-rw-r--r--Userland/Libraries/LibWeb/CMakeLists.txt1
3 files changed, 69 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/Bindings/IDLAbstractOperations.cpp b/Userland/Libraries/LibWeb/Bindings/IDLAbstractOperations.cpp
new file mode 100644
index 0000000000..1662cf992f
--- /dev/null
+++ b/Userland/Libraries/LibWeb/Bindings/IDLAbstractOperations.cpp
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2021, Luke Wilde <lukew@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <AK/NumericLimits.h>
+#include <LibJS/Runtime/AbstractOperations.h>
+#include <LibJS/Runtime/PropertyName.h>
+#include <LibWeb/Bindings/IDLAbstractOperations.h>
+
+namespace Web::Bindings::IDL {
+
+// https://heycam.github.io/webidl/#is-an-array-index
+bool is_an_array_index(JS::GlobalObject& global_object, JS::PropertyName const& property_name)
+{
+ // 1. If Type(P) is not String, then return false.
+ if (!property_name.is_number())
+ return false;
+
+ // 2. Let index be ! CanonicalNumericIndexString(P).
+ auto index = JS::canonical_numeric_index_string(global_object, property_name);
+
+ // 3. If index is undefined, then return false.
+ if (index.is_undefined())
+ return false;
+
+ // 4. If IsInteger(index) is false, then return false.
+ // NOTE: IsInteger is the old name of IsIntegralNumber.
+ if (!index.is_integral_number())
+ return false;
+
+ // 5. If index is −0, then return false.
+ if (index.is_negative_zero())
+ return false;
+
+ // FIXME: I'm not sure if this is correct.
+ auto index_as_double = index.as_double();
+
+ // 6. If index < 0, then return false.
+ if (index_as_double < 0)
+ return false;
+
+ // 7. If index ≥ 2 ** 32 − 1, then return false.
+ // Note: 2 ** 32 − 1 is the maximum array length allowed by ECMAScript.
+ if (index_as_double >= NumericLimits<u32>::max())
+ return false;
+
+ // 8. Return true.
+ return true;
+}
+
+}
diff --git a/Userland/Libraries/LibWeb/Bindings/IDLAbstractOperations.h b/Userland/Libraries/LibWeb/Bindings/IDLAbstractOperations.h
new file mode 100644
index 0000000000..8a58adee70
--- /dev/null
+++ b/Userland/Libraries/LibWeb/Bindings/IDLAbstractOperations.h
@@ -0,0 +1,15 @@
+/*
+ * Copyright (c) 2021, Luke Wilde <lukew@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <LibJS/Forward.h>
+
+namespace Web::Bindings::IDL {
+
+bool is_an_array_index(JS::GlobalObject&, JS::PropertyName const&);
+
+}
diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt
index 1b0ca1a2f0..3e09f4beb6 100644
--- a/Userland/Libraries/LibWeb/CMakeLists.txt
+++ b/Userland/Libraries/LibWeb/CMakeLists.txt
@@ -4,6 +4,7 @@ set(SOURCES
Bindings/EventTargetWrapperFactory.cpp
Bindings/EventWrapperFactory.cpp
Bindings/HTMLCollectionWrapperCustom.cpp
+ Bindings/IDLAbstractOperations.cpp
Bindings/ImageConstructor.cpp
Bindings/LocationObject.cpp
Bindings/MainThreadVM.cpp