node_modules/es-abstract/2022/DetachArrayBuffer.js in immosquare-cleaner-0.1.32 vs node_modules/es-abstract/2022/DetachArrayBuffer.js in immosquare-cleaner-0.1.38

- old
+ new

@@ -1,11 +1,11 @@ 'use strict'; -var GetIntrinsic = require('get-intrinsic'); +var $SyntaxError = require('es-errors/syntax'); +var $TypeError = require('es-errors/type'); -var $SyntaxError = GetIntrinsic('%SyntaxError%'); -var $TypeError = GetIntrinsic('%TypeError%'); +var IsDetachedBuffer = require('./IsDetachedBuffer'); var isArrayBuffer = require('is-array-buffer'); var isSharedArrayBuffer = require('is-shared-array-buffer'); var MessageChannel; @@ -28,16 +28,19 @@ // if (!SameValue(arrayBuffer[[ArrayBufferDetachKey]], key)) { // throw new $TypeError('Assertion failed: `key` must be the value of the [[ArrayBufferDetachKey]] internal slot of `arrayBuffer`'); // } - if (typeof structuredClone === 'function') { - structuredClone(arrayBuffer, { transfer: [arrayBuffer] }); - } else if (typeof postMessage === 'function') { - postMessage('', '/', [arrayBuffer]); // TODO: see if this might trigger listeners - } else if (MessageChannel) { - (new MessageChannel()).port1.postMessage(null, [arrayBuffer]); - } else { - throw new $SyntaxError('DetachArrayBuffer is not supported in this environment'); + if (!IsDetachedBuffer(arrayBuffer)) { // node v21.0.0+ throws when you structuredClone a detached buffer + if (typeof structuredClone === 'function') { + structuredClone(arrayBuffer, { transfer: [arrayBuffer] }); + } else if (typeof postMessage === 'function') { + postMessage('', '/', [arrayBuffer]); // TODO: see if this might trigger listeners + } else if (MessageChannel) { + (new MessageChannel()).port1.postMessage(null, [arrayBuffer]); + } else { + throw new $SyntaxError('DetachArrayBuffer is not supported in this environment'); + } } + return null; };