mirror of
https://github.com/servo/servo.git
synced 2025-09-09 22:48:21 +01:00
Support value iterators in WebIDL interfaces.
This commit is contained in:
parent
221bc84693
commit
34bb937aee
7 changed files with 161 additions and 0 deletions
|
@ -6858,6 +6858,12 @@
|
|||
"url": "/_mozilla/mozilla/interfaces.worker"
|
||||
}
|
||||
],
|
||||
"mozilla/iterable.html": [
|
||||
{
|
||||
"path": "mozilla/iterable.html",
|
||||
"url": "/_mozilla/mozilla/iterable.html"
|
||||
}
|
||||
],
|
||||
"mozilla/lenient_this.html": [
|
||||
{
|
||||
"path": "mozilla/lenient_this.html",
|
||||
|
|
3
tests/wpt/mozilla/meta/mozilla/iterable.html.ini
Normal file
3
tests/wpt/mozilla/meta/mozilla/iterable.html.ini
Normal file
|
@ -0,0 +1,3 @@
|
|||
[iterable.html]
|
||||
type: testharness
|
||||
prefs: [dom.testbinding.enabled:true]
|
54
tests/wpt/mozilla/tests/mozilla/iterable.html
Normal file
54
tests/wpt/mozilla/tests/mozilla/iterable.html
Normal file
|
@ -0,0 +1,54 @@
|
|||
<!doctype html>
|
||||
<meta charset="utf-8">
|
||||
<title>Value and pair iterable bindings</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
function collect(iter) {
|
||||
var collection = [];
|
||||
for (element of iter) {
|
||||
collection.push(element);
|
||||
}
|
||||
return collection;
|
||||
}
|
||||
|
||||
test(function() {
|
||||
var t = new TestBindingIterable();
|
||||
var empty = true;
|
||||
t.forEach(function() { empty = false; });
|
||||
assert_true(empty);
|
||||
}, "Empty value iterator");
|
||||
|
||||
test(function() {
|
||||
var t = new TestBindingIterable();
|
||||
function is_iterator(o) {
|
||||
return o[Symbol.iterator]() === o;
|
||||
}
|
||||
assert_true(is_iterator(t.keys()));
|
||||
assert_true(is_iterator(t.values()));
|
||||
assert_true(is_iterator(t.entries()));
|
||||
}, "Iterable iterators are iterators");
|
||||
|
||||
test(function() {
|
||||
var t = new TestBindingIterable();
|
||||
t.add("first");
|
||||
t.add("second");
|
||||
t.add("third");
|
||||
assert_array_equals(collect(t.keys()), [0, 1, 2]);
|
||||
assert_array_equals(collect(t.values()), ["first", "second", "third"]);
|
||||
var expected = [[0, "first"], [1, "second"], [2, "third"]];
|
||||
var i = 0;
|
||||
for (entry of t.entries()) {
|
||||
assert_array_equals(entry, expected[i++]);
|
||||
}
|
||||
|
||||
t.add("fourth");
|
||||
assert_array_equals(collect(t.keys()), [0, 1, 2, 3]);
|
||||
assert_array_equals(collect(t.values()), ["first", "second", "third", "fourth"]);
|
||||
var expected = [[0, "first"], [1, "second"], [2, "third"], [3, "fourth"]];
|
||||
var i = 0;
|
||||
for (entry of t.entries()) {
|
||||
assert_array_equals(entry, expected[i++]);
|
||||
}
|
||||
}, "Iterators iterate over values");
|
||||
</script>
|
Loading…
Add table
Add a link
Reference in a new issue