UNPKG

882 BJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.Transfer = exports.isTransferDescriptor = void 0;
4const symbols_1 = require("./symbols");
5function isTransferable(thing) {
6 if (!thing || typeof thing !== "object")
7 return false;
8 // Don't check too thoroughly, since the list of transferable things in JS might grow over time
9 return true;
10}
11function isTransferDescriptor(thing) {
12 return thing && typeof thing === "object" && thing[symbols_1.$transferable];
13}
14exports.isTransferDescriptor = isTransferDescriptor;
15function Transfer(payload, transferables) {
16 if (!transferables) {
17 if (!isTransferable(payload))
18 throw Error();
19 transferables = [payload];
20 }
21 return {
22 [symbols_1.$transferable]: true,
23 send: payload,
24 transferables
25 };
26}
27exports.Transfer = Transfer;