mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 965990 - Allow URLSearchParams objects to be associated with multiple URLs, r=ehsan
This commit is contained in:
parent
19a755d4e4
commit
e104f14409
@ -217,9 +217,7 @@ void
|
||||
Link::SetSearch(const nsAString& aSearch)
|
||||
{
|
||||
SetSearchInternal(aSearch);
|
||||
if (mSearchParams) {
|
||||
mSearchParams->Invalidate();
|
||||
}
|
||||
UpdateURLSearchParams();
|
||||
}
|
||||
|
||||
void
|
||||
@ -487,9 +485,7 @@ Link::ResetLinkState(bool aNotify, bool aHasHref)
|
||||
|
||||
// If we've cached the URI, reset always invalidates it.
|
||||
mCachedURI = nullptr;
|
||||
if (mSearchParams) {
|
||||
mSearchParams->Invalidate();
|
||||
}
|
||||
UpdateURLSearchParams();
|
||||
|
||||
// Update our state back to the default.
|
||||
mLinkState = defaultState;
|
||||
@ -589,16 +585,13 @@ Link::SetSearchParams(URLSearchParams* aSearchParams)
|
||||
return;
|
||||
}
|
||||
|
||||
if (!aSearchParams->HasURLAssociated()) {
|
||||
MOZ_ASSERT(aSearchParams->IsValid());
|
||||
|
||||
mSearchParams = aSearchParams;
|
||||
mSearchParams->SetObserver(this);
|
||||
} else {
|
||||
CreateSearchParamsIfNeeded();
|
||||
mSearchParams->CopyFromURLSearchParams(*aSearchParams);
|
||||
if (mSearchParams) {
|
||||
mSearchParams->RemoveObserver(this);
|
||||
}
|
||||
|
||||
mSearchParams = aSearchParams;
|
||||
mSearchParams->AddObserver(this);
|
||||
|
||||
nsAutoString search;
|
||||
mSearchParams->Serialize(search);
|
||||
SetSearchInternal(search);
|
||||
@ -607,7 +600,7 @@ Link::SetSearchParams(URLSearchParams* aSearchParams)
|
||||
void
|
||||
Link::URLSearchParamsUpdated()
|
||||
{
|
||||
MOZ_ASSERT(mSearchParams && mSearchParams->IsValid());
|
||||
MOZ_ASSERT(mSearchParams);
|
||||
|
||||
nsString search;
|
||||
mSearchParams->Serialize(search);
|
||||
@ -615,9 +608,11 @@ Link::URLSearchParamsUpdated()
|
||||
}
|
||||
|
||||
void
|
||||
Link::URLSearchParamsNeedsUpdates()
|
||||
Link::UpdateURLSearchParams()
|
||||
{
|
||||
MOZ_ASSERT(mSearchParams);
|
||||
if (!mSearchParams) {
|
||||
return;
|
||||
}
|
||||
|
||||
nsAutoCString search;
|
||||
nsCOMPtr<nsIURI> uri(GetURI());
|
||||
@ -629,7 +624,7 @@ Link::URLSearchParamsNeedsUpdates()
|
||||
}
|
||||
}
|
||||
|
||||
mSearchParams->ParseInput(search);
|
||||
mSearchParams->ParseInput(search, this);
|
||||
}
|
||||
|
||||
void
|
||||
@ -637,15 +632,18 @@ Link::CreateSearchParamsIfNeeded()
|
||||
{
|
||||
if (!mSearchParams) {
|
||||
mSearchParams = new URLSearchParams();
|
||||
mSearchParams->SetObserver(this);
|
||||
mSearchParams->Invalidate();
|
||||
mSearchParams->AddObserver(this);
|
||||
UpdateURLSearchParams();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Link::Unlink()
|
||||
{
|
||||
mSearchParams = nullptr;
|
||||
if (mSearchParams) {
|
||||
mSearchParams->RemoveObserver(this);
|
||||
mSearchParams = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -114,7 +114,6 @@ public:
|
||||
|
||||
// URLSearchParamsObserver
|
||||
void URLSearchParamsUpdated() MOZ_OVERRIDE;
|
||||
void URLSearchParamsNeedsUpdates() MOZ_OVERRIDE;
|
||||
|
||||
protected:
|
||||
virtual ~Link();
|
||||
@ -134,6 +133,8 @@ protected:
|
||||
nsIURI* GetCachedURI() const { return mCachedURI; }
|
||||
bool HasCachedURI() const { return !!mCachedURI; }
|
||||
|
||||
void UpdateURLSearchParams();
|
||||
|
||||
// CC methods
|
||||
void Unlink();
|
||||
void Traverse(nsCycleCollectionTraversalCallback &cb);
|
||||
|
@ -20,7 +20,18 @@
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_1(URL, mSearchParams)
|
||||
NS_IMPL_CYCLE_COLLECTION_CLASS(URL)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(URL)
|
||||
if (tmp->mSearchParams) {
|
||||
tmp->mSearchParams->RemoveObserver(tmp);
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mSearchParams)
|
||||
}
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(URL)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSearchParams)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(URL)
|
||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(URL)
|
||||
@ -221,10 +232,7 @@ URL::SetHref(const nsAString& aHref, ErrorResult& aRv)
|
||||
}
|
||||
|
||||
aRv = mURI->SetSpec(href);
|
||||
|
||||
if (mSearchParams) {
|
||||
mSearchParams->Invalidate();
|
||||
}
|
||||
UpdateURLSearchParams();
|
||||
}
|
||||
|
||||
void
|
||||
@ -304,7 +312,7 @@ URL::SetHost(const nsAString& aHost)
|
||||
void
|
||||
URL::URLSearchParamsUpdated()
|
||||
{
|
||||
MOZ_ASSERT(mSearchParams && mSearchParams->IsValid());
|
||||
MOZ_ASSERT(mSearchParams);
|
||||
|
||||
nsAutoString search;
|
||||
mSearchParams->Serialize(search);
|
||||
@ -312,9 +320,11 @@ URL::URLSearchParamsUpdated()
|
||||
}
|
||||
|
||||
void
|
||||
URL::URLSearchParamsNeedsUpdates()
|
||||
URL::UpdateURLSearchParams()
|
||||
{
|
||||
MOZ_ASSERT(mSearchParams);
|
||||
if (!mSearchParams) {
|
||||
return;
|
||||
}
|
||||
|
||||
nsAutoCString search;
|
||||
nsCOMPtr<nsIURL> url(do_QueryInterface(mURI));
|
||||
@ -325,7 +335,7 @@ URL::URLSearchParamsNeedsUpdates()
|
||||
}
|
||||
}
|
||||
|
||||
mSearchParams->ParseInput(search);
|
||||
mSearchParams->ParseInput(search, this);
|
||||
}
|
||||
|
||||
void
|
||||
@ -426,10 +436,7 @@ void
|
||||
URL::SetSearch(const nsAString& aSearch)
|
||||
{
|
||||
SetSearchInternal(aSearch);
|
||||
|
||||
if (mSearchParams) {
|
||||
mSearchParams->Invalidate();
|
||||
}
|
||||
UpdateURLSearchParams();
|
||||
}
|
||||
|
||||
void
|
||||
@ -458,16 +465,14 @@ URL::SetSearchParams(URLSearchParams* aSearchParams)
|
||||
return;
|
||||
}
|
||||
|
||||
if (!aSearchParams->HasURLAssociated()) {
|
||||
MOZ_ASSERT(aSearchParams->IsValid());
|
||||
|
||||
mSearchParams = aSearchParams;
|
||||
mSearchParams->SetObserver(this);
|
||||
} else {
|
||||
CreateSearchParamsIfNeeded();
|
||||
mSearchParams->CopyFromURLSearchParams(*aSearchParams);
|
||||
if (mSearchParams) {
|
||||
mSearchParams->RemoveObserver(this);
|
||||
}
|
||||
|
||||
// the observer will be cleared using the cycle collector.
|
||||
mSearchParams = aSearchParams;
|
||||
mSearchParams->AddObserver(this);
|
||||
|
||||
nsAutoString search;
|
||||
mSearchParams->Serialize(search);
|
||||
SetSearchInternal(search);
|
||||
@ -506,8 +511,8 @@ URL::CreateSearchParamsIfNeeded()
|
||||
{
|
||||
if (!mSearchParams) {
|
||||
mSearchParams = new URLSearchParams();
|
||||
mSearchParams->SetObserver(this);
|
||||
mSearchParams->Invalidate();
|
||||
mSearchParams->AddObserver(this);
|
||||
UpdateURLSearchParams();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -125,7 +125,6 @@ public:
|
||||
|
||||
// URLSearchParamsObserver
|
||||
void URLSearchParamsUpdated() MOZ_OVERRIDE;
|
||||
void URLSearchParamsNeedsUpdates() MOZ_OVERRIDE;
|
||||
|
||||
private:
|
||||
nsIURI* GetURI() const
|
||||
@ -137,6 +136,8 @@ private:
|
||||
|
||||
void SetSearchInternal(const nsAString& aSearch);
|
||||
|
||||
void UpdateURLSearchParams();
|
||||
|
||||
static void CreateObjectURLInternal(const GlobalObject& aGlobal,
|
||||
nsISupports* aObject,
|
||||
const nsACString& aScheme,
|
||||
|
@ -9,7 +9,7 @@
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(URLSearchParams, mObserver)
|
||||
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(URLSearchParams, mObservers)
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(URLSearchParams)
|
||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(URLSearchParams)
|
||||
|
||||
@ -19,7 +19,6 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(URLSearchParams)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
URLSearchParams::URLSearchParams()
|
||||
: mValid(false)
|
||||
{
|
||||
SetIsDOMBinding();
|
||||
}
|
||||
@ -41,7 +40,7 @@ URLSearchParams::Constructor(const GlobalObject& aGlobal,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
nsRefPtr<URLSearchParams> sp = new URLSearchParams();
|
||||
sp->ParseInput(NS_ConvertUTF16toUTF8(aInit));
|
||||
sp->ParseInput(NS_ConvertUTF16toUTF8(aInit), nullptr);
|
||||
return sp.forget();
|
||||
}
|
||||
|
||||
@ -52,12 +51,12 @@ URLSearchParams::Constructor(const GlobalObject& aGlobal,
|
||||
{
|
||||
nsRefPtr<URLSearchParams> sp = new URLSearchParams();
|
||||
aInit.mSearchParams.EnumerateRead(CopyEnumerator, sp);
|
||||
sp->mValid = true;
|
||||
return sp.forget();
|
||||
}
|
||||
|
||||
void
|
||||
URLSearchParams::ParseInput(const nsACString& aInput)
|
||||
URLSearchParams::ParseInput(const nsACString& aInput,
|
||||
URLSearchParamsObserver* aObserver)
|
||||
{
|
||||
// Remove all the existing data before parsing a new input.
|
||||
DeleteAll();
|
||||
@ -109,7 +108,7 @@ URLSearchParams::ParseInput(const nsACString& aInput)
|
||||
NS_ConvertUTF8toUTF16(decodedValue));
|
||||
}
|
||||
|
||||
mValid = true;
|
||||
NotifyObservers(aObserver);
|
||||
}
|
||||
|
||||
void
|
||||
@ -165,18 +164,6 @@ URLSearchParams::DecodeString(const nsACString& aInput, nsACString& aOutput)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
URLSearchParams::CopyFromURLSearchParams(URLSearchParams& aSearchParams)
|
||||
{
|
||||
// The other SearchParams must be valid before copying its data.
|
||||
aSearchParams.Validate();
|
||||
|
||||
// Remove all the existing data before parsing a new input.
|
||||
DeleteAll();
|
||||
aSearchParams.mSearchParams.EnumerateRead(CopyEnumerator, this);
|
||||
mValid = true;
|
||||
}
|
||||
|
||||
/* static */ PLDHashOperator
|
||||
URLSearchParams::CopyEnumerator(const nsAString& aName,
|
||||
nsTArray<nsString>* aArray,
|
||||
@ -192,27 +179,23 @@ URLSearchParams::CopyEnumerator(const nsAString& aName,
|
||||
}
|
||||
|
||||
void
|
||||
URLSearchParams::SetObserver(URLSearchParamsObserver* aObserver)
|
||||
URLSearchParams::AddObserver(URLSearchParamsObserver* aObserver)
|
||||
{
|
||||
MOZ_ASSERT(!mObserver);
|
||||
mObserver = aObserver;
|
||||
MOZ_ASSERT(aObserver);
|
||||
MOZ_ASSERT(!mObservers.Contains(aObserver));
|
||||
mObservers.AppendElement(aObserver);
|
||||
}
|
||||
|
||||
void
|
||||
URLSearchParams::Validate()
|
||||
URLSearchParams::RemoveObserver(URLSearchParamsObserver* aObserver)
|
||||
{
|
||||
MOZ_ASSERT(mValid || mObserver);
|
||||
if (!mValid) {
|
||||
mObserver->URLSearchParamsNeedsUpdates();
|
||||
MOZ_ASSERT(mValid);
|
||||
}
|
||||
MOZ_ASSERT(aObserver);
|
||||
mObservers.RemoveElement(aObserver);
|
||||
}
|
||||
|
||||
void
|
||||
URLSearchParams::Get(const nsAString& aName, nsString& aRetval)
|
||||
{
|
||||
Validate();
|
||||
|
||||
nsTArray<nsString>* array;
|
||||
if (!mSearchParams.Get(aName, &array)) {
|
||||
aRetval.Truncate();
|
||||
@ -225,8 +208,6 @@ URLSearchParams::Get(const nsAString& aName, nsString& aRetval)
|
||||
void
|
||||
URLSearchParams::GetAll(const nsAString& aName, nsTArray<nsString>& aRetval)
|
||||
{
|
||||
Validate();
|
||||
|
||||
nsTArray<nsString>* array;
|
||||
if (!mSearchParams.Get(aName, &array)) {
|
||||
return;
|
||||
@ -238,10 +219,6 @@ URLSearchParams::GetAll(const nsAString& aName, nsTArray<nsString>& aRetval)
|
||||
void
|
||||
URLSearchParams::Set(const nsAString& aName, const nsAString& aValue)
|
||||
{
|
||||
// Before setting any new value we have to be sure to have all the previous
|
||||
// values in place.
|
||||
Validate();
|
||||
|
||||
nsTArray<nsString>* array;
|
||||
if (!mSearchParams.Get(aName, &array)) {
|
||||
array = new nsTArray<nsString>();
|
||||
@ -251,18 +228,14 @@ URLSearchParams::Set(const nsAString& aName, const nsAString& aValue)
|
||||
array->ElementAt(0) = aValue;
|
||||
}
|
||||
|
||||
NotifyObserver();
|
||||
NotifyObservers(nullptr);
|
||||
}
|
||||
|
||||
void
|
||||
URLSearchParams::Append(const nsAString& aName, const nsAString& aValue)
|
||||
{
|
||||
// Before setting any new value we have to be sure to have all the previous
|
||||
// values in place.
|
||||
Validate();
|
||||
|
||||
AppendInternal(aName, aValue);
|
||||
NotifyObserver();
|
||||
NotifyObservers(nullptr);
|
||||
}
|
||||
|
||||
void
|
||||
@ -280,17 +253,12 @@ URLSearchParams::AppendInternal(const nsAString& aName, const nsAString& aValue)
|
||||
bool
|
||||
URLSearchParams::Has(const nsAString& aName)
|
||||
{
|
||||
Validate();
|
||||
return mSearchParams.Get(aName, nullptr);
|
||||
}
|
||||
|
||||
void
|
||||
URLSearchParams::Delete(const nsAString& aName)
|
||||
{
|
||||
// Before deleting any value we have to be sure to have all the previous
|
||||
// values in place.
|
||||
Validate();
|
||||
|
||||
nsTArray<nsString>* array;
|
||||
if (!mSearchParams.Get(aName, &array)) {
|
||||
return;
|
||||
@ -298,7 +266,7 @@ URLSearchParams::Delete(const nsAString& aName)
|
||||
|
||||
mSearchParams.Remove(aName);
|
||||
|
||||
NotifyObserver();
|
||||
NotifyObservers(nullptr);
|
||||
}
|
||||
|
||||
void
|
||||
@ -343,8 +311,6 @@ public:
|
||||
void
|
||||
URLSearchParams::Serialize(nsAString& aValue) const
|
||||
{
|
||||
MOZ_ASSERT(mValid);
|
||||
|
||||
SerializeData data;
|
||||
mSearchParams.EnumerateRead(SerializeEnumerator, &data);
|
||||
aValue.Assign(data.mValue);
|
||||
@ -373,18 +339,14 @@ URLSearchParams::SerializeEnumerator(const nsAString& aName,
|
||||
}
|
||||
|
||||
void
|
||||
URLSearchParams::NotifyObserver()
|
||||
URLSearchParams::NotifyObservers(URLSearchParamsObserver* aExceptObserver)
|
||||
{
|
||||
if (mObserver) {
|
||||
mObserver->URLSearchParamsUpdated();
|
||||
for (uint32_t i = 0; i < mObservers.Length(); ++i) {
|
||||
if (mObservers[i] != aExceptObserver) {
|
||||
mObservers[i]->URLSearchParamsUpdated();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
URLSearchParams::Invalidate()
|
||||
{
|
||||
mValid = false;
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
@ -23,7 +23,6 @@ public:
|
||||
virtual ~URLSearchParamsObserver() {}
|
||||
|
||||
virtual void URLSearchParamsUpdated() = 0;
|
||||
virtual void URLSearchParamsNeedsUpdates() = 0;
|
||||
};
|
||||
|
||||
class URLSearchParams MOZ_FINAL : public nsISupports,
|
||||
@ -36,11 +35,6 @@ public:
|
||||
URLSearchParams();
|
||||
~URLSearchParams();
|
||||
|
||||
bool HasURLAssociated() const
|
||||
{
|
||||
return !!mObserver;
|
||||
}
|
||||
|
||||
// WebIDL methods
|
||||
nsISupports* GetParentObject() const
|
||||
{
|
||||
@ -58,18 +52,11 @@ public:
|
||||
Constructor(const GlobalObject& aGlobal, URLSearchParams& aInit,
|
||||
ErrorResult& aRv);
|
||||
|
||||
void ParseInput(const nsACString& aInput);
|
||||
void ParseInput(const nsACString& aInput,
|
||||
URLSearchParamsObserver* aObserver);
|
||||
|
||||
void CopyFromURLSearchParams(URLSearchParams& aSearchParams);
|
||||
|
||||
void SetObserver(URLSearchParamsObserver* aObserver);
|
||||
|
||||
void Invalidate();
|
||||
|
||||
bool IsValid() const
|
||||
{
|
||||
return mValid;
|
||||
}
|
||||
void AddObserver(URLSearchParamsObserver* aObserver);
|
||||
void RemoveObserver(URLSearchParamsObserver* aObserver);
|
||||
|
||||
void Serialize(nsAString& aValue) const;
|
||||
|
||||
@ -87,7 +74,6 @@ public:
|
||||
|
||||
void Stringify(nsString& aRetval)
|
||||
{
|
||||
Validate();
|
||||
Serialize(aRetval);
|
||||
}
|
||||
|
||||
@ -98,7 +84,7 @@ private:
|
||||
|
||||
void DecodeString(const nsACString& aInput, nsACString& aOutput);
|
||||
|
||||
void NotifyObserver();
|
||||
void NotifyObservers(URLSearchParamsObserver* aExceptObserver);
|
||||
|
||||
static PLDHashOperator
|
||||
CopyEnumerator(const nsAString& aName, nsTArray<nsString>* aArray,
|
||||
@ -108,14 +94,9 @@ private:
|
||||
SerializeEnumerator(const nsAString& aName, nsTArray<nsString>* aArray,
|
||||
void *userData);
|
||||
|
||||
void
|
||||
Validate();
|
||||
|
||||
nsClassHashtable<nsStringHashKey, nsTArray<nsString>> mSearchParams;
|
||||
|
||||
nsRefPtr<URLSearchParamsObserver> mObserver;
|
||||
|
||||
bool mValid;
|
||||
nsTArray<nsRefPtr<URLSearchParamsObserver>> mObservers;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
|
@ -137,7 +137,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=887836
|
||||
|
||||
var url2 = new URL('http://www.example.net?e=f');
|
||||
url.searchParams = url2.searchParams;
|
||||
isnot(url.searchParams, url2.searchParams, "URL.searchParams is not the same object");
|
||||
is(url.searchParams, url2.searchParams, "URL.searchParams is not the same object");
|
||||
is(url.searchParams.get('e'), 'f', "URL.searchParams.get('e')");
|
||||
|
||||
url.href = "http://www.example.net?bar=foo";
|
||||
@ -170,7 +170,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=887836
|
||||
|
||||
var url2 = new URL('http://www.example.net?e=f');
|
||||
e.searchParams = url2.searchParams;
|
||||
isnot(e.searchParams, url2.searchParams, "e.searchParams is not the same object");
|
||||
is(e.searchParams, url2.searchParams, "e.searchParams is not the same object");
|
||||
is(e.searchParams.get('e'), 'f', "e.searchParams.get('e')");
|
||||
|
||||
e.href = "http://www.example.net?bar=foo";
|
||||
@ -203,6 +203,45 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=887836
|
||||
runTest();
|
||||
}
|
||||
|
||||
function testMultiURL() {
|
||||
var a = new URL('http://www.example.net?a=b&c=d');
|
||||
var b = new URL('http://www.example.net?e=f');
|
||||
var c = document.createElement('a');
|
||||
var d = document.createElement('area');
|
||||
ok(a.searchParams.has('a'), "a.searchParams.has('a')");
|
||||
ok(a.searchParams.has('c'), "a.searchParams.has('c')");
|
||||
ok(b.searchParams.has('e'), "b.searchParams.has('e')");
|
||||
ok(c.searchParams, "c.searchParams");
|
||||
ok(d.searchParams, "d.searchParams");
|
||||
|
||||
var u = new URLSearchParams();
|
||||
a.searchParams = b.searchParams = c.searchParams = d.searchParams = u;
|
||||
is(a.searchParams, u, "a.searchParams === u");
|
||||
is(b.searchParams, u, "b.searchParams === u");
|
||||
is(c.searchParams, u, "c.searchParams === u");
|
||||
is(d.searchParams, u, "d.searchParams === u");
|
||||
ok(!a.searchParams.has('a'), "!a.searchParams.has('a')");
|
||||
ok(!a.searchParams.has('c'), "!a.searchParams.has('c')");
|
||||
ok(!b.searchParams.has('e'), "!b.searchParams.has('e')");
|
||||
|
||||
u.append('foo', 'bar');
|
||||
is(a.searchParams.get('foo'), 'bar', "a has foo=bar");
|
||||
is(b.searchParams.get('foo'), 'bar', "b has foo=bar");
|
||||
is(c.searchParams.get('foo'), 'bar', "c has foo=bar");
|
||||
is(d.searchParams.get('foo'), 'bar', "d has foo=bar");
|
||||
is(a + "", b + "", "stringify a == b");
|
||||
is(c.searchParams + "", b.searchParams + "", "stringify c.searchParams == b.searchParams");
|
||||
is(d.searchParams + "", b.searchParams + "", "stringify d.searchParams == b.searchParams");
|
||||
|
||||
a.search = "?bar=foo";
|
||||
is(a.searchParams.get('bar'), 'foo', "a has bar=foo");
|
||||
is(b.searchParams.get('bar'), 'foo', "b has bar=foo");
|
||||
is(c.searchParams.get('bar'), 'foo', "c has bar=foo");
|
||||
is(d.searchParams.get('bar'), 'foo', "d has bar=foo");
|
||||
|
||||
runTest();
|
||||
}
|
||||
|
||||
var tests = [
|
||||
testSimpleURLSearchParams,
|
||||
testCopyURLSearchParams,
|
||||
@ -210,7 +249,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=887836
|
||||
testURL,
|
||||
function() { testElement(document.getElementById('anchor')) },
|
||||
function() { testElement(document.getElementById('area')) },
|
||||
testEncoding
|
||||
testEncoding,
|
||||
testMultiURL
|
||||
];
|
||||
|
||||
function runTest() {
|
||||
|
@ -615,9 +615,7 @@ URL::SetHref(const nsAString& aHref, ErrorResult& aRv)
|
||||
JS_ReportPendingException(mWorkerPrivate->GetJSContext());
|
||||
}
|
||||
|
||||
if (mSearchParams) {
|
||||
mSearchParams->Invalidate();
|
||||
}
|
||||
UpdateURLSearchParams();
|
||||
}
|
||||
|
||||
void
|
||||
@ -823,10 +821,7 @@ void
|
||||
URL::SetSearch(const nsAString& aSearch)
|
||||
{
|
||||
SetSearchInternal(aSearch);
|
||||
|
||||
if (mSearchParams) {
|
||||
mSearchParams->Invalidate();
|
||||
}
|
||||
UpdateURLSearchParams();
|
||||
}
|
||||
|
||||
void
|
||||
@ -856,16 +851,12 @@ URL::SetSearchParams(URLSearchParams* aSearchParams)
|
||||
return;
|
||||
}
|
||||
|
||||
if (!aSearchParams->HasURLAssociated()) {
|
||||
MOZ_ASSERT(aSearchParams->IsValid());
|
||||
|
||||
mSearchParams = aSearchParams;
|
||||
mSearchParams->SetObserver(this);
|
||||
} else {
|
||||
CreateSearchParamsIfNeeded();
|
||||
mSearchParams->CopyFromURLSearchParams(*aSearchParams);
|
||||
if (mSearchParams) {
|
||||
mSearchParams->RemoveObserver(this);
|
||||
}
|
||||
|
||||
mSearchParams = aSearchParams;
|
||||
mSearchParams->AddObserver(this);
|
||||
|
||||
nsString search;
|
||||
mSearchParams->Serialize(search);
|
||||
@ -951,7 +942,7 @@ URL::RevokeObjectURL(const GlobalObject& aGlobal, const nsAString& aUrl)
|
||||
void
|
||||
URL::URLSearchParamsUpdated()
|
||||
{
|
||||
MOZ_ASSERT(mSearchParams && mSearchParams->IsValid());
|
||||
MOZ_ASSERT(mSearchParams);
|
||||
|
||||
nsString search;
|
||||
mSearchParams->Serialize(search);
|
||||
@ -959,13 +950,13 @@ URL::URLSearchParamsUpdated()
|
||||
}
|
||||
|
||||
void
|
||||
URL::URLSearchParamsNeedsUpdates()
|
||||
URL::UpdateURLSearchParams()
|
||||
{
|
||||
MOZ_ASSERT(mSearchParams);
|
||||
|
||||
nsString search;
|
||||
GetSearch(search);
|
||||
mSearchParams->ParseInput(NS_ConvertUTF16toUTF8(Substring(search, 1)));
|
||||
if (mSearchParams) {
|
||||
nsString search;
|
||||
GetSearch(search);
|
||||
mSearchParams->ParseInput(NS_ConvertUTF16toUTF8(Substring(search, 1)), this);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@ -973,8 +964,8 @@ URL::CreateSearchParamsIfNeeded()
|
||||
{
|
||||
if (!mSearchParams) {
|
||||
mSearchParams = new URLSearchParams();
|
||||
mSearchParams->SetObserver(this);
|
||||
mSearchParams->Invalidate();
|
||||
mSearchParams->AddObserver(this);
|
||||
UpdateURLSearchParams();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -119,7 +119,6 @@ public:
|
||||
|
||||
// IURLSearchParamsObserver
|
||||
void URLSearchParamsUpdated() MOZ_OVERRIDE;
|
||||
void URLSearchParamsNeedsUpdates() MOZ_OVERRIDE;
|
||||
|
||||
private:
|
||||
URLProxy* GetURLProxy() const
|
||||
@ -131,6 +130,8 @@ private:
|
||||
|
||||
void SetSearchInternal(const nsAString& aSearch);
|
||||
|
||||
void UpdateURLSearchParams();
|
||||
|
||||
WorkerPrivate* mWorkerPrivate;
|
||||
nsRefPtr<URLProxy> mURLProxy;
|
||||
nsRefPtr<URLSearchParams> mSearchParams;
|
||||
|
@ -8,11 +8,6 @@ function is(a, b, msg) {
|
||||
postMessage({type: 'status', status: a === b, msg: a + " === " + b + ": " + msg });
|
||||
}
|
||||
|
||||
function isnot(a, b, msg) {
|
||||
dump("ISNOT: " + (a!==b) + " => " + a + " | " + b + " " + msg + "\n");
|
||||
postMessage({type: 'status', status: a !== b, msg: a + " !== " + b + ": " + msg });
|
||||
}
|
||||
|
||||
onmessage = function() {
|
||||
status = false;
|
||||
try {
|
||||
@ -134,7 +129,7 @@ onmessage = function() {
|
||||
|
||||
var url2 = new URL('http://www.example.net?e=f');
|
||||
url.searchParams = url2.searchParams;
|
||||
isnot(url.searchParams, url2.searchParams, "URL.searchParams is not the same object");
|
||||
is(url.searchParams, url2.searchParams, "URL.searchParams is not the same object");
|
||||
is(url.searchParams.get('e'), 'f', "URL.searchParams.get('e')");
|
||||
|
||||
url.href = "http://www.example.net?bar=foo";
|
||||
@ -164,12 +159,39 @@ onmessage = function() {
|
||||
runTest();
|
||||
}
|
||||
|
||||
function testMultiURL() {
|
||||
var a = new URL('http://www.example.net?a=b&c=d');
|
||||
var b = new URL('http://www.example.net?e=f');
|
||||
ok(a.searchParams.has('a'), "a.searchParams.has('a')");
|
||||
ok(a.searchParams.has('c'), "a.searchParams.has('c')");
|
||||
ok(b.searchParams.has('e'), "b.searchParams.has('e')");
|
||||
|
||||
var u = new URLSearchParams();
|
||||
a.searchParams = b.searchParams = u;
|
||||
is(a.searchParams, u, "a.searchParams === u");
|
||||
is(b.searchParams, u, "b.searchParams === u");
|
||||
ok(!a.searchParams.has('a'), "!a.searchParams.has('a')");
|
||||
ok(!a.searchParams.has('c'), "!a.searchParams.has('c')");
|
||||
ok(!b.searchParams.has('e'), "!b.searchParams.has('e')");
|
||||
|
||||
u.append('foo', 'bar');
|
||||
is(a.searchParams.get('foo'), 'bar', "a has foo=bar");
|
||||
is(b.searchParams.get('foo'), 'bar', "b has foo=bar");
|
||||
is(a + "", b + "", "stringify a == b");
|
||||
|
||||
a.search = "?bar=foo";
|
||||
is(a.searchParams.get('bar'), 'foo', "a has bar=foo");
|
||||
is(b.searchParams.get('bar'), 'foo', "b has bar=foo");
|
||||
|
||||
runTest();
|
||||
}
|
||||
var tests = [
|
||||
testSimpleURLSearchParams,
|
||||
testCopyURLSearchParams,
|
||||
testParserURLSearchParams,
|
||||
testURL,
|
||||
testEncoding
|
||||
testEncoding,
|
||||
testMultiURL
|
||||
];
|
||||
|
||||
function runTest() {
|
||||
|
@ -123,9 +123,9 @@ Link::URLSearchParamsUpdated()
|
||||
}
|
||||
|
||||
void
|
||||
Link::URLSearchParamsNeedsUpdates()
|
||||
Link::UpdateURLSearchParams()
|
||||
{
|
||||
NS_NOTREACHED("Unexpected call to Link::URLSearchParamsNeedsUpdates");
|
||||
NS_NOTREACHED("Unexpected call to Link::UpdateURLSearchParams");
|
||||
}
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_CLASS(URLSearchParams)
|
||||
@ -159,19 +159,20 @@ URLSearchParams::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
|
||||
}
|
||||
|
||||
void
|
||||
URLSearchParams::ParseInput(const nsACString& aInput)
|
||||
URLSearchParams::ParseInput(const nsACString& aInput,
|
||||
URLSearchParamsObserver* aObserver)
|
||||
{
|
||||
NS_NOTREACHED("Unexpected call to URLSearchParams::ParseInput");
|
||||
}
|
||||
|
||||
void
|
||||
URLSearchParams::CopyFromURLSearchParams(URLSearchParams& aSearchParams)
|
||||
URLSearchParams::AddObserver(URLSearchParamsObserver* aObserver)
|
||||
{
|
||||
NS_NOTREACHED("Unexpected call to URLSearchParams::CopyFromURLSearchParams");
|
||||
NS_NOTREACHED("Unexpected call to URLSearchParams::SetObserver");
|
||||
}
|
||||
|
||||
void
|
||||
URLSearchParams::SetObserver(URLSearchParamsObserver* aObserver)
|
||||
URLSearchParams::RemoveObserver(URLSearchParamsObserver* aObserver)
|
||||
{
|
||||
NS_NOTREACHED("Unexpected call to URLSearchParams::SetObserver");
|
||||
}
|
||||
@ -232,18 +233,11 @@ URLSearchParams::DeleteAll()
|
||||
}
|
||||
|
||||
void
|
||||
URLSearchParams::NotifyObserver()
|
||||
URLSearchParams::NotifyObservers(URLSearchParamsObserver* aExceptObserver)
|
||||
{
|
||||
NS_NOTREACHED("Unexpected call to URLSearchParams::NotifyObserver");
|
||||
NS_NOTREACHED("Unexpected call to URLSearchParams::NotifyObservers");
|
||||
}
|
||||
|
||||
void
|
||||
URLSearchParams::Invalidate()
|
||||
{
|
||||
NS_NOTREACHED("Unexpected call to URLSearchParams::Invalidate");
|
||||
}
|
||||
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user