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

Commit

Permalink
fix(patch): fix #708, modify the canPatchDescriptor logic when browse…
Browse files Browse the repository at this point in the history
…r don't provide onreadystatechange (#711)
  • Loading branch information
JiaLiPassion authored and mhevery committed Apr 21, 2017
1 parent 0a06874 commit 7d4d07f
Showing 1 changed file with 34 additions and 13 deletions.
47 changes: 34 additions & 13 deletions lib/browser/property-descriptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,40 @@ function canPatchViaPropertyDescriptor() {
// by default XMLHttpRequest.prototype.onreadystatechange is undefined
// without adding enumerable and configurable will cause onreadystatechange
// non-configurable
Object.defineProperty(XMLHttpRequest.prototype, 'onreadystatechange', {
enumerable: true,
configurable: true,
get: function() {
return true;
}
});
const req = new XMLHttpRequest();
const result = !!req.onreadystatechange;
// restore original desc
Object.defineProperty(XMLHttpRequest.prototype, 'onreadystatechange', xhrDesc || {});
return result;
}
// and if XMLHttpRequest.prototype.onreadystatechange is undefined,
// we should set a real desc instead a fake one
if (xhrDesc) {
Object.defineProperty(XMLHttpRequest.prototype, 'onreadystatechange', {
enumerable: true,
configurable: true,
get: function() {
return true;
}
});
const req = new XMLHttpRequest();
const result = !!req.onreadystatechange;
// restore original desc
Object.defineProperty(XMLHttpRequest.prototype, 'onreadystatechange', xhrDesc || {});
return result;
} else {
Object.defineProperty(XMLHttpRequest.prototype, 'onreadystatechange', {
enumerable: true,
configurable: true,
get: function() {
return this[zoneSymbol('fakeonreadystatechange')];
},
set: function(value) {
this[zoneSymbol('fakeonreadystatechange')] = value;
}
});
const req = new XMLHttpRequest();
const detectFunc = () => {};
req.onreadystatechange = detectFunc;
const result = (req as any)[zoneSymbol('fakeonreadystatechange')] === detectFunc;
req.onreadystatechange = null;
return result;
}
};

const unboundKey = zoneSymbol('unbound');

Expand Down

0 comments on commit 7d4d07f

Please sign in to comment.