tor-browser

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

isAsyncFunction-isGeneratorFunction.js (2187B)


      1 // Debugger.Script.prototype.isAsyncFunction, Debugger.Object.prototype.isAsyncFunction,
      2 // Debugger.Script.prototype.isGeneratorFunction, Debugger.Object.prototype.isGeneratorFunction
      3 
      4 var g = newGlobal({newCompartment: true});
      5 var dbg = new Debugger();
      6 var gDO = dbg.addDebuggee(g);
      7 g.non_debuggee = function non_debuggee () {}
      8 
      9 function checkExpr(expr, { isAsync, isGenerator })
     10 {
     11  print("Evaluating: " + JSON.stringify(expr));
     12  let completion = gDO.executeInGlobal(expr);
     13  if (completion.throw)
     14    throw completion.throw.unsafeDereference();
     15 
     16  let fn = completion.return;
     17  assertEq(fn.isAsyncFunction, isAsync);
     18  assertEq(fn.isGeneratorFunction, isGenerator);
     19 
     20  // The Debugger.Object and its Debugger.Script should always agree.
     21  if (fn.script) {
     22    assertEq(fn.isAsyncFunction, fn.script.isAsyncFunction);
     23    assertEq(fn.isGeneratorFunction, fn.script.isGeneratorFunction);
     24  }
     25 }
     26 
     27 checkExpr('({})', { isAsync: undefined, isGenerator: undefined });
     28 checkExpr('non_debuggee', { isAsync: undefined, isGenerator: undefined });
     29 checkExpr('(function(){})', { isAsync: false, isGenerator: false });
     30 checkExpr('(function*(){})', { isAsync: false, isGenerator: true });
     31 checkExpr('(async function snerf(){})', { isAsync: true, isGenerator: false });
     32 checkExpr('(async function* omlu(){})', { isAsync: true, isGenerator: true });
     33 
     34 checkExpr('new Function("1+2")', { isAsync: false, isGenerator: false });
     35 checkExpr('Object.getPrototypeOf(function*(){}).constructor("1+2")',
     36          { isAsync: false, isGenerator: true });
     37 checkExpr('Object.getPrototypeOf(async function(){}).constructor("1+2")',
     38          { isAsync: true, isGenerator: false });
     39 checkExpr('Object.getPrototypeOf(async function*(){}).constructor("1+2")',
     40          { isAsync: true, isGenerator: true });
     41 
     42 // Check eval scripts.
     43 function checkFrame(expr, type)
     44 {
     45  var log = '';
     46  dbg.onDebuggerStatement = function(frame) {
     47    log += 'd';
     48    assertEq(frame.type, type);
     49    assertEq(frame.script.isAsyncFunction, false);
     50    assertEq(frame.script.isGeneratorFunction, false);
     51  }
     52  gDO.executeInGlobal(expr);
     53  assertEq(log, 'd');
     54 }
     55 
     56 checkFrame('debugger;', 'global');
     57 checkFrame('eval("debugger;")', 'eval');