Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

worker: remove file extension check #39788

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions doc/api/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -2510,12 +2510,6 @@ nor a relative path starting with `./` or `../`.

All attempts at serializing an uncaught exception from a worker thread failed.

<a id="ERR_WORKER_UNSUPPORTED_EXTENSION"></a>
### `ERR_WORKER_UNSUPPORTED_EXTENSION`

The pathname used for the main script of a worker has an
unknown file extension.

jasnell marked this conversation as resolved.
Show resolved Hide resolved
<a id="ERR_WORKER_UNSUPPORTED_OPERATION"></a>
### `ERR_WORKER_UNSUPPORTED_OPERATION`

Expand Down Expand Up @@ -2842,6 +2836,16 @@ Used when a given value is out of the accepted range.

The module must be successfully linked before instantiation.

<a id="ERR_WORKER_UNSUPPORTED_EXTENSION"></a>
### `ERR_WORKER_UNSUPPORTED_EXTENSION`
<!-- YAML
added: v11.0.0
removed: REPLACEME
-->

The pathname used for the main script of a worker has an
unknown file extension.

<a id="ERR_ZLIB_BINDING_CLOSED"></a>
### `ERR_ZLIB_BINDING_CLOSED`
<!-- YAML
Expand Down
3 changes: 0 additions & 3 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
6 changes: 0 additions & 6 deletions lib/internal/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
Empty file added test/fixtures/worker-script.ts
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';
const common = require('../common');
const fixtures = require('../common/fixtures');

const { Worker } = require('worker_threads');

(common.mustCall(() => {
new Worker(fixtures.path('worker-script.ts'));
jasnell marked this conversation as resolved.
Show resolved Hide resolved
}))();
11 changes: 0 additions & 11 deletions test/parallel/test-worker-unsupported-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down