tor-browser

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

default-constructor-position.js (1669B)


      1 // Test default class constructors have reasonable lineno/column values
      2 
      3 const source = `
      4  /* GeneralParser::synthesizeConstructor */ class A {
      5  }
      6 
      7  /* GeneralParser::synthesizeConstructor (derived) */ class B extends A {
      8  }
      9 
     10  /* GeneralParser::synthesizeConstructor */ class C {
     11    field = "default value";
     12  }
     13 
     14  /* GeneralParser::synthesizeConstructor (derived) */ class D extends A {
     15    field = "default value";
     16  }
     17 `;
     18 
     19 // Use the Debugger API to introspect the line / column.
     20 let d = new Debugger();
     21 let g = newGlobal({newCompartment: true})
     22 let gw = d.addDebuggee(g);
     23 
     24 g.evaluate(source);
     25 
     26 function getStartLine(name) {
     27  return gw.makeDebuggeeValue(g.eval(name)).script.startLine;
     28 }
     29 
     30 function getStartColumn(name) {
     31  return gw.makeDebuggeeValue(g.eval(name)).script.startColumn;
     32 }
     33 
     34 function getSourceStart(name) {
     35  return gw.makeDebuggeeValue(g.eval(name)).script.sourceStart;
     36 }
     37 
     38 function getSourceLength(name) {
     39  return gw.makeDebuggeeValue(g.eval(name)).script.sourceLength;
     40 }
     41 
     42 // Compute the expected line/column from source.
     43 matches = "";
     44 lineno = 0;
     45 for (text of source.split("\n")) {
     46  lineno++;
     47 
     48  column = text.indexOf("class");
     49  if (column < 0) {
     50    continue;
     51  }
     52 
     53  className = text[column + 6];
     54  matches += className;
     55 
     56  // Check lineno/column.
     57  assertEq(getStartLine(className), lineno);
     58  assertEq(getStartColumn(className), column + 1);
     59 
     60  // Check sourceStart/sourceEnd.
     61  offset = source.indexOf("class " + className)
     62  length = source.substring(offset).indexOf("}") + 1
     63  assertEq(getSourceStart(className), offset)
     64  assertEq(getSourceLength(className), length)
     65 }
     66 
     67 // Sanity check to did actual matches
     68 assertEq(matches, "ABCD");