GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test: add workerdata-sharedarraybuffer test · nodejs/node@792335f

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • test/parallel
    • test-worker-workerdata-sharedarraybuffer.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎test/parallel/test-worker-workerdata-sharedarraybuffer.js‎

Copy file name to clipboard
+32Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Flags: --expose-gc --experimental-worker
2+
'use strict';
3+
4+
const common = require('../common');
5+
const assert = require('assert');
6+
const { Worker } = require('worker_threads');
7+
8+
{
9+
const sharedArrayBuffer = new SharedArrayBuffer(12);
10+
const local = Buffer.from(sharedArrayBuffer);
11+
12+
const w = new Worker(`
13+
const { parentPort, workerData } = require('worker_threads');
14+
const local = Buffer.from(workerData.sharedArrayBuffer);
15+
16+
parentPort.on('message', () => {
17+
local.write('world!', 6);
18+
parentPort.postMessage('written!');
19+
});
20+
`, {
21+
eval: true,
22+
workerData: { sharedArrayBuffer }
23+
});
24+
w.on('message', common.mustCall(() => {
25+
assert.strictEqual(local.toString(), 'Hello world!');
26+
global.gc();
27+
w.terminate();
28+
}));
29+
w.postMessage({});
30+
// This would be a race condition if the memory regions were overlapping
31+
local.write('Hello ');
32+
}

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.