1234567891011121314151617181920212223242526272829303132333435363738394041 |
- 'use strict';
- var $SyntaxError = require('es-errors/syntax');
- var $TypeError = require('es-errors/type');
- var isArrayBuffer = require('is-array-buffer');
- var isSharedArrayBuffer = require('is-shared-array-buffer');
- var MessageChannel;
- try {
-
- MessageChannel = require('worker_threads').MessageChannel;
- } catch (e) { }
- module.exports = function DetachArrayBuffer(arrayBuffer) {
- if (!isArrayBuffer(arrayBuffer) || isSharedArrayBuffer(arrayBuffer)) {
- throw new $TypeError('Assertion failed: `arrayBuffer` must be an Object with an [[ArrayBufferData]] internal slot, and not a Shared Array Buffer');
- }
-
-
-
-
-
- if (typeof structuredClone === 'function') {
- structuredClone(arrayBuffer, { transfer: [arrayBuffer] });
- } else if (typeof postMessage === 'function') {
- postMessage('', '/', [arrayBuffer]);
- } else if (MessageChannel) {
- (new MessageChannel()).port1.postMessage(null, [arrayBuffer]);
- } else {
- throw new $SyntaxError('DetachArrayBuffer is not supported in this environment');
- }
- return null;
- };
|