Created
November 8, 2017 04:08
-
-
Save timdorr/326ed608a9cbe67f247c2fbc709cdba3 to your computer and use it in GitHub Desktop.
isPlainObject iframe test case
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
<!DOCTYPE html> | |
<html> | |
<body> | |
<script> | |
function isPlainObject(obj) { | |
if (typeof obj !== 'object' || obj === null) return false | |
let proto = obj | |
while (Object.getPrototypeOf(proto) !== null) { | |
proto = Object.getPrototypeOf(proto) | |
} | |
return Object.getPrototypeOf(obj) === proto | |
} | |
const iframe = document.createElement("iframe") | |
document.body.appendChild(iframe) | |
var doc = iframe.contentDocument | |
doc.open() | |
// doc.write("<body onload='class Action {}; window.top.callback(new Action)'>") | |
doc.write("<body onload='window.top.callback({})'>") | |
doc.close() | |
function callback(obj) { | |
console.log(isPlainObject(obj)) | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment