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>
27 lines
741 B
JavaScript
27 lines
741 B
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
|
|
const { MessageChannel } = require('worker_threads');
|
|
|
|
{
|
|
const { port1, port2 } = new MessageChannel();
|
|
|
|
const arrayBuffer = new ArrayBuffer(40);
|
|
const typedArray = new Uint32Array(arrayBuffer);
|
|
typedArray[0] = 0x12345678;
|
|
|
|
port1.postMessage(typedArray, [ arrayBuffer ]);
|
|
assert.strictEqual(arrayBuffer.byteLength, 0);
|
|
// Transferring again should throw a DataCloneError.
|
|
assert.throws(() => port1.postMessage(typedArray, [ arrayBuffer ]), {
|
|
code: 25,
|
|
name: 'DataCloneError',
|
|
});
|
|
|
|
port2.on('message', common.mustCall((received) => {
|
|
assert.strictEqual(received[0], 0x12345678);
|
|
port2.close(common.mustCall());
|
|
}));
|
|
}
|