Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix MutationObserver infinite loop bugs (#3173)
- Loading branch information
Showing
2 changed files
with
57 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
test/web-platform-tests/to-upstream/dom/nodes/MutationObserver-callback-tricky.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<!doctype html> | ||
<meta charset=utf-8> | ||
<title>Certain actions within the callback does not lead to infinite loop</title> | ||
<script src=/resources/testharness.js></script> | ||
<script src=/resources/testharnessreport.js></script> | ||
<body> | ||
<script> | ||
"use strict"; | ||
|
||
promise_test(() => { | ||
let called = 0; | ||
const div1 = document.createElement("div"); | ||
document.body.appendChild(div1); | ||
const m = new MutationObserver(() => { | ||
called++; | ||
const div2 = document.createElement("div"); | ||
document.body.appendChild(div2); | ||
m.observe(div2, { attributes: true }); | ||
}); | ||
m.observe(div1, { attributes: true }); | ||
div1.setAttribute("data-test", "test"); | ||
return Promise.resolve().then(() => { | ||
assert_equals(called, 1, "times callback called"); | ||
}); | ||
}, "Calling observe in callback should not lead to more calls"); | ||
|
||
promise_test(() => { | ||
let called = 0; | ||
const div1 = document.createElement("div"); | ||
document.body.appendChild(div1); | ||
const m = new MutationObserver(() => { | ||
called++; | ||
m.disconnect(); | ||
m.observe(div1, { attributes: true }); | ||
}); | ||
m.observe(div1, { attributes: true }); | ||
div1.setAttribute("data-test", "test"); | ||
return Promise.resolve().then(() => { | ||
assert_equals(called, 1, "times callback called"); | ||
}); | ||
}, "Disconnect and re-observe in callback should not lead to more calls"); | ||
</script> | ||
|