11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciconst assert = require('assert');
41cb0ef41Sopenharmony_ciconst { Worker, parentPort } = require('worker_threads');
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ci// Do not use isMainThread so that this test itself can be run inside a Worker.
71cb0ef41Sopenharmony_ciif (!process.env.HAS_STARTED_WORKER) {
81cb0ef41Sopenharmony_ci  process.env.HAS_STARTED_WORKER = 1;
91cb0ef41Sopenharmony_ci  process.env.NODE_CHANNEL_FD = 'foo'; // Make worker think it has IPC.
101cb0ef41Sopenharmony_ci  const w = new Worker(__filename);
111cb0ef41Sopenharmony_ci  w.on('message', common.mustCall((message) => {
121cb0ef41Sopenharmony_ci    assert.strictEqual(message, true);
131cb0ef41Sopenharmony_ci  }));
141cb0ef41Sopenharmony_ci} else {
151cb0ef41Sopenharmony_ci  {
161cb0ef41Sopenharmony_ci    const before = process.title;
171cb0ef41Sopenharmony_ci    process.title += ' in worker';
181cb0ef41Sopenharmony_ci    assert.strictEqual(process.title, before);
191cb0ef41Sopenharmony_ci  }
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ci  {
221cb0ef41Sopenharmony_ci    const before = process.debugPort;
231cb0ef41Sopenharmony_ci    process.debugPort++;
241cb0ef41Sopenharmony_ci    assert.strictEqual(process.debugPort, before);
251cb0ef41Sopenharmony_ci  }
261cb0ef41Sopenharmony_ci
271cb0ef41Sopenharmony_ci  {
281cb0ef41Sopenharmony_ci    const mask = 0o600;
291cb0ef41Sopenharmony_ci    assert.throws(() => { process.umask(mask); }, {
301cb0ef41Sopenharmony_ci      code: 'ERR_WORKER_UNSUPPORTED_OPERATION',
311cb0ef41Sopenharmony_ci      message: 'Setting process.umask() is not supported in workers'
321cb0ef41Sopenharmony_ci    });
331cb0ef41Sopenharmony_ci  }
341cb0ef41Sopenharmony_ci
351cb0ef41Sopenharmony_ci  const stubs = ['abort', 'chdir', 'send', 'disconnect'];
361cb0ef41Sopenharmony_ci
371cb0ef41Sopenharmony_ci  if (!common.isWindows) {
381cb0ef41Sopenharmony_ci    stubs.push('setuid', 'seteuid', 'setgid',
391cb0ef41Sopenharmony_ci               'setegid', 'setgroups', 'initgroups');
401cb0ef41Sopenharmony_ci  }
411cb0ef41Sopenharmony_ci
421cb0ef41Sopenharmony_ci  stubs.forEach((fn) => {
431cb0ef41Sopenharmony_ci    assert.strictEqual(process[fn].disabled, true);
441cb0ef41Sopenharmony_ci    assert.throws(() => {
451cb0ef41Sopenharmony_ci      process[fn]();
461cb0ef41Sopenharmony_ci    }, {
471cb0ef41Sopenharmony_ci      code: 'ERR_WORKER_UNSUPPORTED_OPERATION',
481cb0ef41Sopenharmony_ci      message: `process.${fn}() is not supported in workers`
491cb0ef41Sopenharmony_ci    });
501cb0ef41Sopenharmony_ci  });
511cb0ef41Sopenharmony_ci
521cb0ef41Sopenharmony_ci  ['channel', 'connected'].forEach((fn) => {
531cb0ef41Sopenharmony_ci    assert.throws(() => {
541cb0ef41Sopenharmony_ci      process[fn]; // eslint-disable-line no-unused-expressions
551cb0ef41Sopenharmony_ci    }, {
561cb0ef41Sopenharmony_ci      code: 'ERR_WORKER_UNSUPPORTED_OPERATION',
571cb0ef41Sopenharmony_ci      message: `process.${fn} is not supported in workers`
581cb0ef41Sopenharmony_ci    });
591cb0ef41Sopenharmony_ci  });
601cb0ef41Sopenharmony_ci
611cb0ef41Sopenharmony_ci  assert.strictEqual('_startProfilerIdleNotifier' in process, false);
621cb0ef41Sopenharmony_ci  assert.strictEqual('_stopProfilerIdleNotifier' in process, false);
631cb0ef41Sopenharmony_ci  assert.strictEqual('_debugProcess' in process, false);
641cb0ef41Sopenharmony_ci  assert.strictEqual('_debugPause' in process, false);
651cb0ef41Sopenharmony_ci  assert.strictEqual('_debugEnd' in process, false);
661cb0ef41Sopenharmony_ci
671cb0ef41Sopenharmony_ci  parentPort.postMessage(true);
681cb0ef41Sopenharmony_ci}
69