forked from mirrors/gecko-dev
Automatic update from web-platform-tests
Update URLs to Web IDL
Only two instances of "heycam.github.io" remain now.
interfaces/WebIDL.idl will be updated when webref is updated next time,
as it has already been fixed there:
7c04f47557
resources/webidl2/lib/webidl2.js is third-party code and will be updated
at some point in the future.
--
wpt-commits: 9a88dfd5bf623a8cb326c154b27f1e3494e11022
wpt-pr: 31148
40 lines
1.3 KiB
HTML
40 lines
1.3 KiB
HTML
<!doctype html>
|
|
<meta charset="utf-8">
|
|
<title>Behavior of iterators when modified within foreach</title>
|
|
<script src="/resources/testharness.js"></script>
|
|
<script src="/resources/testharnessreport.js"></script>
|
|
<link rel="help" href="https://webidl.spec.whatwg.org/#es-forEach">
|
|
<link rel="author" title="Manish Goregaokar" href="mailto:manishsmail@gmail.com">
|
|
<script>
|
|
test(function() {
|
|
let params = new URLSearchParams("a=1&b=2&c=3");
|
|
let arr = [];
|
|
params.forEach((p) => {
|
|
arr.push(p);
|
|
params.delete("b");
|
|
})
|
|
assert_array_equals(arr, ["1", "3"]);
|
|
}, "forEach will not iterate over elements removed during iteration");
|
|
test(function() {
|
|
let params = new URLSearchParams("a=1&b=2&c=3&d=4");
|
|
let arr = [];
|
|
params.forEach((p) => {
|
|
arr.push(p);
|
|
if (p == "2") {
|
|
params.delete("a");
|
|
}
|
|
})
|
|
assert_array_equals(arr, ["1", "2", "4"]);
|
|
}, "Removing elements already iterated over during forEach will cause iterator to skip an element");
|
|
test(function() {
|
|
let params = new URLSearchParams("a=1&b=2&c=3&d=4");
|
|
let arr = [];
|
|
params.forEach((p) => {
|
|
arr.push(p);
|
|
if (p == "2") {
|
|
params.append("e", "5");
|
|
}
|
|
})
|
|
assert_array_equals(arr, ["1", "2", "3", "4", "5"]);
|
|
}, "Elements added during iteration with forEach will be reached");
|
|
</script>
|