tor-browser

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

imagebitmap_structuredclone.js (1292B)


      1 function ok(expect, msg) {
      2  postMessage({ type: "status", status: !!expect, msg });
      3 }
      4 
      5 onmessage = function (event) {
      6  ok(!!event.data.bitmap1, "Get the 1st ImageBitmap from the main script.");
      7  ok(!!event.data.bitmap2, "Get the 2nd ImageBitmap from the main script.");
      8  ok(!!event.data.bitmap3, "Get the 3rd ImageBitmap from the main script.");
      9 
     10  // send the first original ImageBitmap back to the main-thread
     11  postMessage({ type: "bitmap1", bitmap: event.data.bitmap1 });
     12 
     13  // create a new ImageBitmap from the 2nd original ImageBitmap
     14  // and then send the newly created ImageBitmap back to the main-thread
     15  var promise = createImageBitmap(event.data.bitmap2);
     16  promise.then(
     17    function (bitmap) {
     18      ok(
     19        true,
     20        "Successfully create a new ImageBitmap from the 2nd original bitmap in worker."
     21      );
     22 
     23      // send the newly created ImageBitmap back to the main-thread
     24      postMessage({ type: "bitmap2", bitmap });
     25 
     26      // finish the test
     27      postMessage({ type: "finish" });
     28    },
     29    function () {
     30      ok(
     31        false,
     32        "Cannot create a new bitmap from the original bitmap in worker."
     33      );
     34    }
     35  );
     36 
     37  // send the third original ImageBitmap back to the main-thread
     38  postMessage({ type: "bitmap3", bitmap: event.data.bitmap3 });
     39 };