11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_cirequire('../common');
41cb0ef41Sopenharmony_ciconst path = require('path');
51cb0ef41Sopenharmony_ciconst assert = require('assert');
61cb0ef41Sopenharmony_ciconst { Worker } = require('worker_threads');
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ci{
91cb0ef41Sopenharmony_ci  const expectedErr = {
101cb0ef41Sopenharmony_ci    code: 'ERR_WORKER_PATH',
111cb0ef41Sopenharmony_ci    name: 'TypeError'
121cb0ef41Sopenharmony_ci  };
131cb0ef41Sopenharmony_ci  const existingRelPathNoDot = path.relative('.', __filename);
141cb0ef41Sopenharmony_ci  assert.throws(() => { new Worker(existingRelPathNoDot); }, expectedErr);
151cb0ef41Sopenharmony_ci  assert.throws(() => { new Worker('relative_no_dot'); }, expectedErr);
161cb0ef41Sopenharmony_ci  assert.throws(() => { new Worker('file:///file_url'); }, expectedErr);
171cb0ef41Sopenharmony_ci  assert.throws(() => { new Worker('https://www.url.com'); }, expectedErr);
181cb0ef41Sopenharmony_ci}
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_ci{
211cb0ef41Sopenharmony_ci  assert.throws(
221cb0ef41Sopenharmony_ci    () => { new Worker('file:///file_url'); },
231cb0ef41Sopenharmony_ci    /Wrap file:\/\/ URLs with `new URL`/
241cb0ef41Sopenharmony_ci  );
251cb0ef41Sopenharmony_ci  assert.throws(
261cb0ef41Sopenharmony_ci    () => { new Worker('data:text/javascript,'); },
271cb0ef41Sopenharmony_ci    /Wrap data: URLs with `new URL`/
281cb0ef41Sopenharmony_ci  );
291cb0ef41Sopenharmony_ci  assert.throws(
301cb0ef41Sopenharmony_ci    () => { new Worker('relative_no_dot'); },
311cb0ef41Sopenharmony_ci    // eslint-disable-next-line node-core/no-unescaped-regexp-dot
321cb0ef41Sopenharmony_ci    /^((?!Wrap file:\/\/ URLs with `new URL`).)*$/s
331cb0ef41Sopenharmony_ci  );
341cb0ef41Sopenharmony_ci}
351cb0ef41Sopenharmony_ci
361cb0ef41Sopenharmony_ci{
371cb0ef41Sopenharmony_ci  const expectedErr = {
381cb0ef41Sopenharmony_ci    code: 'ERR_INVALID_URL_SCHEME',
391cb0ef41Sopenharmony_ci    name: 'TypeError'
401cb0ef41Sopenharmony_ci  };
411cb0ef41Sopenharmony_ci  assert.throws(() => { new Worker(new URL('https://www.url.com')); },
421cb0ef41Sopenharmony_ci                expectedErr);
431cb0ef41Sopenharmony_ci}
44