mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
4201cdde89
This test would be broken by V8 7.9 due to the changed `ArrayBuffer` backing store management (the same way that V8 7.8 broke this for `SharedArrayBuffer`s). While working on a solution, it would be good to already have this test in Node.js to avoid unnecessary accidental breakage. Refs: https://github.com/nodejs/node-v8/issues/115 PR-URL: https://github.com/nodejs/node/pull/30044 Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
29 lines
1.0 KiB
JavaScript
29 lines
1.0 KiB
JavaScript
// Flags: --debug-arraybuffer-allocations
|
|
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const { Worker } = require('worker_threads');
|
|
|
|
// Regression test for https://github.com/nodejs/node/issues/28777
|
|
// Make sure that SharedArrayBuffers and transferred ArrayBuffers created in
|
|
// Worker threads are accessible after the creating thread ended.
|
|
|
|
for (const ctor of ['ArrayBuffer', 'SharedArrayBuffer']) {
|
|
const w = new Worker(`
|
|
const { parentPort } = require('worker_threads');
|
|
const arrayBuffer = new ${ctor}(4);
|
|
parentPort.postMessage(
|
|
arrayBuffer,
|
|
'${ctor}' === 'SharedArrayBuffer' ? [] : [arrayBuffer]);
|
|
`, { eval: true });
|
|
|
|
let arrayBuffer;
|
|
w.once('message', common.mustCall((message) => arrayBuffer = message));
|
|
w.once('exit', common.mustCall(() => {
|
|
assert.strictEqual(arrayBuffer.constructor.name, ctor);
|
|
const uint8array = new Uint8Array(arrayBuffer);
|
|
uint8array[0] = 42;
|
|
assert.deepStrictEqual(uint8array, new Uint8Array([42, 0, 0, 0]));
|
|
}));
|
|
}
|