From 81a93aa3958a6c3de5799c5a3ac1237a31b9db09 Mon Sep 17 00:00:00 2001 From: Qingyu Deng Date: Tue, 17 Aug 2021 14:17:28 +0800 Subject: [PATCH 1/3] worker: remove file extension check Fixes: https://github.com/nodejs/node/issues/39124 --- 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 79a653e98c72bc..f1508943624b8a 100644 --- a/doc/api/errors.md +++ b/doc/api/errors.md @@ -2510,12 +2510,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 0ba45e63387415..84431fe811d9fc 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', From 9076f351b0de38d0816064617c03736b67c9628e Mon Sep 17 00:00:00 2001 From: Qingyu Deng Date: Tue, 17 Aug 2021 20:48:41 +0800 Subject: [PATCH 2/3] doc: move ERR_WORKER_UNSPPORTED_EXTENSION to legacy --- doc/api/errors.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/doc/api/errors.md b/doc/api/errors.md index f1508943624b8a..a7674c55665df9 100644 --- a/doc/api/errors.md +++ b/doc/api/errors.md @@ -2836,6 +2836,16 @@ Used when a given value is out of the accepted range. The module must be successfully linked before instantiation. + +### `ERR_WORKER_UNSUPPORTED_EXTENSION` + + +The pathname used for the main script of a worker has an +unknown file extension. + ### `ERR_ZLIB_BINDING_CLOSED`