mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 11:07:35 +00:00
LibWeb: Add support for the record variant of URLSearchParams
This commit is contained in:
parent
b7c435de17
commit
b305ee8692
3 changed files with 16 additions and 5 deletions
|
@ -66,7 +66,9 @@ Vector<QueryParam> url_decode(StringView input)
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
DOM::ExceptionOr<NonnullRefPtr<URLSearchParams>> URLSearchParams::create_with_global_object(Bindings::WindowObject&, Variant<Vector<Vector<String>>, String> const& init)
|
// https://url.spec.whatwg.org/#dom-urlsearchparams-urlsearchparams
|
||||||
|
// https://url.spec.whatwg.org/#urlsearchparams-initialize
|
||||||
|
DOM::ExceptionOr<NonnullRefPtr<URLSearchParams>> URLSearchParams::create_with_global_object(Bindings::WindowObject&, Variant<Vector<Vector<String>>, OrderedHashMap<String, String>, String> const& init)
|
||||||
{
|
{
|
||||||
// 1. If init is a string and starts with U+003F (?), then remove the first code point from init.
|
// 1. If init is a string and starts with U+003F (?), then remove the first code point from init.
|
||||||
// NOTE: We do this when we know that it's a string on step 3 of initialization.
|
// NOTE: We do this when we know that it's a string on step 3 of initialization.
|
||||||
|
@ -94,8 +96,18 @@ DOM::ExceptionOr<NonnullRefPtr<URLSearchParams>> URLSearchParams::create_with_gl
|
||||||
return URLSearchParams::create(move(list));
|
return URLSearchParams::create(move(list));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
|
||||||
// 2. Otherwise, if init is a record, then for each name → value of init, append a new name-value pair whose name is name and value is value, to query’s list.
|
// 2. Otherwise, if init is a record, then for each name → value of init, append a new name-value pair whose name is name and value is value, to query’s list.
|
||||||
|
if (init.has<OrderedHashMap<String, String>>()) {
|
||||||
|
auto const& init_record = init.get<OrderedHashMap<String, String>>();
|
||||||
|
|
||||||
|
Vector<QueryParam> list;
|
||||||
|
list.ensure_capacity(init_record.size());
|
||||||
|
|
||||||
|
for (auto const& pair : init_record)
|
||||||
|
list.append(QueryParam { .name = pair.key, .value = pair.value });
|
||||||
|
|
||||||
|
return URLSearchParams::create(move(list));
|
||||||
|
}
|
||||||
|
|
||||||
// 3. Otherwise:
|
// 3. Otherwise:
|
||||||
// a. Assert: init is a string.
|
// a. Assert: init is a string.
|
||||||
|
|
|
@ -30,7 +30,7 @@ public:
|
||||||
return adopt_ref(*new URLSearchParams(move(list)));
|
return adopt_ref(*new URLSearchParams(move(list)));
|
||||||
}
|
}
|
||||||
|
|
||||||
static DOM::ExceptionOr<NonnullRefPtr<URLSearchParams>> create_with_global_object(Bindings::WindowObject&, Variant<Vector<Vector<String>>, String> const& init);
|
static DOM::ExceptionOr<NonnullRefPtr<URLSearchParams>> create_with_global_object(Bindings::WindowObject&, Variant<Vector<Vector<String>>, OrderedHashMap<String, String>, String> const& init);
|
||||||
|
|
||||||
void append(String const& name, String const& value);
|
void append(String const& name, String const& value);
|
||||||
void delete_(String const& name);
|
void delete_(String const& name);
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
interface URLSearchParams {
|
interface URLSearchParams {
|
||||||
|
|
||||||
// FIXME: the real type of init is (sequence<sequence<USVString>> or record<USVString, USVString> or USVString)
|
constructor(optional (sequence<sequence<USVString>> or record<USVString, USVString> or USVString) init = "");
|
||||||
constructor(optional (sequence<sequence<USVString>> or USVString) init = "");
|
|
||||||
|
|
||||||
undefined append(USVString name, USVString value);
|
undefined append(USVString name, USVString value);
|
||||||
undefined delete(USVString name);
|
undefined delete(USVString name);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue