tor-browser

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

Debugger-isCompilableUnit.js (1139B)


      1 load(libdir + "asserts.js");
      2 
      3 const bad_types = [
      4    2112,
      5    {geddy: "lee"},
      6    () => 1,
      7    [],
      8    Array
      9 ]
     10 
     11 // We only accept strings around here!
     12 for (var badType of bad_types) {
     13    assertThrowsInstanceOf(() => {
     14        Debugger.isCompilableUnit(badType);
     15    }, TypeError);
     16 }
     17 
     18 const compilable_units = [
     19   "wubba-lubba-dub-dub",
     20   "'Get Schwifty!'",
     21   "1 + 2",
     22   "function f(x) {}",
     23   "function x(...f,) {", // statements with bad syntax are always compilable
     24   "let x = 100",
     25   ";;;;;;;;",
     26   "",
     27   " ",
     28   "\n",
     29   "let x",
     30 ]
     31 
     32 const non_compilable_units = [
     33    "function f(x) {",
     34    "(...d) =>",
     35    "{geddy:",
     36    "{",
     37    "[1, 2",
     38    "[",
     39    "1 +",
     40    "let x =",
     41    "3 ==",
     42 ]
     43 
     44 for (var code of compilable_units) {
     45    assertEq(Debugger.isCompilableUnit(code), true);
     46 }
     47 
     48 for (var code of non_compilable_units) {
     49    assertEq(Debugger.isCompilableUnit(code), false);
     50 }
     51 
     52 // Supplying no arguments should throw a type error
     53 assertThrowsInstanceOf(() => {
     54    Debugger.isCompilableUnit();
     55 }, TypeError);
     56 
     57 // Supplying extra arguments should be fine
     58 assertEq(Debugger.isCompilableUnit("", 1, 2, 3, 4, {}, []), true);