Skip to content
This repository was 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
mhevery merged 1 commit intoangular:masterfrom
JiaLiPassion:xhr
Apr 21, 2017
Merged

fix(patch): fix #708, modify the canPatchDescriptor logic when browser has no onreadystatechange#711
mhevery merged 1 commit intoangular:masterfrom
JiaLiPassion:xhr

Conversation

@JiaLiPassion
Copy link
Copy Markdown
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) {
Copy link
Copy Markdown

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
Copy Markdown
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.

Copy link
Copy Markdown

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) {
Copy link
Copy Markdown

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
Copy Markdown
Contributor

mhevery commented Apr 10, 2017

could you rebase so that we can merge it in?

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

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

@abner
Copy link
Copy Markdown

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