You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.1 KiB
37 lines
1.1 KiB
'use strict';
|
|
var global = require('../internals/global');
|
|
var tryNodeRequire = require('../internals/try-node-require');
|
|
var PROPER_STRUCTURED_CLONE_TRANSFER = require('../internals/structured-clone-proper-transfer');
|
|
|
|
var structuredClone = global.structuredClone;
|
|
var $ArrayBuffer = global.ArrayBuffer;
|
|
var $MessageChannel = global.MessageChannel;
|
|
var detach = false;
|
|
var WorkerThreads, channel, buffer, $detach;
|
|
|
|
if (PROPER_STRUCTURED_CLONE_TRANSFER) {
|
|
detach = function (transferable) {
|
|
structuredClone(transferable, { transfer: [transferable] });
|
|
};
|
|
} else if ($ArrayBuffer) try {
|
|
if (!$MessageChannel) {
|
|
WorkerThreads = tryNodeRequire('worker_threads');
|
|
if (WorkerThreads) $MessageChannel = WorkerThreads.MessageChannel;
|
|
}
|
|
|
|
if ($MessageChannel) {
|
|
channel = new $MessageChannel();
|
|
buffer = new $ArrayBuffer(2);
|
|
|
|
$detach = function (transferable) {
|
|
channel.port1.postMessage(null, [transferable]);
|
|
};
|
|
|
|
if (buffer.byteLength === 2) {
|
|
$detach(buffer);
|
|
if (buffer.byteLength === 0) detach = $detach;
|
|
}
|
|
}
|
|
} catch (error) { /* empty */ }
|
|
|
|
module.exports = detach;
|
|
|