tor-browser

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

observable-map.window.js (1304B)


      1 async function loadIframeAndReturnContentWindow() {
      2   // Create and attach an iframe.
      3  const iframe = document.createElement('iframe');
      4  const iframeLoadPromise = new Promise((resolve, reject) => {
      5    iframe.onload = resolve;
      6    iframe.onerror = reject;
      7  });
      8  document.body.append(iframe);
      9  await iframeLoadPromise;
     10  return iframe.contentWindow;
     11 }
     12 
     13 promise_test(async t => {
     14  const contentWin = await loadIframeAndReturnContentWindow();
     15 
     16  window.results = [];
     17 
     18  contentWin.eval(`
     19    const parentResults = parent.results;
     20 
     21    const source = new Observable(subscriber => {
     22      // Detach the document before calling next().
     23      window.frameElement.remove();
     24 
     25      // This invokes the map() operator's internal observer's next steps,
     26      // which at least in Chromium, must have a special "context is detached"
     27      // check to early-return, so as to not crash before invoking the "mapper"
     28      // callback supplied to the map() operator.
     29      subscriber.next(1);
     30    });
     31 
     32    source.map(value => {
     33      parentResults.push(value);
     34    }).subscribe(v => parentResults.push(v));
     35  `);
     36 
     37  // If we got here, we didn't crash! Let's also check that `results` is empty.
     38  assert_array_equals(results, []);
     39 }, "map()'s internal observer's next steps do not crash in a detached document");