File: no-new-global.window.js

package info (click to toggle)
firefox-esr 91.12.0esr-1~deb10u1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 3,375,668 kB
  • sloc: cpp: 5,762,032; javascript: 5,481,714; ansic: 3,121,206; python: 851,492; asm: 331,174; xml: 178,949; java: 155,554; sh: 63,704; makefile: 20,127; perl: 12,825; yacc: 4,583; cs: 3,846; objc: 3,026; lex: 1,720; exp: 762; pascal: 635; php: 436; lisp: 260; awk: 231; ruby: 103; sed: 53; sql: 46; csh: 45
file content (57 lines) | stat: -rw-r--r-- 2,972 bytes parent folder | download | duplicates (25)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// In an earlier version of the HTML Standard, document open steps created a
// new JavaScript realm and migrated the existing objects to use the new realm.
// Test that this no longer happens.

async_test(t => {
  const frame = document.body.appendChild(document.createElement("iframe"));
  // Ensure a load event gets dispatched to unblock testharness
  t.add_cleanup(() => frame.remove());
  frame.src = "resources/global-variables-frame.html";
  frame.onload = t.step_func_done(() => {
    assert_equals(frame.contentWindow.hey, "You", "precondition");
    frame.contentDocument.open();
    assert_equals(frame.contentWindow.hey, "You", "actual check");
  });
}, "Obtaining a variable from a global whose document had open() invoked");

function testIdentity(desc, frameToObject, frameToConstructor) {
  async_test(t => {
    const frame = document.body.appendChild(document.createElement("iframe"));
    // Ensure a load event gets dispatched to unblock testharness
    t.add_cleanup(() => frame.remove());
    frame.src = "/common/blank.html";
    frame.onload = t.step_func_done(() => {
      const obj = frameToObject(frame);
      frame.contentDocument.open();
      assert_equals(frameToObject(frame), obj);
    });
  }, `${desc} maintains object identity through open()`);

  async_test(t => {
    const frame = document.body.appendChild(document.createElement("iframe"));
    // Ensure a load event gets dispatched to unblock testharness
    t.add_cleanup(() => frame.remove());
    frame.src = "/common/blank.html";
    frame.onload = t.step_func_done(() => {
      const obj = frameToObject(frame);
      const origProto = Object.getPrototypeOf(obj);
      const origCtor = frameToConstructor(frame);
      const sym = Symbol();
      obj[sym] = "foo";
      frame.contentDocument.open();
      assert_equals(frameToObject(frame)[sym], "foo");
      assert_true(frameToObject(frame) instanceof origCtor);
      assert_equals(Object.getPrototypeOf(frameToObject(frame)), origProto);
      assert_equals(frameToConstructor(frame), origCtor);
    });
  }, `${desc} maintains its prototype and properties through open()`);
}

testIdentity("Document", frame => frame.contentDocument, frame => frame.contentWindow.Document);
testIdentity("WindowProxy", frame => frame.contentWindow, frame => frame.contentWindow.Window);
testIdentity("BarProp", frame => frame.contentWindow.locationbar, frame => frame.contentWindow.BarProp);
testIdentity("History", frame => frame.contentWindow.history, frame => frame.contentWindow.History);
testIdentity("localStorage", frame => frame.contentWindow.localStorage, frame => frame.contentWindow.Storage);
testIdentity("Location", frame => frame.contentWindow.location, frame => frame.contentWindow.Location);
testIdentity("sessionStorage", frame => frame.contentWindow.sessionStorage, frame => frame.contentWindow.Storage);
testIdentity("Navigator", frame => frame.contentWindow.navigator, frame => frame.contentWindow.Navigator);