mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Compile raw inline event handlers lazily. Resolves #8489.
This commit is contained in:
parent
3703e6d4f6
commit
2796a4dfa8
11 changed files with 323 additions and 67 deletions
|
@ -0,0 +1,52 @@
|
|||
<!doctype html>
|
||||
<meta charset="utf-8">
|
||||
<title>Inline event handlers retain their ordering even when invalid</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<body>
|
||||
<script>
|
||||
var events = [];
|
||||
|
||||
test(function() {
|
||||
events = [];
|
||||
var e = document.createElement("div");
|
||||
document.body.appendChild(e);
|
||||
e.addEventListener("click", function() { events.push("ONE") });
|
||||
e.setAttribute("onclick", "window.open(");
|
||||
e.addEventListener("click", function() { events.push("THREE") });
|
||||
// Try to compile the event handler.
|
||||
e.onclick;
|
||||
e.setAttribute("onclick", "events.push('TWO')");
|
||||
e.dispatchEvent(new Event("click"));
|
||||
var expected_events = ["ONE", "TWO", "THREE"];
|
||||
assert_array_equals(events, expected_events);
|
||||
}, "Inline event handlers retain their ordering when invalid and force-compiled");
|
||||
|
||||
test(function() {
|
||||
events = [];
|
||||
var e = document.createElement("div");
|
||||
document.body.appendChild(e);
|
||||
e.addEventListener("click", function() { events.push("ONE") });
|
||||
e.setAttribute("onclick", "window.open(");
|
||||
e.addEventListener("click", function() { events.push("THREE") });
|
||||
e.dispatchEvent(new Event("click"));
|
||||
e.setAttribute("onclick", "events.push('TWO')");
|
||||
e.dispatchEvent(new Event("click"));
|
||||
var expected_events = ["ONE", "THREE", "ONE", "TWO", "THREE"];
|
||||
assert_array_equals(events, expected_events);
|
||||
}, "Inline event handlers retain their ordering when invalid and force-compiled via dispatch");
|
||||
|
||||
test(function() {
|
||||
events = [];
|
||||
var e = document.createElement("div");
|
||||
document.body.appendChild(e);
|
||||
e.addEventListener("click", function() { events.push("ONE") });
|
||||
e.setAttribute("onclick", "window.open(");
|
||||
e.addEventListener("click", function() { events.push("THREE") });
|
||||
e.setAttribute("onclick", "events.push('TWO')");
|
||||
e.dispatchEvent(new Event("click"));
|
||||
var expected_events = ["ONE", "TWO", "THREE"];
|
||||
assert_array_equals(events, expected_events);
|
||||
}, "Inline event handlers retain their ordering when invalid and lazy-compiled");
|
||||
</script>
|
||||
</body>
|
|
@ -0,0 +1,23 @@
|
|||
<!doctype html>
|
||||
<meta charset="utf-8">
|
||||
<title>Invalid uncompiled raw handlers should only be compiled once.</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<body>
|
||||
<script>
|
||||
setup({ allow_uncaught_exception: true });
|
||||
|
||||
var errors = 0;
|
||||
window.onerror = function() {
|
||||
errors++;
|
||||
};
|
||||
|
||||
test(function() {
|
||||
var e = document.body;
|
||||
e.setAttribute("onclick", "window.open(");
|
||||
assert_equals(e.onclick, null);
|
||||
assert_equals(e.onclick, null);
|
||||
assert_equals(errors, 1);
|
||||
});
|
||||
</script>
|
||||
</body>
|
Loading…
Add table
Add a link
Reference in a new issue