Skip to content
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

Merged
merged 3 commits into from
Dec 19, 2016
Merged

Conversation

patrickhulce
Copy link
Collaborator

@patrickhulce patrickhulce commented Dec 19, 2016

R: @brendankenny

Fixes evaluateAsync behavior when zone.js has mucked with Promise.
Adds zone.js to the smoke tests so regression won't happen again.

Addresses #1173

Fixes evaluateAsync behavior when [zone.js](https://github.com/angular/zone.js) has mucked with Promise.
Adds zone.js to the smoke tests so regression won't happen again.

Addresses #1177.
Copy link
Contributor

@ebidel ebidel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we bring in zones via npm?

https://www.npmjs.com/package/zone.js

@@ -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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

explicitly

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, done :)

@brendankenny
Copy link
Member

Should we bring in zones via npm?

Looks like you didn't have to modify @patrickhulce, so this could work this time?

@patrickhulce
Copy link
Collaborator Author

yeah true I didn't this time around, will fix

const thirdPartyPath = '../../../lighthouse-core/third_party';
absoluteFilePath = path.join(__dirname, `${thirdPartyPath}/promise-polyfill/promise.js`);
// We bring in an aggressive Promise polyfill (zone) to ensure we don't still fail.
const zonePath = '../../../node_modules/zone.js';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'../../../node_modules/`

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ebidel not sure what you're requesting here, to change zonePath to nodeModule path?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OH nvm. This is probably where it gets installed. Just looks funny from a reviewer's perspective :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All 👍

.then(_ => ${expression})
.catch(${wrapRuntimeEvalErrorInBrowser.toString()})
.then(resolve);
});
Copy link
Member

Choose a reason for hiding this comment

The 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 __nativePromise constructor is intact, not our earlier assumption that its prototype chain had also not been altered

Copy link
Member

@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. Nice detective work.

@brendankenny brendankenny merged commit 54fe456 into master Dec 19, 2016
@brendankenny brendankenny deleted the fix_promise_polyfill_again branch December 19, 2016 23:29
andrewrota pushed a commit to andrewrota/lighthouse that referenced this pull request Jan 13, 2017
…Chrome#1178)

* Fix `driver.evaluateAsync` behavior when [zone.js](https://github.com/angular/zone.js) has mucked with Promise.

* Add zone.js to the smoke tests so regression won't happen again.

* Remove old testing promise-polyfill
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants