Last active
April 1, 2017 20:46
-
-
Save DaveMBush/dbaa474a79924f9450644de80d76c875 to your computer and use it in GitHub Desktop.
JSDom
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Object.defineProperty(XMLHttpRequest.prototype, 'onreadystatechange', { | |
enumerable: true, | |
configurable: true, | |
get: function() { | |
return this.orsc; | |
}, | |
set: function(f) { | |
this.orsc = f; | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const req = new XMLHttpRequest(); | |
req.onreadystatechange = function(){} | |
const result = !!req.onreadystatechange; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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