mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-04-12 02:50:13 +00:00
Bug 1085284 - Implement URLSearchParams iterable<>, r=bz
This commit is contained in:
parent
6729df0f94
commit
097bae44d1
@ -418,5 +418,23 @@ URLSearchParams::NotifyObserver()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t
|
||||||
|
URLSearchParams::GetIterableLength() const
|
||||||
|
{
|
||||||
|
return mParams->Length();
|
||||||
|
}
|
||||||
|
|
||||||
|
const nsAString&
|
||||||
|
URLSearchParams::GetKeyAtIndex(uint32_t aIndex) const
|
||||||
|
{
|
||||||
|
return mParams->GetKeyAtIndex(aIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
const nsAString&
|
||||||
|
URLSearchParams::GetValueAtIndex(uint32_t aIndex) const
|
||||||
|
{
|
||||||
|
return mParams->GetValueAtIndex(aIndex);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace dom
|
} // namespace dom
|
||||||
} // namespace mozilla
|
} // namespace mozilla
|
||||||
|
@ -91,6 +91,23 @@ public:
|
|||||||
mParams.Clear();
|
mParams.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t Length() const
|
||||||
|
{
|
||||||
|
return mParams.Length();
|
||||||
|
}
|
||||||
|
|
||||||
|
const nsAString& GetKeyAtIndex(uint32_t aIndex) const
|
||||||
|
{
|
||||||
|
MOZ_ASSERT(aIndex < mParams.Length());
|
||||||
|
return mParams[aIndex].mKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
const nsAString& GetValueAtIndex(uint32_t aIndex) const
|
||||||
|
{
|
||||||
|
MOZ_ASSERT(aIndex < mParams.Length());
|
||||||
|
return mParams[aIndex].mValue;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void DecodeString(const nsACString& aInput, nsAString& aOutput);
|
void DecodeString(const nsACString& aInput, nsAString& aOutput);
|
||||||
void ConvertString(const nsACString& aInput, nsAString& aOutput);
|
void ConvertString(const nsACString& aInput, nsAString& aOutput);
|
||||||
@ -153,6 +170,10 @@ public:
|
|||||||
|
|
||||||
void Delete(const nsAString& aName);
|
void Delete(const nsAString& aName);
|
||||||
|
|
||||||
|
uint32_t GetIterableLength() const;
|
||||||
|
const nsAString& GetKeyAtIndex(uint32_t aIndex) const;
|
||||||
|
const nsAString& GetValueAtIndex(uint32_t aIndex) const;
|
||||||
|
|
||||||
void Stringify(nsString& aRetval) const
|
void Stringify(nsString& aRetval) const
|
||||||
{
|
{
|
||||||
Serialize(aRetval);
|
Serialize(aRetval);
|
||||||
|
@ -237,6 +237,58 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=887836
|
|||||||
runTest();
|
runTest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testIterable() {
|
||||||
|
var u = new URLSearchParams();
|
||||||
|
u.set('1','2');
|
||||||
|
u.set('2','4');
|
||||||
|
u.set('3','6');
|
||||||
|
u.set('4','8');
|
||||||
|
u.set('5','10');
|
||||||
|
|
||||||
|
var key_iter = u.keys();
|
||||||
|
var value_iter = u.values();
|
||||||
|
var entries_iter = u.entries();
|
||||||
|
for (var i = 0; i < 5; ++i) {
|
||||||
|
var v = i + 1;
|
||||||
|
var key = key_iter.next();
|
||||||
|
var value = value_iter.next();
|
||||||
|
var entry = entries_iter.next();
|
||||||
|
is(key.value, v.toString(), "Correct Key iterator: " + v.toString());
|
||||||
|
ok(!key.done, "Key.done is false");
|
||||||
|
is(value.value, (v * 2).toString(), "Correct Value iterator: " + (v * 2).toString());
|
||||||
|
ok(!value.done, "Value.done is false");
|
||||||
|
is(entry.value[0], v.toString(), "Correct Entry 0 iterator: " + v.toString());
|
||||||
|
is(entry.value[1], (v * 2).toString(), "Correct Entry 1 iterator: " + (v * 2).toString());
|
||||||
|
ok(!entry.done, "Entry.done is false");
|
||||||
|
}
|
||||||
|
|
||||||
|
var last = key_iter.next();
|
||||||
|
ok(last.done, "Nothing more to read.");
|
||||||
|
is(last.value, undefined, "Undefined is the last key");
|
||||||
|
|
||||||
|
last = value_iter.next();
|
||||||
|
ok(last.done, "Nothing more to read.");
|
||||||
|
is(last.value, undefined, "Undefined is the last value");
|
||||||
|
|
||||||
|
last = entries_iter.next();
|
||||||
|
ok(last.done, "Nothing more to read.");
|
||||||
|
|
||||||
|
key_iter = u.keys();
|
||||||
|
key_iter.next();
|
||||||
|
key_iter.next();
|
||||||
|
u.delete('1');
|
||||||
|
u.delete('2');
|
||||||
|
u.delete('3');
|
||||||
|
u.delete('4');
|
||||||
|
u.delete('5');
|
||||||
|
|
||||||
|
last = key_iter.next();
|
||||||
|
ok(last.done, "Nothing more to read.");
|
||||||
|
is(last.value, undefined, "Undefined is the last key");
|
||||||
|
|
||||||
|
runTest();
|
||||||
|
}
|
||||||
|
|
||||||
var tests = [
|
var tests = [
|
||||||
testSimpleURLSearchParams,
|
testSimpleURLSearchParams,
|
||||||
testCopyURLSearchParams,
|
testCopyURLSearchParams,
|
||||||
@ -248,7 +300,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=887836
|
|||||||
testOrdering,
|
testOrdering,
|
||||||
testDelete,
|
testDelete,
|
||||||
testGetNULL,
|
testGetNULL,
|
||||||
testSet
|
testSet,
|
||||||
|
testIterable
|
||||||
];
|
];
|
||||||
|
|
||||||
function runTest() {
|
function runTest() {
|
||||||
|
@ -23,6 +23,6 @@ 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);
|
||||||
// iterable<USVString, USVString>; - Bug 1085284
|
iterable<USVString, USVString>;
|
||||||
stringifier;
|
stringifier;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user