Created
June 18, 2019 14:11
-
-
Save brianloveswords/b0360822500df13b6e61ebb47dd768f4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 addH1() { | |
document.body.innerHTML += '<h1>okay!</h1>'; | |
} | |
// this lets callers from `file.js` through to the original version of | |
// innerHTML but not other callers | |
(function(){ | |
const innerHTMLDesc = Object.getOwnPropertyDescriptor(Element.prototype, 'innerHTML'); | |
Object.defineProperty(Element.prototype, 'innerHTML', { | |
get() { | |
let stack; | |
try { throw new Error(); } | |
catch(e) { stack = e.stack;} | |
if (/file.js/.test(stack)) { | |
return innerHTMLDesc.get.call(this); | |
} | |
return "nah"; | |
}, | |
set(value) { | |
let stack; | |
try { throw new Error(); } | |
catch(e) { stack = e.stack; } | |
if (/file.js/.test(stack)) { | |
return innerHTMLDesc.set.call(this, value); | |
} | |
return "nah"; | |
} | |
}); | |
})(); |
This file contains hidden or 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
<h1>no user innerHTML</h1> | |
<script src='file.js'></script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment