-
Notifications
You must be signed in to change notification settings - Fork 9.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Promise polyfill for zone #1178
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,15 +143,19 @@ class Driver { | |
); | ||
|
||
this.sendCommand('Runtime.evaluate', { | ||
// We need to wrap the raw expression for several purposes | ||
// We need to expliticly wrap the raw expression for several purposes: | ||
// 1. Ensure that the expression will be a native Promise and not a polyfill/non-Promise. | ||
// 2. Ensure that errors captured in the Promise are converted into plain-old JS Objects | ||
// 2. Ensure that errors in the expression are captured by the Promise. | ||
// 3. Ensure that errors captured in the Promise are converted into plain-old JS Objects | ||
// so that they can be serialized properly b/c JSON.stringify(new Error('foo')) === '{}' | ||
expression: `(function wrapInNativePromise() { | ||
const __nativePromise = window.__nativePromise || Promise; | ||
return __nativePromise.resolve() | ||
.then(_ => ${expression}) | ||
.catch(${wrapRuntimeEvalErrorInBrowser.toString()}); | ||
return new __nativePromise(function (resolve) { | ||
return __nativePromise.resolve() | ||
.then(_ => ${expression}) | ||
.catch(${wrapRuntimeEvalErrorInBrowser.toString()}) | ||
.then(resolve); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried a few permutations of this and it looks like this is about the only decent one that works :) Reason in #1173 (comment). For anyone following along, the nice thing about this form is that it lets the polyfill handle resolving to a value (or error), and then all we have to assume is that our |
||
}())`, | ||
includeCommandLineAPI: true, | ||
awaitPromise: true, | ||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
explicitly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops, done :)