-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Symbol.unscopables lexical scope test of compiled event handlers
- Loading branch information
Showing
1 changed file
with
92 additions
and
0 deletions.
There are no files selected for viewing
92 changes: 92 additions & 0 deletions
92
html/webappapis/scripting/events/compile-event-handler-symbol-unscopables.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,92 @@ | ||
<!DOCTYPE html> | ||
<meta charset="UTF-8" /> | ||
<title>Inline event handler scopes exclude unscopable properties</title> | ||
<link rel="author" title="ExE Boss" href="https://ExE-Boss.tech" /> | ||
<link rel="help" href="https://html.spec.whatwg.org/multipage/webappapis.html#getting-the-current-value-of-the-event-handler" /> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
|
||
<script> | ||
"use strict"; | ||
|
||
// (document[Symbol.unscopables] ||= {}).testVariable = true; | ||
let documentUnscopables = document[Symbol.unscopables]; | ||
if (!documentUnscopables) { | ||
documentUnscopables = {}; | ||
document[Symbol.unscopables] = documentUnscopables; | ||
} | ||
|
||
documentUnscopables.testVariable = true; | ||
document.testVariable = "FAIL"; | ||
window.testVariable = {}; | ||
</script> | ||
|
||
<!-- test case 1: element, document, and window --> | ||
<div id="test1_target" onclick=' | ||
"use strict"; | ||
window.testResults.testVariable = testVariable; | ||
'></div> | ||
|
||
<script> | ||
"use strict"; | ||
|
||
test(() => { | ||
const results = window.testResults = {}; | ||
|
||
document.getElementById("test1_target").click(); | ||
assert_equals(results.testVariable, window.testVariable); | ||
}, "unscopable `document.testVariable` doesn't shadow `window.testVariable`"); | ||
|
||
test(() => { | ||
const results = window.testResults = {}; | ||
const element = document.getElementById("test1_target"); | ||
|
||
// (element[Symbol.unscopables] ||= {}).testVariable = true; | ||
let elementUnscopables = element[Symbol.unscopables]; | ||
if (!elementUnscopables) { | ||
elementUnscopables = {}; | ||
element[Symbol.unscopables] = elementUnscopables; | ||
} | ||
|
||
elementUnscopables.testVariable = true; | ||
element.testVariable = "FAIL (element)"; | ||
|
||
element.click(); | ||
assert_equals(results.testVariable, window.testVariable); | ||
}, "unscopable `element.testVariable` doesn't shadow `window.testVariable`"); | ||
</script> | ||
|
||
<!-- test case 2: element, form owner, document, and window --> | ||
<form id="test2_form_owner" onsubmit="return false;"> | ||
<!-- <button> is a form-associated element and has a form owner. | ||
https://html.spec.whatwg.org/C/#form-associated-element --> | ||
<button id="test2_target" onclick=' | ||
"use strict"; | ||
window.testResults.testVariable = testVariable; | ||
'></button> | ||
</form> | ||
|
||
<script> | ||
"use strict"; | ||
|
||
test(() => { | ||
const results = window.testResults = {}; | ||
const element = document.getElementById("test2_target"); | ||
const formOwner = document.getElementById("test2_form_owner"); | ||
|
||
// (formOwner[Symbol.unscopables] ||= {}).testVariable = true; | ||
let formOwnerUnscopables = formOwner[Symbol.unscopables]; | ||
if (!formOwnerUnscopables) { | ||
formOwnerUnscopables = {}; | ||
formOwner[Symbol.unscopables] = formOwnerUnscopables; | ||
} | ||
|
||
formOwnerUnscopables.testVariable = true; | ||
formOwner.testVariable = "FAIL (formOwner)"; | ||
|
||
element.click(); | ||
assert_equals(results.testVariable, window.testVariable); | ||
}, "unscopable `formOwner.testVariable` doesn't shadow `window.testVariable`") | ||
</script> |