main
Last change
on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago |
F4 Finalna Verzija
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Line | |
---|
1 | 'use strict';
|
---|
2 | var globalThis = require('../internals/global-this');
|
---|
3 | var getBuiltInNodeModule = require('../internals/get-built-in-node-module');
|
---|
4 | var PROPER_STRUCTURED_CLONE_TRANSFER = require('../internals/structured-clone-proper-transfer');
|
---|
5 |
|
---|
6 | var structuredClone = globalThis.structuredClone;
|
---|
7 | var $ArrayBuffer = globalThis.ArrayBuffer;
|
---|
8 | var $MessageChannel = globalThis.MessageChannel;
|
---|
9 | var detach = false;
|
---|
10 | var WorkerThreads, channel, buffer, $detach;
|
---|
11 |
|
---|
12 | if (PROPER_STRUCTURED_CLONE_TRANSFER) {
|
---|
13 | detach = function (transferable) {
|
---|
14 | structuredClone(transferable, { transfer: [transferable] });
|
---|
15 | };
|
---|
16 | } else if ($ArrayBuffer) try {
|
---|
17 | if (!$MessageChannel) {
|
---|
18 | WorkerThreads = getBuiltInNodeModule('worker_threads');
|
---|
19 | if (WorkerThreads) $MessageChannel = WorkerThreads.MessageChannel;
|
---|
20 | }
|
---|
21 |
|
---|
22 | if ($MessageChannel) {
|
---|
23 | channel = new $MessageChannel();
|
---|
24 | buffer = new $ArrayBuffer(2);
|
---|
25 |
|
---|
26 | $detach = function (transferable) {
|
---|
27 | channel.port1.postMessage(null, [transferable]);
|
---|
28 | };
|
---|
29 |
|
---|
30 | if (buffer.byteLength === 2) {
|
---|
31 | $detach(buffer);
|
---|
32 | if (buffer.byteLength === 0) detach = $detach;
|
---|
33 | }
|
---|
34 | }
|
---|
35 | } catch (error) { /* empty */ }
|
---|
36 |
|
---|
37 | module.exports = detach;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.