no-new-global.window.js (2972B)
1 // In an earlier version of the HTML Standard, document open steps created a 2 // new JavaScript realm and migrated the existing objects to use the new realm. 3 // Test that this no longer happens. 4 5 async_test(t => { 6 const frame = document.body.appendChild(document.createElement("iframe")); 7 // Ensure a load event gets dispatched to unblock testharness 8 t.add_cleanup(() => frame.remove()); 9 frame.src = "resources/global-variables-frame.html"; 10 frame.onload = t.step_func_done(() => { 11 assert_equals(frame.contentWindow.hey, "You", "precondition"); 12 frame.contentDocument.open(); 13 assert_equals(frame.contentWindow.hey, "You", "actual check"); 14 }); 15 }, "Obtaining a variable from a global whose document had open() invoked"); 16 17 function testIdentity(desc, frameToObject, frameToConstructor) { 18 async_test(t => { 19 const frame = document.body.appendChild(document.createElement("iframe")); 20 // Ensure a load event gets dispatched to unblock testharness 21 t.add_cleanup(() => frame.remove()); 22 frame.src = "/common/blank.html"; 23 frame.onload = t.step_func_done(() => { 24 const obj = frameToObject(frame); 25 frame.contentDocument.open(); 26 assert_equals(frameToObject(frame), obj); 27 }); 28 }, `${desc} maintains object identity through open()`); 29 30 async_test(t => { 31 const frame = document.body.appendChild(document.createElement("iframe")); 32 // Ensure a load event gets dispatched to unblock testharness 33 t.add_cleanup(() => frame.remove()); 34 frame.src = "/common/blank.html"; 35 frame.onload = t.step_func_done(() => { 36 const obj = frameToObject(frame); 37 const origProto = Object.getPrototypeOf(obj); 38 const origCtor = frameToConstructor(frame); 39 const sym = Symbol(); 40 obj[sym] = "foo"; 41 frame.contentDocument.open(); 42 assert_equals(frameToObject(frame)[sym], "foo"); 43 assert_true(frameToObject(frame) instanceof origCtor); 44 assert_equals(Object.getPrototypeOf(frameToObject(frame)), origProto); 45 assert_equals(frameToConstructor(frame), origCtor); 46 }); 47 }, `${desc} maintains its prototype and properties through open()`); 48 } 49 50 testIdentity("Document", frame => frame.contentDocument, frame => frame.contentWindow.Document); 51 testIdentity("WindowProxy", frame => frame.contentWindow, frame => frame.contentWindow.Window); 52 testIdentity("BarProp", frame => frame.contentWindow.locationbar, frame => frame.contentWindow.BarProp); 53 testIdentity("History", frame => frame.contentWindow.history, frame => frame.contentWindow.History); 54 testIdentity("localStorage", frame => frame.contentWindow.localStorage, frame => frame.contentWindow.Storage); 55 testIdentity("Location", frame => frame.contentWindow.location, frame => frame.contentWindow.Location); 56 testIdentity("sessionStorage", frame => frame.contentWindow.sessionStorage, frame => frame.contentWindow.Storage); 57 testIdentity("Navigator", frame => frame.contentWindow.navigator, frame => frame.contentWindow.Navigator);