summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/debug/isAsyncFunction-isGeneratorFunction.js
blob: fd2df0277b45f6722c615325c9c91e3ab83c95f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Debugger.Script.prototype.isAsyncFunction, Debugger.Object.prototype.isAsyncFunction,
// Debugger.Script.prototype.isGeneratorFunction, Debugger.Object.prototype.isGeneratorFunction

var g = newGlobal({newCompartment: true});
var dbg = new Debugger();
var gDO = dbg.addDebuggee(g);
g.non_debuggee = function non_debuggee () {}

function checkExpr(expr, { isAsync, isGenerator })
{
  print("Evaluating: " + JSON.stringify(expr));
  let completion = gDO.executeInGlobal(expr);
  if (completion.throw)
    throw completion.throw.unsafeDereference();

  let fn = completion.return;
  assertEq(fn.isAsyncFunction, isAsync);
  assertEq(fn.isGeneratorFunction, isGenerator);

  // The Debugger.Object and its Debugger.Script should always agree.
  if (fn.script) {
    assertEq(fn.isAsyncFunction, fn.script.isAsyncFunction);
    assertEq(fn.isGeneratorFunction, fn.script.isGeneratorFunction);
  }
}

checkExpr('({})', { isAsync: undefined, isGenerator: undefined });
checkExpr('non_debuggee', { isAsync: undefined, isGenerator: undefined });
checkExpr('(function(){})', { isAsync: false, isGenerator: false });
checkExpr('(function*(){})', { isAsync: false, isGenerator: true });
checkExpr('(async function snerf(){})', { isAsync: true, isGenerator: false });
checkExpr('(async function* omlu(){})', { isAsync: true, isGenerator: true });

checkExpr('new Function("1+2")', { isAsync: false, isGenerator: false });
checkExpr('Object.getPrototypeOf(function*(){}).constructor("1+2")',
          { isAsync: false, isGenerator: true });
checkExpr('Object.getPrototypeOf(async function(){}).constructor("1+2")',
          { isAsync: true, isGenerator: false });
checkExpr('Object.getPrototypeOf(async function*(){}).constructor("1+2")',
          { isAsync: true, isGenerator: true });

// Check eval scripts.
function checkFrame(expr, type)
{
  var log = '';
  dbg.onDebuggerStatement = function(frame) {
    log += 'd';
    assertEq(frame.type, type);
    assertEq(frame.script.isAsyncFunction, false);
    assertEq(frame.script.isGeneratorFunction, false);
  }
  gDO.executeInGlobal(expr);
  assertEq(log, 'd');
}

checkFrame('debugger;', 'global');
checkFrame('eval("debugger;")', 'eval');