Преглед изворни кода

LibWeb: Add size to URLSearchParams

Added new size parameter to URLSearchParams.

Spec: https://url.spec.whatwg.org/#dom-urlsearchparams-size
Co-Authored-By: Linus Groh <mail@linusgroh.de>
CanadaHonk пре 2 година
родитељ
комит
3e2ceef8c3

+ 7 - 0
Userland/Libraries/LibWeb/URL/URLSearchParams.cpp

@@ -149,6 +149,13 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<URLSearchParams>> URLSearchParams::construc
     return URLSearchParams::create(realm, url_decode(stripped_init));
 }
 
+// https://url.spec.whatwg.org/#dom-urlsearchparams-size
+size_t URLSearchParams::size() const
+{
+    // The size getter steps are to return this’s list’s size.
+    return m_list.size();
+}
+
 void URLSearchParams::append(DeprecatedString const& name, DeprecatedString const& value)
 {
     // 1. Append a new name-value pair whose name is name and value is value, to list.

+ 1 - 0
Userland/Libraries/LibWeb/URL/URLSearchParams.h

@@ -28,6 +28,7 @@ public:
 
     virtual ~URLSearchParams() override;
 
+    size_t size() const;
     void append(DeprecatedString const& name, DeprecatedString const& value);
     void delete_(DeprecatedString const& name);
     DeprecatedString get(DeprecatedString const& name);

+ 2 - 0
Userland/Libraries/LibWeb/URL/URLSearchParams.idl

@@ -4,6 +4,8 @@ interface URLSearchParams {
 
   constructor(optional (sequence<sequence<USVString>> or record<USVString, USVString> or USVString) init = "");
 
+  readonly attribute unsigned long size;
+
   undefined append(USVString name, USVString value);
   undefined delete(USVString name);
   USVString? get(USVString name);