-
Notifications
You must be signed in to change notification settings - Fork 407
fix(patch): fix #708, modify the canPatchDescriptor logic when browser has no onreadystatechange #711
Conversation
lib/browser/property-descriptor.ts
Outdated
return result; | ||
// and if XMLHttpRequest.prototype.onreadystatechange is undefined, | ||
// we should set a real desc instead a fake one | ||
if (xhrDesc) { |
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.
It would probably make sense to just immediately return false if xhrDesc is falsy...
if (!xhrDesc) return;
this reduces nesting
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.
@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.
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.
OK.. I see the else now.
lib/browser/property-descriptor.ts
Outdated
return result; | ||
// and if XMLHttpRequest.prototype.onreadystatechange is undefined, | ||
// we should set a real desc instead a fake one | ||
if (xhrDesc) { |
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.
OK.. I see the else now.
could you rebase so that we can merge it in? |
… browser don't provide onreadystatechange
@mhevery , I have rebased the PR, please review. |
great! @JiaLiPassion I need this for tests with jest+jsdom. For now i'm using a patch with your changes |
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.