1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 13:18:13 +00:00
serenity/Userland/Libraries/LibWeb/URL/URLSearchParams.h
Andreas Kling 6f433c8656 LibWeb+LibJS: Make the EventTarget hierarchy (incl. DOM) GC-allocated
This is a monster patch that turns all EventTargets into GC-allocated
PlatformObjects. Their C++ wrapper classes are removed, and the LibJS
garbage collector is now responsible for their lifetimes.

There's a fair amount of hacks and band-aids in this patch, and we'll
have a lot of cleanup to do after this.
2022-09-06 00:27:09 +02:00

68 lines
1.7 KiB
C++

/*
* Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/URL.h>
#include <AK/Vector.h>
#include <LibWeb/Bindings/Wrappable.h>
#include <LibWeb/DOM/ExceptionOr.h>
namespace Web::URL {
struct QueryParam {
String name;
String value;
};
String url_encode(Vector<QueryParam> const&, AK::URL::PercentEncodeSet);
Vector<QueryParam> url_decode(StringView);
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(HTML::Window&, Variant<Vector<Vector<String>>, OrderedHashMap<String, String>, String> const& init);
void append(String const& name, String const& value);
void delete_(String const& name);
String get(String const& name);
Vector<String> get_all(String const& name);
bool has(String const& name);
void set(String const& name, String const& value);
void sort();
String to_string() const;
using ForEachCallback = Function<JS::ThrowCompletionOr<void>(String const&, String const&)>;
JS::ThrowCompletionOr<void> for_each(ForEachCallback);
private:
friend class URL;
friend class URLSearchParamsIterator;
explicit URLSearchParams(Vector<QueryParam> list)
: m_list(move(list)) {};
void update();
Vector<QueryParam> m_list;
WeakPtr<URL> m_url;
};
}
namespace Web::Bindings {
URLSearchParamsWrapper* wrap(JS::Realm&, URL::URLSearchParams&);
}