tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

window-indexed-properties-strict.html (3159B)


      1 <!doctype html>
      2 <meta charset=utf-8>
      3 <title>Indexed properties of the window object (strict mode)</title>
      4 <link rel="author" title="Ms2ger" href="ms2ger@gmail.com">
      5 <link rel="help" href="https://html.spec.whatwg.org/multipage/#window">
      6 <link rel="help" href="https://html.spec.whatwg.org/multipage/#dom-window-item">
      7 <link rel="help" href="https://webidl.spec.whatwg.org/#getownproperty">
      8 <link rel="help" href="https://webidl.spec.whatwg.org/#defineownproperty">
      9 <script src="/resources/testharness.js"></script>
     10 <script src="/resources/testharnessreport.js"></script>
     11 <div id=log></div>
     12 <iframe></iframe>
     13 <script>
     14 test(function() {
     15  "use strict";
     16  assert_false("-1" in window, "-1 not in window");
     17  assert_equals(window[-1], undefined);
     18  window[-1] = "foo";
     19  assert_equals(window[-1], "foo");
     20 });
     21 test(function() {
     22  "use strict";
     23  assert_throws_js(TypeError, function() {
     24    window[0] = "foo";
     25  });
     26  assert_throws_js(TypeError, () => Object.defineProperty(window, 0, { value: "bar" }))
     27  assert_throws_js(TypeError, () => Object.defineProperty(window, 0, { get() { return "baz" } }))
     28  assert_throws_js(TypeError, () => Object.defineProperty(window, 0, { set(v) { return "qux" } }))
     29  assert_equals(window[0],
     30                document.getElementsByTagName("iframe")[0].contentWindow);
     31  assert_throws_js(TypeError, () => delete window[0]);
     32 });
     33 test(function() {
     34  "use strict";
     35  assert_throws_js(TypeError, function() {
     36    window[1] = "foo";
     37  });
     38  assert_throws_js(TypeError, () => Object.defineProperty(window, 1, { value: "bar" }))
     39  assert_throws_js(TypeError, () => Object.defineProperty(window, 1, { get() { return "baz" } }))
     40  assert_throws_js(TypeError, () => Object.defineProperty(window, 1, { set(v) { return "qux" } }))
     41  assert_equals(window[1], undefined);
     42  assert_equals(Object.getOwnPropertyDescriptor(window, 1), undefined);
     43  assert_equals(delete window[1], true);
     44 });
     45 test(function() {
     46  "use strict";
     47  assert_throws_js(TypeError, () => { window[4294967294] = 1; });
     48  assert_false(Reflect.set(window, 4294967294, 2));
     49  assert_false(Reflect.defineProperty(window, 4294967294, { value: 3 }));
     50  assert_throws_js(TypeError, () => Object.defineProperty(window, 4294967294, { get: () => 4 }));
     51  assert_equals(window[4294967294], undefined);
     52  assert_false(4294967294 in window);
     53  assert_true(delete window[4294967294]);
     54 }, "Borderline numeric key: 2 ** 32 - 2 is an index (strict mode)");
     55 test(function() {
     56  "use strict";
     57  window[4294967295] = 1;
     58  assert_equals(window[4294967295], 1);
     59  assert_true(Reflect.set(window, 4294967295, 2));
     60  assert_equals(window[4294967295], 2);
     61  assert_true(Reflect.defineProperty(window, 4294967295, { value: 3 }));
     62  assert_equals(window[4294967295], 3);
     63  Object.defineProperty(window, 4294967295, { get: () => 4 });
     64  assert_equals(window[4294967295], 4);
     65  assert_true(delete window[4294967295]);
     66  assert_false(4294967295 in window);
     67 }, "Borderline numeric key: 2 ** 32 - 1 is not an index (strict mode)");
     68 test(function() {
     69  "use strict";
     70  var proto = Window.prototype;
     71  [-1, 0, 1].forEach(function(idx) {
     72    assert_false(idx in proto, idx + " in proto");
     73  });
     74 });
     75 </script>