From f071f94c9388501c20362e735cdd175865dcbea2 Mon Sep 17 00:00:00 2001 From: Qingyu Deng Date: Tue, 17 Aug 2021 14:17:28 +0800 Subject: [PATCH] worker: remove file extension check Fixes: https://github.com/nodejs/node/issues/39124 PR-URL: https://github.com/nodejs/node/pull/39788 Reviewed-By: Anna Henningsen Reviewed-By: Bradley Farias Reviewed-By: James M Snell Reviewed-By: Ruben Bridgewater --- doc/api/errors.md | 6 ------ lib/internal/errors.js | 3 --- lib/internal/worker.js | 6 ------ test/parallel/test-worker-unsupported-path.js | 11 ----------- 4 files changed, 26 deletions(-) diff --git a/doc/api/errors.md b/doc/api/errors.md index b29f83799074aa..6270c00f0b0974 100644 --- a/doc/api/errors.md +++ b/doc/api/errors.md @@ -2502,12 +2502,6 @@ nor a relative path starting with `./` or `../`. All attempts at serializing an uncaught exception from a worker thread failed. - -### `ERR_WORKER_UNSUPPORTED_EXTENSION` - -The pathname used for the main script of a worker has an -unknown file extension. - ### `ERR_WORKER_UNSUPPORTED_OPERATION` diff --git a/lib/internal/errors.js b/lib/internal/errors.js index 483dc391b16a25..2e1174316d4710 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -1617,9 +1617,6 @@ E('ERR_WORKER_PATH', (filename) => TypeError); E('ERR_WORKER_UNSERIALIZABLE_ERROR', 'Serializing an uncaught exception failed', Error); -E('ERR_WORKER_UNSUPPORTED_EXTENSION', - 'The worker script extension must be ".js", ".mjs", or ".cjs". Received "%s"', - TypeError); E('ERR_WORKER_UNSUPPORTED_OPERATION', '%s is not supported in workers', TypeError); E('ERR_ZLIB_INITIALIZATION_FAILED', 'Initialization failed', Error); diff --git a/lib/internal/worker.js b/lib/internal/worker.js index 931bce0c518fc3..d59399bfefed10 100644 --- a/lib/internal/worker.js +++ b/lib/internal/worker.js @@ -35,7 +35,6 @@ const { ERR_WORKER_NOT_RUNNING, ERR_WORKER_PATH, ERR_WORKER_UNSERIALIZABLE_ERROR, - ERR_WORKER_UNSUPPORTED_EXTENSION, ERR_WORKER_INVALID_EXEC_ARGV, ERR_INVALID_ARG_TYPE, ERR_INVALID_ARG_VALUE, @@ -167,11 +166,6 @@ class Worker extends EventEmitter { } else { throw new ERR_WORKER_PATH(filename); } - - const ext = path.extname(filename); - if (ext !== '.js' && ext !== '.mjs' && ext !== '.cjs') { - throw new ERR_WORKER_UNSUPPORTED_EXTENSION(ext); - } } let env; diff --git a/test/parallel/test-worker-unsupported-path.js b/test/parallel/test-worker-unsupported-path.js index 227b759dcfe753..b0e1f7c07cdfc8 100644 --- a/test/parallel/test-worker-unsupported-path.js +++ b/test/parallel/test-worker-unsupported-path.js @@ -5,17 +5,6 @@ const path = require('path'); const assert = require('assert'); const { Worker } = require('worker_threads'); -{ - const expectedErr = { - code: 'ERR_WORKER_UNSUPPORTED_EXTENSION', - name: 'TypeError' - }; - assert.throws(() => { new Worker('/b'); }, expectedErr); - assert.throws(() => { new Worker('/c.wasm'); }, expectedErr); - assert.throws(() => { new Worker('/d.txt'); }, expectedErr); - assert.throws(() => { new Worker(new URL('file:///C:/e.wasm')); }, expectedErr); -} - { const expectedErr = { code: 'ERR_WORKER_PATH',