UNPKG

662 BJavaScriptView Raw
1import { $transferable } from "./symbols";
2function isTransferable(thing) {
3 if (!thing || typeof thing !== "object")
4 return false;
5 // Don't check too thoroughly, since the list of transferable things in JS might grow over time
6 return true;
7}
8export function isTransferDescriptor(thing) {
9 return thing && typeof thing === "object" && thing[$transferable];
10}
11export function Transfer(payload, transferables) {
12 if (!transferables) {
13 if (!isTransferable(payload))
14 throw Error();
15 transferables = [payload];
16 }
17 return {
18 [$transferable]: true,
19 send: payload,
20 transferables
21 };
22}