mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-21 14:47:31 +09:00
Construct URLSearchParams from sequence or from string
This commit is contained in:
parent
5755645f0d
commit
5fc488fe61
3 changed files with 24 additions and 43 deletions
|
|
@ -314,14 +314,6 @@ URLSearchParams::URLSearchParams(nsISupports* aParent,
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
URLSearchParams::URLSearchParams(nsISupports* aParent,
|
|
||||||
const URLSearchParams& aOther)
|
|
||||||
: mParams(new URLParams(*aOther.mParams.get()))
|
|
||||||
, mParent(aParent)
|
|
||||||
, mObserver(nullptr)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
URLSearchParams::~URLSearchParams()
|
URLSearchParams::~URLSearchParams()
|
||||||
{
|
{
|
||||||
DeleteAll();
|
DeleteAll();
|
||||||
|
|
@ -335,34 +327,37 @@ URLSearchParams::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
||||||
|
|
||||||
/* static */ already_AddRefed<URLSearchParams>
|
/* static */ already_AddRefed<URLSearchParams>
|
||||||
URLSearchParams::Constructor(const GlobalObject& aGlobal,
|
URLSearchParams::Constructor(const GlobalObject& aGlobal,
|
||||||
const nsAString& aInit,
|
const USVStringSequenceSequenceOrUSVString& aInit,
|
||||||
ErrorResult& aRv)
|
ErrorResult& aRv)
|
||||||
{
|
{
|
||||||
RefPtr<URLSearchParams> sp =
|
RefPtr<URLSearchParams> sp =
|
||||||
new URLSearchParams(aGlobal.GetAsSupports(), nullptr);
|
new URLSearchParams(aGlobal.GetAsSupports(), nullptr);
|
||||||
|
|
||||||
NS_ConvertUTF16toUTF8 input(aInit);
|
if (aInit.IsUSVString()) {
|
||||||
|
NS_ConvertUTF16toUTF8 input(aInit.GetAsUSVString());
|
||||||
if (StringBeginsWith(input, NS_LITERAL_CSTRING("?"))) {
|
if (StringBeginsWith(input, NS_LITERAL_CSTRING("?"))) {
|
||||||
sp->ParseInput(Substring(input, 1, input.Length() - 1));
|
sp->ParseInput(Substring(input, 1, input.Length() - 1));
|
||||||
|
} else {
|
||||||
|
sp->ParseInput(input);
|
||||||
|
}
|
||||||
|
} else if (aInit.IsUSVStringSequenceSequence()) {
|
||||||
|
const Sequence<Sequence<nsString>>& list =
|
||||||
|
aInit.GetAsUSVStringSequenceSequence();
|
||||||
|
for (uint32_t i = 0; i < list.Length(); ++i) {
|
||||||
|
const Sequence<nsString>& item = list[i];
|
||||||
|
if (item.Length() != 2) {
|
||||||
|
aRv.Throw(NS_ERROR_DOM_TYPE_ERR);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
sp->Append(item[0], item[1]);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
sp->ParseInput(input);
|
MOZ_CRASH("This should not happen.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return sp.forget();
|
return sp.forget();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */ already_AddRefed<URLSearchParams>
|
|
||||||
URLSearchParams::Constructor(const GlobalObject& aGlobal,
|
|
||||||
URLSearchParams& aInit,
|
|
||||||
ErrorResult& aRv)
|
|
||||||
{
|
|
||||||
RefPtr<URLSearchParams> sp =
|
|
||||||
new URLSearchParams(aGlobal.GetAsSupports(), aInit);
|
|
||||||
|
|
||||||
return sp.forget();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
URLSearchParams::ParseInput(const nsACString& aInput)
|
URLSearchParams::ParseInput(const nsACString& aInput)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ namespace mozilla {
|
||||||
namespace dom {
|
namespace dom {
|
||||||
|
|
||||||
class URLSearchParams;
|
class URLSearchParams;
|
||||||
|
class USVStringSequenceSequenceOrUSVString;
|
||||||
|
|
||||||
class URLSearchParamsObserver : public nsISupports
|
class URLSearchParamsObserver : public nsISupports
|
||||||
{
|
{
|
||||||
|
|
@ -43,14 +44,6 @@ public:
|
||||||
DeleteAll();
|
DeleteAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit URLParams(const URLParams& aOther)
|
|
||||||
: mParams(aOther.mParams)
|
|
||||||
{}
|
|
||||||
|
|
||||||
URLParams(const URLParams&& aOther)
|
|
||||||
: mParams(Move(aOther.mParams))
|
|
||||||
{}
|
|
||||||
|
|
||||||
class ForEachIterator
|
class ForEachIterator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
@ -144,9 +137,6 @@ public:
|
||||||
explicit URLSearchParams(nsISupports* aParent,
|
explicit URLSearchParams(nsISupports* aParent,
|
||||||
URLSearchParamsObserver* aObserver=nullptr);
|
URLSearchParamsObserver* aObserver=nullptr);
|
||||||
|
|
||||||
URLSearchParams(nsISupports* aParent,
|
|
||||||
const URLSearchParams& aOther);
|
|
||||||
|
|
||||||
// WebIDL methods
|
// WebIDL methods
|
||||||
nsISupports* GetParentObject() const
|
nsISupports* GetParentObject() const
|
||||||
{
|
{
|
||||||
|
|
@ -157,11 +147,8 @@ public:
|
||||||
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
||||||
|
|
||||||
static already_AddRefed<URLSearchParams>
|
static already_AddRefed<URLSearchParams>
|
||||||
Constructor(const GlobalObject& aGlobal, const nsAString& aInit,
|
Constructor(const GlobalObject& aGlobal,
|
||||||
ErrorResult& aRv);
|
const USVStringSequenceSequenceOrUSVString& aInit,
|
||||||
|
|
||||||
static already_AddRefed<URLSearchParams>
|
|
||||||
Constructor(const GlobalObject& aGlobal, URLSearchParams& aInit,
|
|
||||||
ErrorResult& aRv);
|
ErrorResult& aRv);
|
||||||
|
|
||||||
void ParseInput(const nsACString& aInput);
|
void ParseInput(const nsACString& aInput);
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,7 @@
|
||||||
* http://www.openwebfoundation.org/legal/the-owf-1-0-agreements/owfa-1-0.
|
* http://www.openwebfoundation.org/legal/the-owf-1-0-agreements/owfa-1-0.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
[Constructor(optional USVString init = ""),
|
[Constructor(optional (sequence<sequence<USVString>> or USVString) init = ""),
|
||||||
Constructor(URLSearchParams init),
|
|
||||||
Exposed=(Window,Worker,WorkerDebugger,System)]
|
Exposed=(Window,Worker,WorkerDebugger,System)]
|
||||||
interface URLSearchParams {
|
interface URLSearchParams {
|
||||||
void append(USVString name, USVString value);
|
void append(USVString name, USVString value);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue