Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b7ae73b

Browse filesBrowse files
committed
test: add regression test for C++-created Buffer transfer
Add a test for a regression that occurs when transferring some `Buffer` objects that were created from C++ to a parent thread. Fixes: #34126 PR-URL: #34140 Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
1 parent c190189 commit b7ae73b
Copy full SHA for b7ae73b

File tree

Expand file treeCollapse file tree

1 file changed

+30
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+30
-0
lines changed
Open diff view settings
Collapse file
+30Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
'use strict';
2+
const common = require('../common');
3+
if (!common.hasCrypto)
4+
common.skip('missing crypto');
5+
6+
const assert = require('assert');
7+
const { Worker } = require('worker_threads');
8+
const fixturesPath = require.resolve('../common/fixtures');
9+
10+
// Test that transferring the result of e.g. crypto.sign() from Worker to parent
11+
// thread does not crash
12+
13+
const w = new Worker(`
14+
const { parentPort } = require('worker_threads');
15+
const crypto = require('crypto');
16+
const assert = require('assert');
17+
const fixtures = require(${JSON.stringify(fixturesPath)});
18+
19+
const keyPem = fixtures.readKey('rsa_private.pem');
20+
21+
const buf = crypto.sign('sha256', Buffer.from('hello'), keyPem);
22+
assert.notStrictEqual(buf.byteLength, 0);
23+
parentPort.postMessage(buf, [buf.buffer]);
24+
assert.strictEqual(buf.byteLength, 0);
25+
`, { eval: true });
26+
27+
w.on('message', common.mustCall((buf) => {
28+
assert.notStrictEqual(buf.byteLength, 0);
29+
}));
30+
w.on('exit', common.mustCall());

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.