tor-browser

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

moving-between-documents-during-evaluation.html (2240B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8">
      3 <title>Moving script elements between documents during evaluation</title>
      4 <link rel="help" href="https://html.spec.whatwg.org/multipage/#execute-the-script-block">
      5 
      6 <script src="/resources/testharness.js"></script>
      7 <script src="/resources/testharnessreport.js"></script>
      8 
      9 <body>
     10 <script id="outerScript">
     11 "use strict";
     12 
     13 async_test(t => {
     14  const outerScript = document.querySelector('#outerScript');
     15  assert_equals(document.currentScript, outerScript);
     16 
     17  const innerScript = document.createElement('script');
     18  window.innerScript = innerScript;
     19 
     20  window.innerScriptEvaluated = false;
     21  window.anotherDocument = null;
     22 
     23  innerScript.innerText = `
     24    window.innerScriptEvaluated = true;
     25    const innerScript = window.innerScript;
     26    assert_equals(document.currentScript, innerScript,
     27        '[1] Before move: currentScript of source Document');
     28    assert_equals(innerScript.ownerDocument, document,
     29        '[1] Before move: ownerDocument');
     30 
     31    window.anotherDocument = document.implementation.createHTMLDocument();
     32    window.anotherDocument.body.appendChild(innerScript);
     33 
     34    assert_equals(innerScript.ownerDocument, anotherDocument,
     35        '[2] Just after move: ownerDocument');
     36    assert_equals(document.currentScript, innerScript,
     37        '[2] Just after move: currentScript of source Document');
     38    assert_equals(anotherDocument.currentScript, null,
     39        '[2] Just after move: currentScript of destination Document');
     40  `;
     41 
     42  document.body.appendChild(innerScript);
     43  assert_true(window.innerScriptEvaluated,
     44      'Inner script should be evaluated synchronously');
     45 
     46  assert_equals(document.currentScript, outerScript,
     47      '[3] After inner script: currentScript of source Document');
     48  assert_equals(window.anotherDocument.currentScript, null,
     49      '[3] After inner script: currentScript of destination Document');
     50 
     51  t.step_timeout(() => {
     52    assert_equals(document.currentScript, null,
     53        '[4] After outer script: currentScript of source Document');
     54    assert_equals(anotherDocument.currentScript, null,
     55        '[4] After outer script: currentScript of destination Document');
     56    t.done();
     57  }, 0);
     58 }, 'Script moved between documents during evaluation');
     59 </script>