tor-browser

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

field-initializer-position.js (1591B)


      1 // Test class field initializers have reasonable lineno/column values
      2 
      3 gczeal(0);
      4 
      5 // Use the Debugger API to introspect the line / column.
      6 let d = new Debugger();
      7 let g = newGlobal({newCompartment: true})
      8 let gw = d.addDebuggee(g);
      9 
     10 let source = `
     11    let A = "A";
     12    let B = "B";
     13 
     14    class C {
     15        // START----v
     16                    'field_str';
     17                    'field_str_with_init' = 1;
     18                    [A];
     19                    [B] = 2;
     20             static x;
     21             static y = 3;
     22             static [A + "static"];
     23             static [B + "static"] = 4;
     24        // END
     25    }
     26 `;
     27 
     28 let NumInitializers = 8;
     29 
     30 // Compute (1-based) line number of 'START' and 'END' markers.
     31 let START = source.split('\n').findIndex(x => x.includes("START")) + 1;
     32 let END   = source.split('\n').findIndex(x => x.includes("END")) + 1;
     33 assertEq(END - START - 1, NumInitializers);
     34 
     35 // Use debugger to locate internal field-initializer scripts.
     36 g.evaluate(source);
     37 let scripts = d.findScripts()
     38               .filter(script => (script.startLine >= START &&
     39                                  script.startLine <= END));
     40 scripts.sort((x, y) => (x.sourceStart - y.sourceStart))
     41 
     42 for (var i = 0; i < NumInitializers; ++i) {
     43    let script = scripts[i];
     44    let lineText = source.split('\n')[START + i];
     45 
     46    // Check the initializer lambda has expected line/column
     47    assertEq(script.startLine, START + 1 + i);
     48    assertEq(script.startColumn, 21);
     49 
     50    // Check that source length matches expectations.
     51    assertEq(script.startColumn + script.sourceLength + ';'.length, lineText.length + 1);
     52 }