mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
64549731b6
The HTML StructuredSerializeWithTransfer algorithm defines that when an untransferable object is in the transfer list, a DataCloneError is thrown. An array buffer that is already transferred is also considered as untransferable. PR-URL: https://github.com/nodejs/node/pull/47604 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
19 lines
588 B
JavaScript
19 lines
588 B
JavaScript
'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
|
|
// transferred.
|
|
|
|
const { port1 } = new MessageChannel();
|
|
const origByteLength = buffer.byteLength;
|
|
assert.throws(() => port1.postMessage(buffer, [buffer]), {
|
|
code: 25,
|
|
name: 'DataCloneError',
|
|
});
|
|
|
|
assert.strictEqual(buffer.byteLength, origByteLength);
|
|
assert.notStrictEqual(buffer.byteLength, 0);
|