Closed Bug 1543225 Opened 5 years ago Closed 4 years ago

[jsdbg2] Debugger doesn't distinguish implicit await when an async function returns (just calls onPop twice)

Categories

(Core :: JavaScript Engine, defect, P3)

defect

Tracking

()

RESOLVED FIXED

People

(Reporter: jimb, Unassigned)

References

Details

A Debugger.Frame's onPop handler gets called twice for the return of an async generator. The following program:

var g = newGlobal({ newCompartment: true });
g.eval(`async function* ag() { return 42; }`);

var dbg = new Debugger(g);
dbg.onEnterFrame = f => {
  print(`onEnterFrame: ${f.callee.name}`);
  f.onPop = function (k) {
    print(`onPop: ${uneval(k)}`);
  };
}
(async function () {
  const a = [];
  for await (let item of g.ag()) {
    a.push(item);
  }
  return a;
})().then(v => {
  print(`resolved to ${uneval(v)}`);
});

produces the following output:

onEnterFrame: ag
onPop: ({return:{}})
onEnterFrame: ag
onPop: ({return:42})
onEnterFrame: ag
onPop: ({return:42})
resolved to []

I would have expected to see 42 only once.

Type: task → defect

return in async generators performs an implicit await per spec, basically as if return await 42 had been written: https://tc39.github.io/ecma262/#sec-return-statement-runtime-semantics-evaluation

So I guess the additional onEnterFrame/onPop pair is actually the implicit await.

Ah, okay, great. I was hoping it was something like that. I'm adding more detailed information to completion values in bug 1470558, so that should let consumers distinguish the implicit await from the final return.

Summary: [jsdbg2] Debugger reports returns twice for async generators → [jsdbg2] Debugger doesn't distinguish implicit await when an async function returns (just calls onPop twice)
Depends on: 1470558
Priority: -- → P3

Is this good to close?

Flags: needinfo?(jimb)

Yes, I think we can close this.

Status: NEW → RESOLVED
Closed: 4 years ago
Flags: needinfo?(jimb)
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.