mirror of
https://github.com/nodejs/node.git
synced 2026-11-29 14:27:57 -05:00
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>
This commit is contained in:
1 parent
ced68bfa3d
commit
4875a511ea
9 files changed
+118
-21
No files matched your search
+2
-4
@@ -59,13 +59,11 @@ const {
|
||||
zeroFill: bindingZeroFill
|
||||
} = internalBinding('buffer');
|
||||
const {
|
||||
arraybuffer_untransferable_private_symbol,
|
||||
getOwnNonIndexProperties,
|
||||
propertyFilter: {
|
||||
ALL_PROPERTIES,
|
||||
ONLY_ENUMERABLE
|
||||
},
|
||||
setHiddenValue,
|
||||
} = internalBinding('util');
|
||||
const {
|
||||
customInspectSymbol,
|
||||
@@ -83,7 +81,6 @@ const {
|
||||
} = require('internal/util/inspect');
|
||||
const { encodings } = internalBinding('string_decoder');
|
||||
|
||||
|
||||
const {
|
||||
codes: {
|
||||
ERR_BUFFER_OUT_OF_BOUNDS,
|
||||
@@ -104,6 +101,7 @@ const {
|
||||
|
||||
const {
|
||||
FastBuffer,
|
||||
markAsUntransferable,
|
||||
addBufferPrototypeMethods
|
||||
} = require('internal/buffer');
|
||||
|
||||
@@ -156,7 +154,7 @@ function createUnsafeBuffer(size) {
|
||||
function createPool() {
|
||||
poolSize = Buffer.poolSize;
|
||||
allocPool = createUnsafeBuffer(poolSize).buffer;
|
||||
setHiddenValue(allocPool, arraybuffer_untransferable_private_symbol, true);
|
||||
markAsUntransferable(allocPool);
|
||||
poolOffset = 0;
|
||||
}
|
||||
createPool();
|
||||
|
||||
Reference in new issue
Block a user