summaryrefslogtreecommitdiff
path: root/test/addons/worker-buffer-callback/test.js
blob: b04984f15764329ec7bba28e78f8f2d25e70204c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
'use strict';
const common = require('../../common');
const assert = require('assert');
const { MessageChannel } = require('worker_threads');
const { buffer } = require(`./build/${common.buildType}/binding`);

// Test that buffers allocated with a free callback through our APIs are not
// transfered.

const { port1 } = new MessageChannel();
const origByteLength = buffer.byteLength;
port1.postMessage(buffer, [buffer.buffer]);

assert.strictEqual(buffer.byteLength, origByteLength);
assert.notStrictEqual(buffer.byteLength, 0);