forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1470558: Distinguish yields and awaits in completion values. r=jo…
…rendorff This patch introduces a new type to the debugger, `js::Completion`, describing how a given JavaScript evaluation completed. It's a wrapper around a `Variant` with alternatives: - Return - Throw - Terminate - InitialYield (the initial yield of a generator, returning the generator object) - Yield (subsequent yields of a generator) - Await (both initial and subsequent) We can construct a `Completion` in two ways: - From any JavaScript operation's result (a success value and a context carrying an exception value and stack). This only distinguishes between Return, Throw, and Terminate. - From a stack frame that's about to be popped. This allows us to identify yields and awaits. Given a `Completion` we can construct Debugger API 'completion values' to pass to hooks, as well as the resumption/value/context states that tell the engine how to continue execution. Within Debugger itself, `Completion` values are a convenient place to gather up various bits of logic: identifying suspensions, chaining resumption values from multiple Debugger hooks, and so on. Although `Completion` should be used throughout Debugger, this patch only uses it for the `onPop` hook. Subsequent patches in the series will apply it to other cases where Debugger can invoke JavaScript. Differential Revision: https://phabricator.services.mozilla.com/D24997 --HG-- extra : moz-landing-system : lando
- Loading branch information
Jim Blandy
committed
Jul 6, 2019
1 parent
b515c7b
commit cd56198
Showing
10 changed files
with
622 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Completion values for generators report yields and initial yields. | ||
|
||
load(libdir + "asserts.js"); | ||
load(libdir + 'match.js'); | ||
load(libdir + 'match-debugger.js'); | ||
const { Pattern } = Match; | ||
const { OBJECT_WITH_EXACTLY: X } = Pattern; | ||
|
||
const g = newGlobal({ newCompartment: true }); | ||
g.eval(` | ||
function* f() { | ||
yield "yielding"; | ||
return "returning"; | ||
} | ||
`); | ||
|
||
const dbg = new Debugger(g); | ||
const completions = []; | ||
dbg.onEnterFrame = frame => { | ||
frame.onPop = completion => { | ||
completions.push(completion); | ||
}; | ||
}; | ||
|
||
assertDeepEq([... g.f()], ["yielding"]); | ||
print(uneval(completions)); | ||
Pattern([ | ||
X({ | ||
return: new DebuggerObjectPattern("Generator", {}), | ||
yield: true, | ||
initial: true | ||
}), | ||
X({ | ||
return: new DebuggerObjectPattern("Object", { value: "yielding", done: false }), | ||
yield: true | ||
}), | ||
X({ | ||
return: new DebuggerObjectPattern("Object", { value: "returning", done: true }) | ||
}), | ||
]).assert(completions); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.