Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

fix(patch): fix #708, modify the canPatchDescriptor logic when browser has no onreadystatechange #711

Merged
merged 1 commit into from
Apr 21, 2017

Conversation

JiaLiPassion
Copy link
Collaborator

Fix #708,

in jsdom, XMLHttpRequest has no onreadystatechange,
in zone.js canPatchDescriptor logic, zone.js use a fake onreadystatechange descriptor which only have a getter, and XMLHttpRequest will use this one, and prevent set onreadystatechange property.

so we need to use a workable onreadystatechange descriptor in this case.

return result;
// and if XMLHttpRequest.prototype.onreadystatechange is undefined,
// we should set a real desc instead a fake one
if (xhrDesc) {

Choose a reason for hiding this comment

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

It would probably make sense to just immediately return false if xhrDesc is falsy...

if (!xhrDesc) return;

this reduces nesting

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@DaveMBush , the function canPatchDescriptor will see whether zone.js can patch global object, if return false, zone.js will not patch DOM,XHR, so everything will not in zone. So we have to pick up a global object to try to patch and see the result.

Choose a reason for hiding this comment

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

OK.. I see the else now.

return result;
// and if XMLHttpRequest.prototype.onreadystatechange is undefined,
// we should set a real desc instead a fake one
if (xhrDesc) {

Choose a reason for hiding this comment

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

OK.. I see the else now.

@mhevery
Copy link
Contributor

mhevery commented Apr 10, 2017

could you rebase so that we can merge it in?

… browser don't provide onreadystatechange
@JiaLiPassion
Copy link
Collaborator Author

@mhevery , I have rebased the PR, please review.

@abner
Copy link

abner commented Apr 13, 2017

great! @JiaLiPassion I need this for tests with jest+jsdom.

For now i'm using a patch with your changes

@mhevery mhevery merged commit 7d4d07f into angular:master Apr 21, 2017
@JiaLiPassion JiaLiPassion deleted the xhr branch May 6, 2017 04:55
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants