1'use strict'; 2const common = require('../common'); 3const assert = require('assert'); 4const { Worker, parentPort } = require('worker_threads'); 5 6// Do not use isMainThread so that this test itself can be run inside a Worker. 7if (!process.env.HAS_STARTED_WORKER) { 8 process.env.HAS_STARTED_WORKER = 1; 9 process.env.NODE_CHANNEL_FD = 'foo'; // Make worker think it has IPC. 10 const w = new Worker(__filename); 11 w.on('message', common.mustCall((message) => { 12 assert.strictEqual(message, true); 13 })); 14} else { 15 { 16 const before = process.title; 17 process.title += ' in worker'; 18 assert.strictEqual(process.title, before); 19 } 20 21 { 22 const before = process.debugPort; 23 process.debugPort++; 24 assert.strictEqual(process.debugPort, before); 25 } 26 27 const stubs = ['abort', 'chdir', 'send', 'disconnect']; 28 29 if (!common.isWindows) { 30 stubs.push('setuid', 'seteuid', 'setgid', 31 'setegid', 'setgroups', 'initgroups'); 32 } 33 34 stubs.forEach((fn) => { 35 assert.strictEqual(process[fn].disabled, true); 36 assert.throws(() => { 37 process[fn](); 38 }, { code: 'ERR_WORKER_UNSUPPORTED_OPERATION' }); 39 }); 40 41 ['channel', 'connected'].forEach((fn) => { 42 assert.throws(() => { 43 process[fn]; 44 }, { code: 'ERR_WORKER_UNSUPPORTED_OPERATION' }); 45 }); 46 47 assert.strictEqual('_startProfilerIdleNotifier' in process, false); 48 assert.strictEqual('_stopProfilerIdleNotifier' in process, false); 49 assert.strictEqual('_debugProcess' in process, false); 50 assert.strictEqual('_debugPause' in process, false); 51 assert.strictEqual('_debugEnd' in process, false); 52 53 parentPort.postMessage(true); 54} 55