tor-browser

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

test_immutable_arraybufferview.html (2958B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=1952253
      5 -->
      6 <head>
      7  <meta charset="utf-8">
      8  <title>Test for immutable ArrayBufferViews</title>
      9  <script src="/tests/SimpleTest/SimpleTest.js"></script>
     10  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     11 </head>
     12 <body>
     13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1952253">Mozilla Bug 1952253</a>
     14 <p id="display"></p>
     15 <div id="content" style="display: none">
     16 
     17 </div>
     18 <pre id="test">
     19 </pre>
     20  <script type="application/javascript">
     21    /* global TestFunctions */
     22 
     23    function checkThrowsImmutable(f) {
     24      let ex;
     25      try{
     26        f();
     27        ok(false, "Should have thrown!");
     28      } catch (e) {
     29        ex = e;
     30      }
     31      ok(ex.toString().includes("immutable ArrayBuffer or ArrayBufferView"), "Got exception: " + ex);
     32    }
     33 
     34    add_task(async function test_immutable_arraybuffer_views() {
     35      await SpecialPowers.pushPrefEnv({set: [["dom.expose_test_interfaces", true]]});
     36      let test = new TestFunctions();
     37 
     38      let ab = new ArrayBuffer(16).transferToImmutable();
     39      checkThrowsImmutable(() => test.testNotAllowShared(ab));
     40      checkThrowsImmutable(() => test.testAllowShared(ab));
     41      checkThrowsImmutable(() => test.testDictWithAllowShared({arrayBuffer: ab}));
     42      checkThrowsImmutable(() => test.testUnionOfBufferSource(ab));
     43      checkThrowsImmutable(() => { test.arrayBuffer = ab; });
     44      checkThrowsImmutable(() => { test.allowSharedArrayBuffer = ab; });
     45      checkThrowsImmutable(() => { test.sequenceOfArrayBuffer = [ab]; });
     46      checkThrowsImmutable(() => { test.sequenceOfAllowSharedArrayBuffer = [ab]; });
     47 
     48      let ta = new Int8Array(ab);
     49      checkThrowsImmutable(() => test.testNotAllowShared(ta));
     50      checkThrowsImmutable(() => test.testAllowShared(ta));
     51      checkThrowsImmutable(() => test.testDictWithAllowShared({arrayBufferView: ta}));
     52      checkThrowsImmutable(() => test.testUnionOfBufferSource(ta));
     53      checkThrowsImmutable(() => { test.arrayBufferView = ta; });
     54      checkThrowsImmutable(() => { test.allowSharedArrayBufferView = ta; });
     55      checkThrowsImmutable(() => { test.sequenceOfArrayBufferView = [ta]; });
     56      checkThrowsImmutable(() => { test.sequenceOfAllowSharedArrayBufferView = [ta]; });
     57 
     58      let dv = new DataView(ab);
     59      checkThrowsImmutable(() => test.testNotAllowShared(dv));
     60      checkThrowsImmutable(() => test.testAllowShared(dv));
     61      checkThrowsImmutable(() => test.testDictWithAllowShared({arrayBufferView: dv}));
     62      checkThrowsImmutable(() => test.testUnionOfBufferSource(dv));
     63      checkThrowsImmutable(() => { test.arrayBufferView = dv; });
     64      checkThrowsImmutable(() => { test.allowSharedArrayBufferView = dv; });
     65      checkThrowsImmutable(() => { test.sequenceOfArrayBufferView = [dv]; });
     66      checkThrowsImmutable(() => { test.sequenceOfAllowSharedArrayBufferView = [dv]; });
     67    });
     68  </script>
     69 </body>
     70 </html>