Files
bun.sh/test/js/node/test/parallel/test-buffer-pool-untransferable.js
2025-02-24 20:02:56 -08:00

25 lines
779 B
JavaScript

'use strict';
const common = require('../common');
if ('Bun' in globalThis) common.skip("BUN: we don't use a pool");
const assert = require('assert');
const { MessageChannel } = require('worker_threads');
// Make sure that the pools used by the Buffer implementation are not
// transferable.
// Refs: https://github.com/nodejs/node/issues/32752
const a = Buffer.from('hello world');
const b = Buffer.from('hello world');
assert.strictEqual(a.buffer, b.buffer);
const length = a.length;
const { port1 } = new MessageChannel();
assert.throws(() => port1.postMessage(a, [ a.buffer ]), {
code: 25,
name: 'DataCloneError',
});
// Verify that the pool ArrayBuffer has not actually been transferred:
assert.strictEqual(a.buffer, b.buffer);
assert.strictEqual(a.length, length);