mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-25 18:07:31 +09:00
Issue #1449 - Implement URLSearchParams's sort()
This commit is contained in:
parent
8ca630ef64
commit
0c44ae0a30
3 changed files with 51 additions and 1 deletions
|
|
@ -448,6 +448,15 @@ URLSearchParams::GetValueAtIndex(uint32_t aIndex) const
|
||||||
return mParams->GetValueAtIndex(aIndex);
|
return mParams->GetValueAtIndex(aIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
URLSearchParams::Sort(ErrorResult& aRv)
|
||||||
|
{
|
||||||
|
aRv = mParams->Sort();
|
||||||
|
if (!aRv.Failed()) {
|
||||||
|
NotifyObserver();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Helper functions for structured cloning
|
// Helper functions for structured cloning
|
||||||
inline bool
|
inline bool
|
||||||
ReadString(JSStructuredCloneReader* aReader, nsString& aString)
|
ReadString(JSStructuredCloneReader* aReader, nsString& aString)
|
||||||
|
|
@ -472,6 +481,39 @@ ReadString(JSStructuredCloneReader* aReader, nsString& aString)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nsresult
|
||||||
|
URLParams::Sort()
|
||||||
|
{
|
||||||
|
// Unfortunately we cannot use nsTArray<>.Sort() because it doesn't keep the
|
||||||
|
// correct order of the values for equal keys.
|
||||||
|
|
||||||
|
// Let's sort the keys, without duplicates.
|
||||||
|
FallibleTArray<nsString> keys;
|
||||||
|
for (const Param& param : mParams) {
|
||||||
|
if (!keys.Contains(param.mKey) &&
|
||||||
|
!keys.InsertElementSorted(param.mKey, fallible)) {
|
||||||
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FallibleTArray<Param> params;
|
||||||
|
|
||||||
|
// Here we recreate the array starting from the sorted keys.
|
||||||
|
for (uint32_t keyId = 0, keysLength = keys.Length(); keyId < keysLength;
|
||||||
|
++keyId) {
|
||||||
|
const nsString& key = keys[keyId];
|
||||||
|
for (const Param& param : mParams) {
|
||||||
|
if (param.mKey.Equals(key) &&
|
||||||
|
!params.AppendElement(param, fallible)) {
|
||||||
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mParams.SwapElements(params);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
inline bool
|
inline bool
|
||||||
WriteString(JSStructuredCloneWriter* aWriter, const nsString& aString)
|
WriteString(JSStructuredCloneWriter* aWriter, const nsString& aString)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ public:
|
||||||
|
|
||||||
void Get(const nsAString& aName, nsString& aRetval);
|
void Get(const nsAString& aName, nsString& aRetval);
|
||||||
|
|
||||||
void GetAll(const nsAString& aName, nsTArray<nsString >& aRetval);
|
void GetAll(const nsAString& aName, nsTArray<nsString>& aRetval);
|
||||||
|
|
||||||
void Set(const nsAString& aName, const nsAString& aValue);
|
void Set(const nsAString& aName, const nsAString& aValue);
|
||||||
|
|
||||||
|
|
@ -103,6 +103,8 @@ public:
|
||||||
return mParams[aIndex].mValue;
|
return mParams[aIndex].mValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nsresult Sort();
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ReadStructuredClone(JSStructuredCloneReader* aReader);
|
ReadStructuredClone(JSStructuredCloneReader* aReader);
|
||||||
|
|
||||||
|
|
@ -171,6 +173,8 @@ public:
|
||||||
const nsAString& GetKeyAtIndex(uint32_t aIndex) const;
|
const nsAString& GetKeyAtIndex(uint32_t aIndex) const;
|
||||||
const nsAString& GetValueAtIndex(uint32_t aIndex) const;
|
const nsAString& GetValueAtIndex(uint32_t aIndex) const;
|
||||||
|
|
||||||
|
void Sort(ErrorResult& aRv);
|
||||||
|
|
||||||
void Stringify(nsString& aRetval) const
|
void Stringify(nsString& aRetval) const
|
||||||
{
|
{
|
||||||
Serialize(aRetval);
|
Serialize(aRetval);
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,10 @@ interface URLSearchParams {
|
||||||
sequence<USVString> getAll(USVString name);
|
sequence<USVString> getAll(USVString name);
|
||||||
boolean has(USVString name);
|
boolean has(USVString name);
|
||||||
void set(USVString name, USVString value);
|
void set(USVString name, USVString value);
|
||||||
|
|
||||||
|
[Throws]
|
||||||
|
void sort();
|
||||||
|
|
||||||
iterable<USVString, USVString>;
|
iterable<USVString, USVString>;
|
||||||
stringifier;
|
stringifier;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue