existing-prop.html (1709B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <title>Named access on the window object - Existing property</title> 4 <link rel="author" title="Matthew Phillips" href="mailto:matthew@matthewphillips.info"> 5 <link rel="help" href="https://html.spec.whatwg.org/#named-access-on-the-window-object"> 6 <script src="/resources/testharness.js"></script> 7 <script src="/resources/testharnessreport.js"></script> 8 9 <body> 10 <script> 11 "use strict"; 12 13 test(() => { 14 window["existing-one"] = 5; 15 16 const img = document.createElement("img"); 17 img.setAttribute("id", "existing-one"); 18 document.body.appendChild(img); 19 20 assert_equals(window["existing-one"], 5); 21 }, "A named property must not be set if a property already exists"); 22 23 test(() => { 24 window["existing-undefined"] = undefined; 25 26 const img = document.createElement("img"); 27 img.setAttribute("id", "existing-undefined"); 28 document.body.appendChild(img); 29 30 assert_equals(window["existing-undefined"], undefined); 31 }, "A named property must not be set if a property already exists, even if undefined"); 32 33 test(() => { 34 const img = document.createElement("img"); 35 img.setAttribute("id", "user-val"); 36 document.body.appendChild(img); 37 38 window["user-val"] = 5; 39 40 assert_equals(window["user-val"], 5); 41 }, "If a property is occupied by a named property but then the user sets it, the user's value shadows it"); 42 43 test(() => { 44 const img = document.createElement("img"); 45 img.setAttribute("id", "undefined"); 46 document.body.appendChild(img); 47 48 /* eslint-disable no-void */ 49 assert_equals(undefined, void 0); 50 assert_equals(window.undefined, void 0); 51 /* eslint-enable no-void */ 52 }, "A named property must not be set if the property already exists in the proxy"); 53 </script>