1'use strict'; 2const common = require('../common'); 3if (!common.hasCrypto) 4 common.skip('missing crypto'); 5 6const assert = require('assert'); 7const { Worker } = require('worker_threads'); 8const 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 13const w = new Worker(` 14const { parentPort } = require('worker_threads'); 15const crypto = require('crypto'); 16const assert = require('assert'); 17const fixtures = require(${JSON.stringify(fixturesPath)}); 18 19const keyPem = fixtures.readKey('rsa_private.pem'); 20 21const buf = crypto.sign('sha256', Buffer.from('hello'), keyPem); 22assert.notStrictEqual(buf.byteLength, 0); 23parentPort.postMessage(buf, [buf.buffer]); 24assert.strictEqual(buf.byteLength, 0); 25`, { eval: true }); 26 27w.on('message', common.mustCall((buf) => { 28 assert.notStrictEqual(buf.byteLength, 0); 29})); 30w.on('exit', common.mustCall()); 31