Skip to content

Instantly share code, notes, and snippets.

@jimblandy
Last active August 29, 2015 14:16
Show Gist options
  • Save jimblandy/1fb70dec868f13d2500b to your computer and use it in GitHub Desktop.
Save jimblandy/1fb70dec868f13d2500b to your computer and use it in GitHub Desktop.
Notation:
f -> g "f calls g"
f -> (a -> b) g: "f calls g, supplying async parent stack a -> b"
Suppose we have:
/* in chrome */
1: function contentVisibleChromeImplementedInJS(...) {
2: var p0 = Promise((f0, r0) => { ... });
3: var p1 = p0.then(f1, r1);
return p1;
}
/* in content */
4: let p1 = contentVisibleChromeImplementedInJS(...)
5: var p2 = p1.then(f2, r2);
p0 captures '4 -> 2' as its saved stack
p1 captures '4 -> 3' as its saved stack.
p2 captures '5' as its saved stack.
Promise event handlers are invoked in their own event ticks: the event loop
calls some promise machinery which passes the value to the handler, so the
handler's true call stack looks like: eventLoop -> promiseImpl -> handler.
When invoking a resolution handler, a promise attaches its saved stack as the
handler call's async parent. p0's handler is f1, so p0 will call f1 with an
async parent of '4 -> 2'; the whole stack is thus: eventLoop -> promiseImpl ->
(4 -> 2) handler.
An error in f1 would capture the stack 'eventloop -> promiseImpl -> (4 -> 2) f1'
so if f1 creates and throws exception ex, ex.stack should be 'eventLoop -> promiseImpl -> (4 -> 2) f1'
unfiltered, or '4' filtered.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment