1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 22:27:44 +00:00

LibWeb: Add the URLSearchParams built-in

This is a very partial implementation, as some features (like 2 of the
possible constructor types, iteration and the getAll method) are
missing, and other's are not implemented due to the currently missing
URL built-in.
This commit is contained in:
Idan Horowitz 2021-09-13 01:00:47 +03:00 committed by Andreas Kling
parent de19dcf81a
commit f21041861b
6 changed files with 209 additions and 1 deletions

View file

@ -0,0 +1,46 @@
/*
* Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/Bindings/Wrappable.h>
#include <LibWeb/DOM/ExceptionOr.h>
#include <LibWeb/URL/URL.h>
namespace Web::URL {
class URLSearchParams : public Bindings::Wrappable
, public RefCounted<URLSearchParams> {
public:
using WrapperType = Bindings::URLSearchParamsWrapper;
static NonnullRefPtr<URLSearchParams> create(Vector<QueryParam> list)
{
return adopt_ref(*new URLSearchParams(move(list)));
}
static DOM::ExceptionOr<NonnullRefPtr<URLSearchParams>> create_with_global_object(Bindings::WindowObject&, const String& init);
void append(String const& name, String const& value);
void delete_(String const& name);
String get(String const& name);
bool has(String const& name);
void set(String const& name, String const& value);
void sort();
String to_string();
private:
explicit URLSearchParams(Vector<QueryParam> list)
: m_list(move(list)) {};
void update();
Vector<QueryParam> m_list;
};
}