tor-browser

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

test_Cu_reportError_column.js (1392B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 add_task(async function() {
      6  // Passing an Error with JSErrorReport to Cu.reportError should preserve
      7  // the columnNumber.
      8 
      9  const tests = [
     10    // Parser error.
     11    {
     12      throwError() {
     13        eval("a b");
     14      },
     15      messagePattern: /unexpected token/,
     16      lineNumber: 1,
     17      columnNumber: 3,
     18    },
     19    // Runtime error.
     20    {
     21      throwError() { // line = 21
     22        not_found();
     23      },
     24      messagePattern: /is not defined/,
     25      lineNumber: 22,
     26      columnNumber: 9,
     27    },
     28  ];
     29 
     30  for (const test of tests) {
     31    const { promise, resolve } = Promise.withResolvers();
     32    const listener = {
     33      observe(msg) {
     34        if (msg instanceof Ci.nsIScriptError) {
     35          resolve(msg);
     36        }
     37      }
     38    };
     39 
     40    try {
     41      Services.console.registerListener(listener);
     42 
     43      try {
     44        test.throwError();
     45      } catch (e) {
     46        Cu.reportError(e);
     47      }
     48 
     49      const msg = await promise;
     50      Assert.stringMatches(msg.errorMessage, test.messagePattern);
     51      Assert.equal(msg.lineNumber, test.lineNumber);
     52      Assert.equal(msg.columnNumber, test.columnNumber);
     53    } finally {
     54      Services.console.unregisterListener(listener);
     55    }
     56  }
     57 });