summaryrefslogtreecommitdiffstats
path: root/dom/url/URLSearchParams.cpp
diff options
context:
space:
mode:
authorJustOff <Off.Just.Off@gmail.com>2019-03-13 21:20:12 +0200
committerJustOff <Off.Just.Off@gmail.com>2019-03-13 21:20:12 +0200
commit04c16841227708a6037acb14ba506f0981481e37 (patch)
treed5476f69595a047801191506c46aa9bb81e8ae65 /dom/url/URLSearchParams.cpp
parentca23830127a2123100e52e644302e23143d8369a (diff)
downloadUXP-04c16841227708a6037acb14ba506f0981481e37.tar
UXP-04c16841227708a6037acb14ba506f0981481e37.tar.gz
UXP-04c16841227708a6037acb14ba506f0981481e37.tar.lz
UXP-04c16841227708a6037acb14ba506f0981481e37.tar.xz
UXP-04c16841227708a6037acb14ba506f0981481e37.zip
Construct URLSearchParams from sequence or from string
Diffstat (limited to 'dom/url/URLSearchParams.cpp')
-rw-r--r--dom/url/URLSearchParams.cpp45
1 files changed, 20 insertions, 25 deletions
diff --git a/dom/url/URLSearchParams.cpp b/dom/url/URLSearchParams.cpp
index d9492f81c..8303272e1 100644
--- a/dom/url/URLSearchParams.cpp
+++ b/dom/url/URLSearchParams.cpp
@@ -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()
{
DeleteAll();
@@ -335,34 +327,37 @@ URLSearchParams::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
/* static */ already_AddRefed<URLSearchParams>
URLSearchParams::Constructor(const GlobalObject& aGlobal,
- const nsAString& aInit,
+ const USVStringSequenceSequenceOrUSVString& aInit,
ErrorResult& aRv)
{
RefPtr<URLSearchParams> sp =
new URLSearchParams(aGlobal.GetAsSupports(), nullptr);
- NS_ConvertUTF16toUTF8 input(aInit);
-
- if (StringBeginsWith(input, NS_LITERAL_CSTRING("?"))) {
- sp->ParseInput(Substring(input, 1, input.Length() - 1));
+ if (aInit.IsUSVString()) {
+ NS_ConvertUTF16toUTF8 input(aInit.GetAsUSVString());
+ if (StringBeginsWith(input, NS_LITERAL_CSTRING("?"))) {
+ 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 {
- sp->ParseInput(input);
+ MOZ_CRASH("This should not happen.");
}
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
URLSearchParams::ParseInput(const nsACString& aInput)
{