tor-browser

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

script-text-modifications.html (1602B)


      1 <!doctype html>
      2 <head>
      3 <meta charset=utf-8>
      4 <title>Modify HTMLScriptElement's text after #prepare-a-script</title>
      5 <link rel=help href="https://html.spec.whatwg.org/multipage/scripting.html#prepare-a-script">
      6 <script src="/resources/testharness.js"></script>
      7 <script src="/resources/testharnessreport.js"></script>
      8 
      9 <script>
     10 var t = async_test("Modify inline script element's text " +
     11                   "after prepare-a-script before evaluation");
     12 
     13 function changeScriptText() {
     14  document.querySelector('#script0').textContent =
     15    't.unreached_func("This should not be evaluated")();';
     16 }
     17 
     18 t.step_timeout(changeScriptText, 500);
     19 </script>
     20 
     21 <!-- This is "a style sheet that is blocking scripts" and thus ... -->
     22 <link rel="stylesheet" href="/common/slow.py?pipe=trickle(d1)"></link>
     23 
     24 <!-- This inline script becomes a parser-blocking script, and thus
     25 the step_timeout is evaluated after script0 is inserted into DOM,
     26 prepare-a-script'ed, but before its evaluation. -->
     27 <script id="script0">
     28 t.step(() => {
     29    // When this is evaluated after the stylesheet is loaded,
     30    // script0's textContent is modified by the async script above,
     31    // but the evaluated script is still the original script here,
     32    // not what is overwritten, because "child text content" is taken in
     33    // #prepare-a-script and passed to "creating a classic script".
     34    var s = document.getElementById('script0');
     35    assert_equals(s.textContent,
     36                  't.unreached_func("This should not be evaluated")();',
     37                  "<script>'s textContent should be already modified");
     38    t.done();
     39  });
     40 </script>