mirror of
https://github.com/servo/servo.git
synced 2025-06-29 19:43:39 +01:00
Add WPT test for invalidating WebIDL iterators during forEach
This commit is contained in:
parent
d233558b9b
commit
38a666742f
2 changed files with 50 additions and 0 deletions
|
@ -308306,6 +308306,12 @@
|
||||||
{}
|
{}
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
"WebIDL/ecmascript-binding/iterator-invalidation-foreach.html": [
|
||||||
|
[
|
||||||
|
"WebIDL/ecmascript-binding/iterator-invalidation-foreach.html",
|
||||||
|
{}
|
||||||
|
]
|
||||||
|
],
|
||||||
"WebIDL/ecmascript-binding/iterator-prototype-object.html": [
|
"WebIDL/ecmascript-binding/iterator-prototype-object.html": [
|
||||||
[
|
[
|
||||||
"WebIDL/ecmascript-binding/iterator-prototype-object.html",
|
"WebIDL/ecmascript-binding/iterator-prototype-object.html",
|
||||||
|
@ -466654,6 +466660,10 @@
|
||||||
"03ada7aa0d4d43811652fc679a00a41b9653013d",
|
"03ada7aa0d4d43811652fc679a00a41b9653013d",
|
||||||
"testharness"
|
"testharness"
|
||||||
],
|
],
|
||||||
|
"WebIDL/ecmascript-binding/iterator-invalidation-foreach.html": [
|
||||||
|
"d6498c3e388e0c637830fa080cca78b0ab0e5305",
|
||||||
|
"testharness"
|
||||||
|
],
|
||||||
"WebIDL/ecmascript-binding/iterator-prototype-object.html": [
|
"WebIDL/ecmascript-binding/iterator-prototype-object.html": [
|
||||||
"5a935fa20135d88a7268b872b68ab7fe548ab5c7",
|
"5a935fa20135d88a7268b872b68ab7fe548ab5c7",
|
||||||
"testharness"
|
"testharness"
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
<!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://heycam.github.io/webidl/#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>
|
Loading…
Add table
Add a link
Reference in a new issue