window-properties.https.html (11206B)
1 <!doctype html> 2 <meta charset=utf-8> 3 <title>Properties of the window object</title> 4 <link rel="author" title="Ms2ger" href="mailto:Ms2ger@gmail.com"> 5 <link rel="help" href="http://ecma-international.org/ecma-262/5.1/#sec-15.1"> 6 <link rel="help" href="https://webidl.spec.whatwg.org/#interface-prototype-object"> 7 <link rel="help" href="https://webidl.spec.whatwg.org/#es-attributes"> 8 <link rel="help" href="https://webidl.spec.whatwg.org/#es-operations"> 9 <link rel="help" href="https://dom.spec.whatwg.org/#eventtarget"> 10 <link rel="help" href="https://html.spec.whatwg.org/multipage/#window"> 11 <link rel="help" href="https://html.spec.whatwg.org/multipage/#windowtimers"> 12 <link rel="help" href="https://html.spec.whatwg.org/multipage/#windowbase64"> 13 <link rel="help" href="https://html.spec.whatwg.org/multipage/#windowsessionstorage"> 14 <link rel="help" href="https://html.spec.whatwg.org/multipage/#windowlocalstorage"> 15 <link rel="help" href="https://dvcs.w3.org/hg/editing/raw-file/tip/editing.html#dom-window-getselection"> 16 <link rel="help" href="http://dev.w3.org/csswg/cssom/#widl-def-Window"> 17 <link rel="help" href="http://dev.w3.org/csswg/cssom-view/#widl-def-Window"> 18 <iframe id="iframe" style="visibility: hidden" src="/resources/blank.html"></iframe> 19 <iframe id="detachedIframe" style="visibility: hidden" src="/resources/blank.html"></iframe> 20 <script src="/resources/testharness.js"></script> 21 <script src="/resources/testharnessreport.js"></script> 22 <div id=log></div> 23 <script> 24 function assert_data_propdesc(pd, Writable, Enumerable, Configurable) { 25 assert_equals(typeof pd, "object"); 26 assert_equals(pd.writable, Writable); 27 assert_equals(pd.enumerable, Enumerable); 28 assert_equals(pd.configurable, Configurable); 29 } 30 function assert_accessor_propdesc(pd, hasSetter, Enumerable, Configurable) { 31 assert_equals(typeof pd, "object"); 32 assert_equals(typeof pd.get, "function"); 33 assert_true("set" in pd, 34 "Should always have a setter property on the property descriptor"); 35 assert_equals(typeof pd.set, hasSetter ? "function" : "undefined"); 36 assert_equals(pd.enumerable, Enumerable); 37 assert_equals(pd.configurable, Configurable); 38 } 39 40 var unforgeableAttributes = [ 41 "window", 42 "document", 43 "location", 44 "top" 45 ]; 46 47 var replaceableAttributes = [ 48 "self", 49 "locationbar", 50 "menubar", 51 "personalbar", 52 "scrollbars", 53 "statusbar", 54 "toolbar", 55 "frames", 56 "parent", 57 "external", 58 "length", 59 "origin", 60 61 // CSSOM-View 62 "screen", 63 "scrollX", 64 "scrollY", 65 "pageXOffset", 66 "pageYOffset", 67 "innerWidth", 68 "innerHeight", 69 "screenLeft", 70 "screenTop", 71 "screenX", 72 "screenY", 73 "outerWidth", 74 "outerHeight", 75 "devicePixelRatio", 76 ]; 77 78 var methods = [ 79 "close", 80 "stop", 81 "focus", 82 "blur", 83 "open", 84 "alert", 85 "confirm", 86 "prompt", 87 "print", 88 "postMessage", 89 90 // WindowBase64 91 "btoa", 92 "atob", 93 94 // WindowTimers 95 "setTimeout", 96 "clearTimeout", 97 "setInterval", 98 "clearInterval", 99 100 // Microtask queuing 101 "queueMicrotask", 102 103 // ImageBitmap 104 "createImageBitmap", 105 106 // HTML Editing APIs 107 "getSelection", 108 109 // CSSOM 110 "getComputedStyle", 111 112 // CSSOM-View 113 "matchMedia", 114 "moveBy", 115 "moveTo", 116 "resizeBy", 117 "resizeTo", 118 "scroll", 119 "scrollTo", 120 "scrollBy" 121 ]; 122 123 var readonlyAttributes = [ 124 "history", 125 "frameElement", 126 "navigator", 127 128 // WindowSessionStorage 129 "sessionStorage", 130 131 // WindowLocalStorage 132 "localStorage", 133 ]; 134 135 var writableAttributes = [ 136 "name", 137 "status", 138 "opener", 139 "onabort", 140 "onafterprint", 141 "onbeforeprint", 142 "onbeforeunload", 143 "onblur", 144 "oncancel", 145 "oncanplay", 146 "oncanplaythrough", 147 "onchange", 148 "onclick", 149 "onclose", 150 "oncontextmenu", 151 "oncuechange", 152 "ondblclick", 153 "ondrag", 154 "ondragend", 155 "ondragenter", 156 "ondragleave", 157 "ondragover", 158 "ondragstart", 159 "ondrop", 160 "ondurationchange", 161 "onemptied", 162 "onended", 163 "onerror", 164 "onfocus", 165 "onhashchange", 166 "oninput", 167 "oninvalid", 168 "onkeydown", 169 "onkeypress", 170 "onkeyup", 171 "onload", 172 "onloadeddata", 173 "onloadedmetadata", 174 "onloadstart", 175 "onmessage", 176 "onmousedown", 177 "onmousemove", 178 "onmouseout", 179 "onmouseover", 180 "onmouseup", 181 "onoffline", 182 "ononline", 183 "onpause", 184 "onplay", 185 "onplaying", 186 "onpagehide", 187 "onpageshow", 188 "onpopstate", 189 "onprogress", 190 "onratechange", 191 "onreset", 192 "onresize", 193 "onscroll", 194 "onseeked", 195 "onseeking", 196 "onselect", 197 "onstalled", 198 "onstorage", 199 "onsubmit", 200 "onsuspend", 201 "ontimeupdate", 202 "onunload", 203 "onvolumechange", 204 "onwaiting" 205 ]; 206 207 test(function() { 208 // 15.1.1 Value Properties of the Global Object 209 ["NaN", "Infinity", "undefined"].forEach(function(id) { 210 test(function() { 211 assert_true(id in window, id + " in window"); 212 assert_data_propdesc(Object.getOwnPropertyDescriptor(window, id), 213 false, false, false); 214 }, "Value Property: " + id); 215 }); 216 }, "Value Properties of the Global Object"); 217 test(function() { 218 // 15.1.2 Function Properties of the Global Object 219 ["eval", "parseInt", "parseFloat", "isNaN", "isFinite"].forEach(function(id) { 220 test(function() { 221 assert_true(id in window, id + " in window"); 222 assert_data_propdesc(Object.getOwnPropertyDescriptor(window, id), 223 true, false, true); 224 }, "Function Property: " + id); 225 }); 226 }, "Function Properties of the Global Object"); 227 test(function() { 228 // 15.1.3 URI Handling Function Properties 229 ["decodeURI", "decodeURIComponent", "encodeURI", "encodeURIComponent"].forEach(function(id) { 230 test(function() { 231 assert_true(id in window, id + " in window"); 232 assert_data_propdesc(Object.getOwnPropertyDescriptor(window, id), 233 true, false, true); 234 }, "URI Handling Function Property: " + id); 235 }); 236 }, "URI Handling Function Properties"); 237 test(function() { 238 // 15.1.4 Constructor Properties of the Global Object 239 ["Object", "Function", "Array", "String", "Boolean", "Number", "Date", 240 "RegExp", "Error", "EvalError", "RangeError", "ReferenceError", 241 "SyntaxError", "TypeError", "URIError"].forEach(function(id) { 242 test(function() { 243 assert_true(id in window, id + " in window"); 244 assert_data_propdesc(Object.getOwnPropertyDescriptor(window, id), 245 true, false, true); 246 }, "Constructor Property: " + id); 247 }); 248 }, "Constructor Properties of the Global Object"); 249 test(function() { 250 // 15.1.5 Other Properties of the Global Object 251 ["Math", "JSON"].forEach(function(id) { 252 test(function() { 253 assert_true(id in window, id + " in window"); 254 assert_data_propdesc(Object.getOwnPropertyDescriptor(window, id), 255 true, false, true); 256 }, "Other Property: " + id); 257 }); 258 }, "Other Properties of the Global Object"); 259 test(function() { 260 // EventTarget interface 261 ["addEventListener", "removeEventListener", "dispatchEvent"].forEach(function(id) { 262 test(function() { 263 var EventTargetProto = EventTarget.prototype; 264 assert_true(id in window, id + " in window"); 265 assert_equals(window[id], EventTargetProto[id]); 266 assert_data_propdesc(Object.getOwnPropertyDescriptor(EventTargetProto, id), 267 true, true, true); 268 assert_equals(Object.getOwnPropertyDescriptor(window, id), undefined); 269 }, "EventTarget method: " + id); 270 }); 271 }, "EventTarget interface"); 272 test(function() { 273 // Window interface 274 methods.forEach(function(id) { 275 test(function() { 276 var WindowProto = Window.prototype; 277 assert_true(id in window, id + " in window"); 278 assert_false(id in WindowProto, id + " in Window.prototype"); 279 assert_data_propdesc(Object.getOwnPropertyDescriptor(window, id), 280 true, true, true); 281 }, "Window method: " + id); 282 }); 283 readonlyAttributes.forEach(function(id) { 284 test(function() { 285 var WindowProto = Window.prototype; 286 assert_true(id in window, id + " in window"); 287 assert_false(id in WindowProto, id + " in Window.prototype"); 288 assert_accessor_propdesc(Object.getOwnPropertyDescriptor(window, id), 289 false, true, true); 290 }, "Window readonly attribute: " + id); 291 }); 292 writableAttributes.forEach(function(id) { 293 test(function() { 294 var WindowProto = Window.prototype; 295 assert_true(id in window, id + " in window"); 296 assert_false(id in WindowProto, id + " in Window.prototype"); 297 assert_accessor_propdesc(Object.getOwnPropertyDescriptor(window, id), 298 true, true, true); 299 }, "Window attribute: " + id); 300 }); 301 unforgeableAttributes.forEach(function(id) { 302 test(function() { 303 var WindowProto = Window.prototype; 304 assert_true(id in window, id + " in window"); 305 assert_false(id in WindowProto, id + " in Window.prototype"); 306 // location has a [PutForwards] extended attribute. 307 assert_accessor_propdesc(Object.getOwnPropertyDescriptor(window, id), 308 id === "location", true, false); 309 }, "Window unforgeable attribute: " + id); 310 }); 311 replaceableAttributes.forEach(function(id) { 312 test(function() { 313 var WindowProto = Window.prototype; 314 assert_true(id in window, id + " in window"); 315 assert_false(id in WindowProto, id + " in Window.prototype"); 316 assert_accessor_propdesc(Object.getOwnPropertyDescriptor(window, id), 317 true, true, true); 318 }, "Window replaceable attribute: " + id); 319 }); 320 }, "Window interface"); 321 test(function() { 322 assert_equals(window.constructor, Window); 323 assert_false(window.hasOwnProperty("constructor"), "window.constructor should not be an own property."); 324 assert_data_propdesc(Object.getOwnPropertyDescriptor(Window.prototype, "constructor"), 325 true, false, true); 326 }, "constructor"); 327 var selfReferentialAccessors = ['window', 'self', 'frames']; 328 // Test a variety of access methods 329 var detached = window.detachedIframe; 330 var detachedWindow = detached.contentWindow; 331 detachedIframe.remove(); 332 selfReferentialAccessors.forEach(function(id) { 333 test(function() { 334 assert_equals(eval(`window.${id}`), window); 335 assert_equals(window[id], window); 336 assert_equals(Object.getOwnPropertyDescriptor(window, id).get.call(window), window); 337 assert_equals(Reflect.get(window, id), window); 338 }, "Window readonly getter: " + id); 339 340 test(function() { 341 var globalObject = iframe.contentWindow; 342 var _eval = globalObject.eval; 343 assert_equals(globalObject.eval(`window.${id}`), globalObject); 344 assert_equals(globalObject[id], globalObject); 345 assert_equals(_eval(`Object.getOwnPropertyDescriptor(window, "${id}").get.call(window)`), globalObject); 346 assert_equals(_eval(`Reflect.get(window, "${id}")`), globalObject); 347 }, "Window readonly getter in iframe: " + id); 348 test(function() { 349 var globalObject = detachedWindow; 350 var _eval = globalObject.eval; 351 assert_equals(_eval(`window.${id}`), globalObject); 352 assert_equals(globalObject[id], globalObject); 353 assert_equals(_eval(`Object.getOwnPropertyDescriptor(window, "${id}").get.call(window)`), globalObject); 354 assert_equals(_eval(`Reflect.get(window, "${id}")`), globalObject); 355 }, "Window readonly getter in detached iframe: " + id); 356 }); 357 </script>