11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciconst assert = require('assert');
41cb0ef41Sopenharmony_ciconst { Worker, isMainThread, workerData } = require('worker_threads');
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ciif (isMainThread) {
71cb0ef41Sopenharmony_ci  assert.throws(() => {
81cb0ef41Sopenharmony_ci    new Worker(__filename, { argv: 'foo' });
91cb0ef41Sopenharmony_ci  }, {
101cb0ef41Sopenharmony_ci    code: 'ERR_INVALID_ARG_TYPE'
111cb0ef41Sopenharmony_ci  });
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ci  [
141cb0ef41Sopenharmony_ci    new Worker(__filename, {
151cb0ef41Sopenharmony_ci      argv: [null, 'foo', 123, Symbol('bar')],
161cb0ef41Sopenharmony_ci      // Asserts only if the worker is started by the test.
171cb0ef41Sopenharmony_ci      workerData: 'assert-argv'
181cb0ef41Sopenharmony_ci    }),
191cb0ef41Sopenharmony_ci    new Worker(`
201cb0ef41Sopenharmony_ci      const assert = require('assert');
211cb0ef41Sopenharmony_ci      assert.deepStrictEqual(
221cb0ef41Sopenharmony_ci        process.argv,
231cb0ef41Sopenharmony_ci        [process.execPath, '[worker eval]']
241cb0ef41Sopenharmony_ci      );
251cb0ef41Sopenharmony_ci    `, {
261cb0ef41Sopenharmony_ci      eval: true
271cb0ef41Sopenharmony_ci    }),
281cb0ef41Sopenharmony_ci    new Worker(`
291cb0ef41Sopenharmony_ci      const assert = require('assert');
301cb0ef41Sopenharmony_ci      assert.deepStrictEqual(
311cb0ef41Sopenharmony_ci        process.argv,
321cb0ef41Sopenharmony_ci        [process.execPath, '[worker eval]', 'null', 'foo', '123',
331cb0ef41Sopenharmony_ci        String(Symbol('bar'))]
341cb0ef41Sopenharmony_ci      );
351cb0ef41Sopenharmony_ci    `, {
361cb0ef41Sopenharmony_ci      argv: [null, 'foo', 123, Symbol('bar')],
371cb0ef41Sopenharmony_ci      eval: true
381cb0ef41Sopenharmony_ci    }),
391cb0ef41Sopenharmony_ci  ].forEach((worker) => {
401cb0ef41Sopenharmony_ci    worker.on('exit', common.mustCall((code) => {
411cb0ef41Sopenharmony_ci      assert.strictEqual(code, 0);
421cb0ef41Sopenharmony_ci    }));
431cb0ef41Sopenharmony_ci  });
441cb0ef41Sopenharmony_ci} else if (workerData === 'assert-argv') {
451cb0ef41Sopenharmony_ci  assert.deepStrictEqual(
461cb0ef41Sopenharmony_ci    process.argv,
471cb0ef41Sopenharmony_ci    [process.execPath, __filename, 'null', 'foo', '123', String(Symbol('bar'))]
481cb0ef41Sopenharmony_ci  );
491cb0ef41Sopenharmony_ci}
50