Created
May 12, 2021 12:39
-
-
Save tniessen/9d63df7dc9860e2f1514cd701a932891 to your computer and use it in GitHub Desktop.
Tests the behavior of instanceof on CryptoKey instances shared across frames
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> | |
<head> | |
<title>Index</title> | |
</head> | |
<body> | |
<iframe src="iframe.html" width="100%" height="300"></iframe> | |
<pre id="parent"></pre> | |
<script type="text/javascript" src="test.js"></script> | |
<script type="text/javascript"> | |
window.addEventListener('message', (e) => { | |
const { testValuesFromWorker: v } = window; | |
document.querySelector('#parent').textContent = summarizeTestValues(v); | |
}); | |
</script> | |
</body> | |
</html> |
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> | |
<head> | |
<title>Frame</title> | |
</head> | |
<body> | |
<pre id="child"></pre> | |
<script type="text/javascript" src="test.js"></script> | |
<script type="text/javascript"> | |
generateTestValues().then((v) => { | |
document.querySelector('#child').textContent = summarizeTestValues(v); | |
window.parent.testValuesFromWorker = v; | |
parent.postMessage('doStuff'); | |
}); | |
</script> | |
</body> | |
</html> |
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
'use strict'; | |
async function generateTestValues() { | |
const array = [1, 2, 3]; | |
const cryptoKey = await crypto.subtle.generateKey({ | |
name: 'AES-CTR', | |
length: 128 | |
}, true, ['encrypt']); | |
return { array, cryptoKey }; | |
} | |
function summarizeTestValues({ array, cryptoKey }) { | |
return [ | |
` array instanceof Array === ${array instanceof Array}`, | |
` Array.isArray(array) === ${Array.isArray(array)}`, | |
`cryptoKey instanceof CryptoKey === ${cryptoKey instanceof CryptoKey}` | |
].join('\n'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment