tor-browser

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

console-label-conversion.any.js (972B)


      1 // META: global=window,dedicatedworker,shadowrealm
      2 
      3 "use strict";
      4 // https://console.spec.whatwg/org/#counting
      5 // https://console.spec.whatwg/org/#timing
      6 
      7 const methods = ['count', 'countReset', 'time', 'timeLog', 'timeEnd'];
      8 
      9 for (const method of methods) {
     10  test(() => {
     11    let labelToStringCalled = false;
     12 
     13    console[method]({
     14      toString() {
     15        labelToStringCalled = true;
     16      }
     17    });
     18 
     19    assert_true(labelToStringCalled, `${method}() must call toString() on label when label is an object`);
     20  }, `console.${method}()'s label gets converted to string via label.toString() when label is an object`);
     21 
     22  test(() => {
     23    assert_throws_js(Error, () => {
     24      console[method]({
     25        toString() {
     26          throw new Error('conversion error');
     27        }
     28      });
     29    }, `${method} must re-throw any exceptions thrown by label.toString() conversion`);
     30  }, `console.${method}() throws exceptions generated by erroneous label.toString() conversion`);
     31 }