tor-browser

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

worker-support.js (1377B)


      1 'use strict';
      2 
      3 importScripts('/resources/testharness.js');
      4 importScripts('/common/utils.js');
      5 importScripts('/common/dispatcher/dispatcher.js');
      6 
      7 // Only used by some tests.
      8 importScripts('/compute-pressure/resources/sync-pressure-observer.js');
      9 
     10 function send_message(message) {
     11  return new Promise((resolve, reject) => {
     12    const id = token();
     13    message.id = id;
     14 
     15    addEventListener('message', function listener(e) {
     16      if (!e.data.command || e.data.id !== id) {
     17        return;
     18      }
     19 
     20      removeEventListener('message', listener);
     21 
     22      if (e.data.command !== message.command) {
     23        reject(`Expected reply with command '${message.command}', got '${
     24            e.data.command}' instead`);
     25        return;
     26      }
     27      if (e.data.error) {
     28        reject(e.data.error);
     29        return;
     30      }
     31      resolve();
     32    });
     33 
     34    postMessage(message);
     35  });
     36 }
     37 
     38 function create_virtual_pressure_source(source, options = {}) {
     39  return send_message({command: 'create', params: [source, options]});
     40 }
     41 
     42 function remove_virtual_pressure_source(source) {
     43  return send_message({command: 'remove', params: [source]});
     44 }
     45 
     46 function update_virtual_pressure_source(source, state, estimate) {
     47  return send_message({command: 'update', params: [source, state, estimate]});
     48 }
     49 
     50 const uuid = new URLSearchParams(location.search).get('uuid');
     51 const executor = new Executor(uuid);