mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Backed out changeset 2d021370c57f (bug 965990) for causing bug 973307.
This commit is contained in:
parent
1b9fd6371f
commit
f1a55855c0
@ -217,7 +217,9 @@ void
|
||||
Link::SetSearch(const nsAString& aSearch)
|
||||
{
|
||||
SetSearchInternal(aSearch);
|
||||
UpdateURLSearchParams();
|
||||
if (mSearchParams) {
|
||||
mSearchParams->Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@ -485,7 +487,9 @@ Link::ResetLinkState(bool aNotify, bool aHasHref)
|
||||
|
||||
// If we've cached the URI, reset always invalidates it.
|
||||
mCachedURI = nullptr;
|
||||
UpdateURLSearchParams();
|
||||
if (mSearchParams) {
|
||||
mSearchParams->Invalidate();
|
||||
}
|
||||
|
||||
// Update our state back to the default.
|
||||
mLinkState = defaultState;
|
||||
@ -585,12 +589,15 @@ Link::SetSearchParams(URLSearchParams* aSearchParams)
|
||||
return;
|
||||
}
|
||||
|
||||
if (mSearchParams) {
|
||||
mSearchParams->RemoveObserver(this);
|
||||
}
|
||||
if (!aSearchParams->HasURLAssociated()) {
|
||||
MOZ_ASSERT(aSearchParams->IsValid());
|
||||
|
||||
mSearchParams = aSearchParams;
|
||||
mSearchParams->AddObserver(this);
|
||||
mSearchParams = aSearchParams;
|
||||
mSearchParams->SetObserver(this);
|
||||
} else {
|
||||
CreateSearchParamsIfNeeded();
|
||||
mSearchParams->CopyFromURLSearchParams(*aSearchParams);
|
||||
}
|
||||
|
||||
nsAutoString search;
|
||||
mSearchParams->Serialize(search);
|
||||
@ -600,7 +607,7 @@ Link::SetSearchParams(URLSearchParams* aSearchParams)
|
||||
void
|
||||
Link::URLSearchParamsUpdated()
|
||||
{
|
||||
MOZ_ASSERT(mSearchParams);
|
||||
MOZ_ASSERT(mSearchParams && mSearchParams->IsValid());
|
||||
|
||||
nsString search;
|
||||
mSearchParams->Serialize(search);
|
||||
@ -608,11 +615,9 @@ Link::URLSearchParamsUpdated()
|
||||
}
|
||||
|
||||
void
|
||||
Link::UpdateURLSearchParams()
|
||||
Link::URLSearchParamsNeedsUpdates()
|
||||
{
|
||||
if (!mSearchParams) {
|
||||
return;
|
||||
}
|
||||
MOZ_ASSERT(mSearchParams);
|
||||
|
||||
nsAutoCString search;
|
||||
nsCOMPtr<nsIURI> uri(GetURI());
|
||||
@ -624,7 +629,7 @@ Link::UpdateURLSearchParams()
|
||||
}
|
||||
}
|
||||
|
||||
mSearchParams->ParseInput(search, this);
|
||||
mSearchParams->ParseInput(search);
|
||||
}
|
||||
|
||||
void
|
||||
@ -632,8 +637,8 @@ Link::CreateSearchParamsIfNeeded()
|
||||
{
|
||||
if (!mSearchParams) {
|
||||
mSearchParams = new URLSearchParams();
|
||||
mSearchParams->AddObserver(this);
|
||||
UpdateURLSearchParams();
|
||||
mSearchParams->SetObserver(this);
|
||||
mSearchParams->Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -114,6 +114,7 @@ public:
|
||||
|
||||
// URLSearchParamsObserver
|
||||
void URLSearchParamsUpdated() MOZ_OVERRIDE;
|
||||
void URLSearchParamsNeedsUpdates() MOZ_OVERRIDE;
|
||||
|
||||
protected:
|
||||
virtual ~Link();
|
||||
@ -133,8 +134,6 @@ protected:
|
||||
nsIURI* GetCachedURI() const { return mCachedURI; }
|
||||
bool HasCachedURI() const { return !!mCachedURI; }
|
||||
|
||||
void UpdateURLSearchParams();
|
||||
|
||||
// CC methods
|
||||
void Unlink();
|
||||
void Traverse(nsCycleCollectionTraversalCallback &cb);
|
||||
|
@ -221,7 +221,10 @@ URL::SetHref(const nsAString& aHref, ErrorResult& aRv)
|
||||
}
|
||||
|
||||
aRv = mURI->SetSpec(href);
|
||||
UpdateURLSearchParams();
|
||||
|
||||
if (mSearchParams) {
|
||||
mSearchParams->Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@ -301,7 +304,7 @@ URL::SetHost(const nsAString& aHost)
|
||||
void
|
||||
URL::URLSearchParamsUpdated()
|
||||
{
|
||||
MOZ_ASSERT(mSearchParams);
|
||||
MOZ_ASSERT(mSearchParams && mSearchParams->IsValid());
|
||||
|
||||
nsAutoString search;
|
||||
mSearchParams->Serialize(search);
|
||||
@ -309,11 +312,9 @@ URL::URLSearchParamsUpdated()
|
||||
}
|
||||
|
||||
void
|
||||
URL::UpdateURLSearchParams()
|
||||
URL::URLSearchParamsNeedsUpdates()
|
||||
{
|
||||
if (!mSearchParams) {
|
||||
return;
|
||||
}
|
||||
MOZ_ASSERT(mSearchParams);
|
||||
|
||||
nsAutoCString search;
|
||||
nsCOMPtr<nsIURL> url(do_QueryInterface(mURI));
|
||||
@ -324,7 +325,7 @@ URL::UpdateURLSearchParams()
|
||||
}
|
||||
}
|
||||
|
||||
mSearchParams->ParseInput(search, this);
|
||||
mSearchParams->ParseInput(search);
|
||||
}
|
||||
|
||||
void
|
||||
@ -425,7 +426,10 @@ void
|
||||
URL::SetSearch(const nsAString& aSearch)
|
||||
{
|
||||
SetSearchInternal(aSearch);
|
||||
UpdateURLSearchParams();
|
||||
|
||||
if (mSearchParams) {
|
||||
mSearchParams->Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@ -454,13 +458,15 @@ URL::SetSearchParams(URLSearchParams* aSearchParams)
|
||||
return;
|
||||
}
|
||||
|
||||
if (mSearchParams) {
|
||||
mSearchParams->RemoveObserver(this);
|
||||
}
|
||||
if (!aSearchParams->HasURLAssociated()) {
|
||||
MOZ_ASSERT(aSearchParams->IsValid());
|
||||
|
||||
// the observer will be cleared using the cycle collector.
|
||||
mSearchParams = aSearchParams;
|
||||
mSearchParams->AddObserver(this);
|
||||
mSearchParams = aSearchParams;
|
||||
mSearchParams->SetObserver(this);
|
||||
} else {
|
||||
CreateSearchParamsIfNeeded();
|
||||
mSearchParams->CopyFromURLSearchParams(*aSearchParams);
|
||||
}
|
||||
|
||||
nsAutoString search;
|
||||
mSearchParams->Serialize(search);
|
||||
@ -500,8 +506,8 @@ URL::CreateSearchParamsIfNeeded()
|
||||
{
|
||||
if (!mSearchParams) {
|
||||
mSearchParams = new URLSearchParams();
|
||||
mSearchParams->AddObserver(this);
|
||||
UpdateURLSearchParams();
|
||||
mSearchParams->SetObserver(this);
|
||||
mSearchParams->Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -125,6 +125,7 @@ public:
|
||||
|
||||
// URLSearchParamsObserver
|
||||
void URLSearchParamsUpdated() MOZ_OVERRIDE;
|
||||
void URLSearchParamsNeedsUpdates() MOZ_OVERRIDE;
|
||||
|
||||
private:
|
||||
nsIURI* GetURI() const
|
||||
@ -136,8 +137,6 @@ 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, mObservers)
|
||||
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(URLSearchParams, mObserver)
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(URLSearchParams)
|
||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(URLSearchParams)
|
||||
|
||||
@ -19,6 +19,7 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(URLSearchParams)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
URLSearchParams::URLSearchParams()
|
||||
: mValid(false)
|
||||
{
|
||||
SetIsDOMBinding();
|
||||
}
|
||||
@ -40,7 +41,7 @@ URLSearchParams::Constructor(const GlobalObject& aGlobal,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
nsRefPtr<URLSearchParams> sp = new URLSearchParams();
|
||||
sp->ParseInput(NS_ConvertUTF16toUTF8(aInit), nullptr);
|
||||
sp->ParseInput(NS_ConvertUTF16toUTF8(aInit));
|
||||
return sp.forget();
|
||||
}
|
||||
|
||||
@ -51,12 +52,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,
|
||||
URLSearchParamsObserver* aObserver)
|
||||
URLSearchParams::ParseInput(const nsACString& aInput)
|
||||
{
|
||||
// Remove all the existing data before parsing a new input.
|
||||
DeleteAll();
|
||||
@ -108,7 +109,7 @@ URLSearchParams::ParseInput(const nsACString& aInput,
|
||||
NS_ConvertUTF8toUTF16(decodedValue));
|
||||
}
|
||||
|
||||
NotifyObservers(aObserver);
|
||||
mValid = true;
|
||||
}
|
||||
|
||||
void
|
||||
@ -164,6 +165,18 @@ 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,
|
||||
@ -179,24 +192,27 @@ URLSearchParams::CopyEnumerator(const nsAString& aName,
|
||||
}
|
||||
|
||||
void
|
||||
URLSearchParams::AddObserver(URLSearchParamsObserver* aObserver)
|
||||
URLSearchParams::SetObserver(URLSearchParamsObserver* aObserver)
|
||||
{
|
||||
MOZ_ASSERT(aObserver);
|
||||
MOZ_ASSERT(!mObservers.Contains(aObserver));
|
||||
mObservers.AppendElement(aObserver);
|
||||
MOZ_ASSERT(!mObserver);
|
||||
mObserver = aObserver;
|
||||
}
|
||||
|
||||
void
|
||||
URLSearchParams::RemoveObserver(URLSearchParamsObserver* aObserver)
|
||||
URLSearchParams::Validate()
|
||||
{
|
||||
MOZ_ASSERT(aObserver);
|
||||
MOZ_ASSERT(mObservers.Contains(aObserver));
|
||||
mObservers.RemoveElement(aObserver);
|
||||
MOZ_ASSERT(mValid || mObserver);
|
||||
if (!mValid) {
|
||||
mObserver->URLSearchParamsNeedsUpdates();
|
||||
MOZ_ASSERT(mValid);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
URLSearchParams::Get(const nsAString& aName, nsString& aRetval)
|
||||
{
|
||||
Validate();
|
||||
|
||||
nsTArray<nsString>* array;
|
||||
if (!mSearchParams.Get(aName, &array)) {
|
||||
aRetval.Truncate();
|
||||
@ -209,6 +225,8 @@ 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;
|
||||
@ -220,6 +238,10 @@ 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>();
|
||||
@ -229,14 +251,18 @@ URLSearchParams::Set(const nsAString& aName, const nsAString& aValue)
|
||||
array->ElementAt(0) = aValue;
|
||||
}
|
||||
|
||||
NotifyObservers(nullptr);
|
||||
NotifyObserver();
|
||||
}
|
||||
|
||||
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);
|
||||
NotifyObservers(nullptr);
|
||||
NotifyObserver();
|
||||
}
|
||||
|
||||
void
|
||||
@ -254,12 +280,17 @@ 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;
|
||||
@ -267,7 +298,7 @@ URLSearchParams::Delete(const nsAString& aName)
|
||||
|
||||
mSearchParams.Remove(aName);
|
||||
|
||||
NotifyObservers(nullptr);
|
||||
NotifyObserver();
|
||||
}
|
||||
|
||||
void
|
||||
@ -312,6 +343,8 @@ public:
|
||||
void
|
||||
URLSearchParams::Serialize(nsAString& aValue) const
|
||||
{
|
||||
MOZ_ASSERT(mValid);
|
||||
|
||||
SerializeData data;
|
||||
mSearchParams.EnumerateRead(SerializeEnumerator, &data);
|
||||
aValue.Assign(data.mValue);
|
||||
@ -340,14 +373,18 @@ URLSearchParams::SerializeEnumerator(const nsAString& aName,
|
||||
}
|
||||
|
||||
void
|
||||
URLSearchParams::NotifyObservers(URLSearchParamsObserver* aExceptObserver)
|
||||
URLSearchParams::NotifyObserver()
|
||||
{
|
||||
for (uint32_t i = 0; i < mObservers.Length(); ++i) {
|
||||
if (mObservers[i] != aExceptObserver) {
|
||||
mObservers[i]->URLSearchParamsUpdated();
|
||||
}
|
||||
if (mObserver) {
|
||||
mObserver->URLSearchParamsUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
URLSearchParams::Invalidate()
|
||||
{
|
||||
mValid = false;
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
@ -23,6 +23,7 @@ public:
|
||||
virtual ~URLSearchParamsObserver() {}
|
||||
|
||||
virtual void URLSearchParamsUpdated() = 0;
|
||||
virtual void URLSearchParamsNeedsUpdates() = 0;
|
||||
};
|
||||
|
||||
class URLSearchParams MOZ_FINAL : public nsISupports,
|
||||
@ -35,6 +36,11 @@ public:
|
||||
URLSearchParams();
|
||||
~URLSearchParams();
|
||||
|
||||
bool HasURLAssociated() const
|
||||
{
|
||||
return !!mObserver;
|
||||
}
|
||||
|
||||
// WebIDL methods
|
||||
nsISupports* GetParentObject() const
|
||||
{
|
||||
@ -52,11 +58,18 @@ public:
|
||||
Constructor(const GlobalObject& aGlobal, URLSearchParams& aInit,
|
||||
ErrorResult& aRv);
|
||||
|
||||
void ParseInput(const nsACString& aInput,
|
||||
URLSearchParamsObserver* aObserver);
|
||||
void ParseInput(const nsACString& aInput);
|
||||
|
||||
void AddObserver(URLSearchParamsObserver* aObserver);
|
||||
void RemoveObserver(URLSearchParamsObserver* aObserver);
|
||||
void CopyFromURLSearchParams(URLSearchParams& aSearchParams);
|
||||
|
||||
void SetObserver(URLSearchParamsObserver* aObserver);
|
||||
|
||||
void Invalidate();
|
||||
|
||||
bool IsValid() const
|
||||
{
|
||||
return mValid;
|
||||
}
|
||||
|
||||
void Serialize(nsAString& aValue) const;
|
||||
|
||||
@ -74,6 +87,7 @@ public:
|
||||
|
||||
void Stringify(nsString& aRetval)
|
||||
{
|
||||
Validate();
|
||||
Serialize(aRetval);
|
||||
}
|
||||
|
||||
@ -84,7 +98,7 @@ private:
|
||||
|
||||
void DecodeString(const nsACString& aInput, nsACString& aOutput);
|
||||
|
||||
void NotifyObservers(URLSearchParamsObserver* aExceptObserver);
|
||||
void NotifyObserver();
|
||||
|
||||
static PLDHashOperator
|
||||
CopyEnumerator(const nsAString& aName, nsTArray<nsString>* aArray,
|
||||
@ -94,9 +108,14 @@ private:
|
||||
SerializeEnumerator(const nsAString& aName, nsTArray<nsString>* aArray,
|
||||
void *userData);
|
||||
|
||||
void
|
||||
Validate();
|
||||
|
||||
nsClassHashtable<nsStringHashKey, nsTArray<nsString>> mSearchParams;
|
||||
|
||||
nsTArray<nsRefPtr<URLSearchParamsObserver>> mObservers;
|
||||
nsRefPtr<URLSearchParamsObserver> mObserver;
|
||||
|
||||
bool mValid;
|
||||
};
|
||||
|
||||
} // 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;
|
||||
is(url.searchParams, url2.searchParams, "URL.searchParams is not the same object");
|
||||
isnot(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;
|
||||
is(e.searchParams, url2.searchParams, "e.searchParams is not the same object");
|
||||
isnot(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,45 +203,6 @@ 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,
|
||||
@ -249,8 +210,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=887836
|
||||
testURL,
|
||||
function() { testElement(document.getElementById('anchor')) },
|
||||
function() { testElement(document.getElementById('area')) },
|
||||
testEncoding,
|
||||
testMultiURL
|
||||
testEncoding
|
||||
];
|
||||
|
||||
function runTest() {
|
||||
|
@ -615,7 +615,9 @@ URL::SetHref(const nsAString& aHref, ErrorResult& aRv)
|
||||
JS_ReportPendingException(mWorkerPrivate->GetJSContext());
|
||||
}
|
||||
|
||||
UpdateURLSearchParams();
|
||||
if (mSearchParams) {
|
||||
mSearchParams->Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@ -821,7 +823,10 @@ void
|
||||
URL::SetSearch(const nsAString& aSearch)
|
||||
{
|
||||
SetSearchInternal(aSearch);
|
||||
UpdateURLSearchParams();
|
||||
|
||||
if (mSearchParams) {
|
||||
mSearchParams->Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@ -851,12 +856,16 @@ URL::SetSearchParams(URLSearchParams* aSearchParams)
|
||||
return;
|
||||
}
|
||||
|
||||
if (mSearchParams) {
|
||||
mSearchParams->RemoveObserver(this);
|
||||
if (!aSearchParams->HasURLAssociated()) {
|
||||
MOZ_ASSERT(aSearchParams->IsValid());
|
||||
|
||||
mSearchParams = aSearchParams;
|
||||
mSearchParams->SetObserver(this);
|
||||
} else {
|
||||
CreateSearchParamsIfNeeded();
|
||||
mSearchParams->CopyFromURLSearchParams(*aSearchParams);
|
||||
}
|
||||
|
||||
mSearchParams = aSearchParams;
|
||||
mSearchParams->AddObserver(this);
|
||||
|
||||
nsString search;
|
||||
mSearchParams->Serialize(search);
|
||||
@ -942,7 +951,7 @@ URL::RevokeObjectURL(const GlobalObject& aGlobal, const nsAString& aUrl)
|
||||
void
|
||||
URL::URLSearchParamsUpdated()
|
||||
{
|
||||
MOZ_ASSERT(mSearchParams);
|
||||
MOZ_ASSERT(mSearchParams && mSearchParams->IsValid());
|
||||
|
||||
nsString search;
|
||||
mSearchParams->Serialize(search);
|
||||
@ -950,13 +959,13 @@ URL::URLSearchParamsUpdated()
|
||||
}
|
||||
|
||||
void
|
||||
URL::UpdateURLSearchParams()
|
||||
URL::URLSearchParamsNeedsUpdates()
|
||||
{
|
||||
if (mSearchParams) {
|
||||
nsString search;
|
||||
GetSearch(search);
|
||||
mSearchParams->ParseInput(NS_ConvertUTF16toUTF8(Substring(search, 1)), this);
|
||||
}
|
||||
MOZ_ASSERT(mSearchParams);
|
||||
|
||||
nsString search;
|
||||
GetSearch(search);
|
||||
mSearchParams->ParseInput(NS_ConvertUTF16toUTF8(Substring(search, 1)));
|
||||
}
|
||||
|
||||
void
|
||||
@ -964,8 +973,8 @@ URL::CreateSearchParamsIfNeeded()
|
||||
{
|
||||
if (!mSearchParams) {
|
||||
mSearchParams = new URLSearchParams();
|
||||
mSearchParams->AddObserver(this);
|
||||
UpdateURLSearchParams();
|
||||
mSearchParams->SetObserver(this);
|
||||
mSearchParams->Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -119,6 +119,7 @@ public:
|
||||
|
||||
// IURLSearchParamsObserver
|
||||
void URLSearchParamsUpdated() MOZ_OVERRIDE;
|
||||
void URLSearchParamsNeedsUpdates() MOZ_OVERRIDE;
|
||||
|
||||
private:
|
||||
URLProxy* GetURLProxy() const
|
||||
@ -130,8 +131,6 @@ private:
|
||||
|
||||
void SetSearchInternal(const nsAString& aSearch);
|
||||
|
||||
void UpdateURLSearchParams();
|
||||
|
||||
WorkerPrivate* mWorkerPrivate;
|
||||
nsRefPtr<URLProxy> mURLProxy;
|
||||
nsRefPtr<URLSearchParams> mSearchParams;
|
||||
|
@ -8,6 +8,11 @@ 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 {
|
||||
@ -129,7 +134,7 @@ onmessage = function() {
|
||||
|
||||
var url2 = new URL('http://www.example.net?e=f');
|
||||
url.searchParams = url2.searchParams;
|
||||
is(url.searchParams, url2.searchParams, "URL.searchParams is not the same object");
|
||||
isnot(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";
|
||||
@ -159,39 +164,12 @@ 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,
|
||||
testMultiURL
|
||||
testEncoding
|
||||
];
|
||||
|
||||
function runTest() {
|
||||
|
@ -123,9 +123,9 @@ Link::URLSearchParamsUpdated()
|
||||
}
|
||||
|
||||
void
|
||||
Link::UpdateURLSearchParams()
|
||||
Link::URLSearchParamsNeedsUpdates()
|
||||
{
|
||||
NS_NOTREACHED("Unexpected call to Link::UpdateURLSearchParams");
|
||||
NS_NOTREACHED("Unexpected call to Link::URLSearchParamsNeedsUpdates");
|
||||
}
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_CLASS(URLSearchParams)
|
||||
@ -159,20 +159,19 @@ URLSearchParams::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
|
||||
}
|
||||
|
||||
void
|
||||
URLSearchParams::ParseInput(const nsACString& aInput,
|
||||
URLSearchParamsObserver* aObserver)
|
||||
URLSearchParams::ParseInput(const nsACString& aInput)
|
||||
{
|
||||
NS_NOTREACHED("Unexpected call to URLSearchParams::ParseInput");
|
||||
}
|
||||
|
||||
void
|
||||
URLSearchParams::AddObserver(URLSearchParamsObserver* aObserver)
|
||||
URLSearchParams::CopyFromURLSearchParams(URLSearchParams& aSearchParams)
|
||||
{
|
||||
NS_NOTREACHED("Unexpected call to URLSearchParams::SetObserver");
|
||||
NS_NOTREACHED("Unexpected call to URLSearchParams::CopyFromURLSearchParams");
|
||||
}
|
||||
|
||||
void
|
||||
URLSearchParams::RemoveObserver(URLSearchParamsObserver* aObserver)
|
||||
URLSearchParams::SetObserver(URLSearchParamsObserver* aObserver)
|
||||
{
|
||||
NS_NOTREACHED("Unexpected call to URLSearchParams::SetObserver");
|
||||
}
|
||||
@ -233,11 +232,18 @@ URLSearchParams::DeleteAll()
|
||||
}
|
||||
|
||||
void
|
||||
URLSearchParams::NotifyObservers(URLSearchParamsObserver* aExceptObserver)
|
||||
URLSearchParams::NotifyObserver()
|
||||
{
|
||||
NS_NOTREACHED("Unexpected call to URLSearchParams::NotifyObservers");
|
||||
NS_NOTREACHED("Unexpected call to URLSearchParams::NotifyObserver");
|
||||
}
|
||||
|
||||
void
|
||||
URLSearchParams::Invalidate()
|
||||
{
|
||||
NS_NOTREACHED("Unexpected call to URLSearchParams::Invalidate");
|
||||
}
|
||||
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user