node/lib/worker_threads.js
Anna Henningsen 88fb5a5c79
worker: add public method for marking objects as untransferable
We currently mark a number of `ArrayBuffer`s as not transferable,
including the `Buffer` pool and ones with finalizers provided
by C++ addons.

There is no good reason to assume that userland code might not
encounter similar problems, for example when doing `ArrayBuffer`
pooling similar to ours. Therefore, provide an API that lets
userland code also mark objects as not transferable.

PR-URL: https://github.com/nodejs/node/pull/33979
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
2020-06-25 08:33:29 -07:00

36 lines
558 B
JavaScript

'use strict';
const {
isMainThread,
SHARE_ENV,
resourceLimits,
threadId,
Worker
} = require('internal/worker');
const {
MessagePort,
MessageChannel,
moveMessagePortToContext,
receiveMessageOnPort,
} = require('internal/worker/io');
const {
markAsUntransferable,
} = require('internal/buffer');
module.exports = {
isMainThread,
MessagePort,
MessageChannel,
markAsUntransferable,
moveMessagePortToContext,
receiveMessageOnPort,
resourceLimits,
threadId,
SHARE_ENV,
Worker,
parentPort: null,
workerData: null,
};