Skip to content

Commit

Permalink
Add URLSearchParams's size
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=252749
rdar://105781287

Reviewed by Darin Adler.

Add support for URLSearchParams.size:
- whatwg/url#734
- web-platform-tests/wpt#38655

* LayoutTests/imported/w3c/web-platform-tests/url/urlsearchparams-size.any-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/url/urlsearchparams-size.any.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/url/urlsearchparams-size.any.js: Added.
(test):
* LayoutTests/imported/w3c/web-platform-tests/url/urlsearchparams-size.any.worker-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/url/urlsearchparams-size.any.worker.html: Added.
* Source/WebCore/html/URLSearchParams.h:
(WebCore::URLSearchParams::size const):
* Source/WebCore/html/URLSearchParams.idl:

Canonical link: https://commits.webkit.org/260836@main
  • Loading branch information
cdumez committed Feb 25, 2023
1 parent 624d353 commit 2f4844a
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

PASS URLSearchParams's size and deletion
PASS URLSearchParams's size and addition
PASS URLSearchParams's size when obtained from a URL
PASS URLSearchParams's size when obtained from a URL and using .search

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!-- This file is required for WebKit test infrastructure to run the templated test -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
test(() => {
const params = new URLSearchParams("a=1&b=2&a=3");
assert_equals(params.size, 3);

params.delete("a");
assert_equals(params.size, 1);
}, "URLSearchParams's size and deletion");

test(() => {
const params = new URLSearchParams("a=1&b=2&a=3");
assert_equals(params.size, 3);

params.append("b", "4");
assert_equals(params.size, 4);
}, "URLSearchParams's size and addition");

test(() => {
const url = new URL("http://localhost/query?a=1&b=2&a=3");
assert_equals(url.searchParams.size, 3);

url.searchParams.delete("a");
assert_equals(url.searchParams.size, 1);

url.searchParams.append("b", 4);
assert_equals(url.searchParams.size, 2);
}, "URLSearchParams's size when obtained from a URL");

test(() => {
const url = new URL("http://localhost/query?a=1&b=2&a=3");
assert_equals(url.searchParams.size, 3);

url.search = "?";
assert_equals(url.searchParams.size, 0);
}, "URLSearchParams's size when obtained from a URL and using .search");
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

PASS URLSearchParams's size and deletion
PASS URLSearchParams's size and addition
PASS URLSearchParams's size when obtained from a URL
PASS URLSearchParams's size when obtained from a URL and using .search

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!-- This file is required for WebKit test infrastructure to run the templated test -->
2 changes: 2 additions & 0 deletions Source/WebCore/html/URLSearchParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class URLSearchParams : public RefCounted<URLSearchParams> {
return adoptRef(*new URLSearchParams(string, associatedURL));
}

size_t size() const { return m_pairs.size(); }

void append(const String& name, const String& value);
void remove(const String& name);
String get(const String& name) const;
Expand Down
2 changes: 2 additions & 0 deletions Source/WebCore/html/URLSearchParams.idl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,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);
[ImplementedAs=remove] undefined delete(USVString name);
USVString? get(USVString name);
Expand Down

0 comments on commit 2f4844a

Please sign in to comment.