-
-
Save zryty/f8f08b95ab52c4d20da1fbbdc769546c to your computer and use it in GitHub Desktop.
A polyfill for ArrayBuffer#dispose
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
void function () { | |
if ( 'dispose' in ArrayBuffer.prototype ) return | |
var blob = new Blob([''], { | |
type: 'text/javascript' | |
}) | |
var url = URL.createObjectURL(blob) | |
var worker = new Worker(url) | |
URL.revokeObjectURL(url) | |
Object.defineProperty(ArrayBuffer.prototype, 'dispose', { | |
writable: true, | |
enumerable: false, | |
value: function () { | |
worker.postMessage(this, [this]) | |
} | |
}) | |
}() |
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
var x = new Float32Array(16) | |
console.log(x.length) // 16 | |
x.buffer.dispose() | |
console.log(x.length) // 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment