Compile raw inline event handlers lazily. Resolves #8489.

This commit is contained in:
Josh Matthews 2015-11-12 11:20:08 -05:00 committed by Ms2ger
parent 3703e6d4f6
commit 2796a4dfa8
11 changed files with 323 additions and 67 deletions

View file

@ -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>

View file

@ -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>