Skip to content

Instantly share code, notes, and snippets.

@DaveMBush
Last active April 1, 2017 20:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DaveMBush/dbaa474a79924f9450644de80d76c875 to your computer and use it in GitHub Desktop.
Save DaveMBush/dbaa474a79924f9450644de80d76c875 to your computer and use it in GitHub Desktop.
JSDom
Object.defineProperty(XMLHttpRequest.prototype, 'onreadystatechange', {
enumerable: true,
configurable: true,
get: function() {
return this.orsc;
},
set: function(f) {
this.orsc = f;
}
});
const req = new XMLHttpRequest();
req.onreadystatechange = function(){}
const result = !!req.onreadystatechange;
function canPatchViaPropertyDescriptor() {
if ((isBrowser || isMix) && !Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'onclick') &&
typeof Element !== 'undefined') {
// WebKit https://bugs.webkit.org/show_bug.cgi?id=134364
// IDL interface attributes are not configurable
const desc = Object.getOwnPropertyDescriptor(Element.prototype, 'onclick');
if (desc && !desc.configurable) return false;
}
const xhrDesc = Object.getOwnPropertyDescriptor(XMLHttpRequest.prototype, 'onreadystatechange');
// add enumerable and configurable here because in opera
// 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 this.orsc;
},
set: function(f) {
this.orsc = f;
}
});
const req = new XMLHttpRequest();
req.onreadystatechange = function(){}
const result = !!req.onreadystatechange;
// restore original desc
Object.defineProperty(XMLHttpRequest.prototype, 'onreadystatechange', xhrDesc || {});
return result;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment