tor-browser

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

common.js (2060B)


      1 (window => {
      2  // Both a controlling side and a receiving one must share the same Stash ID to
      3  // transmit data from one to the other. On the other hand, due to polling mechanism
      4  // which cleans up a stash, stashes in both controller-to-receiver direction
      5  // and one for receiver-to-controller are necessary.
      6  window.stashIds = {
      7    toController: '0c382524-5738-4df0-837d-4f53ea8addc2',
      8    toReceiver: 'a9618cd1-ca2b-4155-b7f6-630dce953c44'
      9  }
     10 
     11  // handle a test result received from a receiving page
     12  const parseValue = value => {
     13    let r;
     14 
     15    // String
     16    if (r = value.match(/^(\(string\)\s+)?"(.*)"$/))
     17      return r[2];
     18    // Object
     19    else if (r = value.match(/^(\(object\)\s+)?object\s+"\[object\s+(.*)\]"$/))
     20      return window[r[2]].prototype;
     21    // Number, boolean, null, undefined
     22    else {
     23      if (r = value.match(/^(\(\S+\)\s+)?(\S+)$/)) {
     24        try {
     25          return JSON.parse(r[2]);
     26        } catch(e) {
     27          return value;
     28        }
     29      }
     30      else
     31        return value;
     32    }
     33  };
     34 
     35  window.parseResult = message => {
     36    let r = message.match(/^(assert_.*):\s+(.*)$/);
     37    if (r) {
     38      const assertion = r[1];
     39      const body = r[2];
     40      let args;
     41      switch (assertion) {
     42        case 'assert_equals':
     43          if (r = body.match(/^((.*)\s+)?expected\s+((\(\S*\)\s+)?(\S+|(\S+\s+)?\".*\"))\s+but\s+got\s+((\(\S*\)\s+)?(\S+|(\S+\s+)?\".*\"))$/))
     44            args = [parseValue(r[7]), parseValue(r[3]), r[2]];
     45          break;
     46        case 'assert_true':
     47          if (r = body.match(/^((.*)\s+)?expected\s+(true|false)\s+got\s+(\S+|(\S+\s+)?\".*\")$/))
     48            args = [parseValue(r[4]), r[2]];
     49          break;
     50        case 'assert_unreached':
     51          if (r = body.match(/^((.*)\s+)?Reached\s+unreachable\s+code$/))
     52            args = [r[2]];
     53          break;
     54      }
     55      if (args) {
     56        window[assertion](args[0], args[1], args[2]);
     57        return;
     58      }
     59    }
     60    // default
     61    assert_unreached('Test result received from a receiving user agent: ' + message + ': ');
     62  };
     63 })(window);