MCPcopy Index your code
hub / github.com/nodejs/node / constructor

Method constructor

lib/internal/worker.js:207–391  ·  view source on GitHub ↗
(filename, options = kEmptyObject)

Source from the content-addressed store, hash-verified

205
206class Worker extends EventEmitter {
207 constructor(filename, options = kEmptyObject) {
208 throwIfBuildingSnapshot('Creating workers');
209 super();
210 const isInternal = arguments[2] === kIsInternal;
211 debug(
212 `[${threadId}] create new worker`,
213 filename,
214 options,
215 `isInternal: ${isInternal}`,
216 );
217 if (options.execArgv)
218 validateArray(options.execArgv, 'options.execArgv');
219
220 let argv;
221 if (options.argv) {
222 validateArray(options.argv, 'options.argv');
223 argv = ArrayPrototypeMap(options.argv, String);
224 }
225
226 let url, doEval;
227 if (isInternal) {
228 doEval = 'internal';
229 url = `node:${filename}`;
230 } else if (options.eval) {
231 if (typeof filename !== 'string') {
232 throw new ERR_INVALID_ARG_VALUE(
233 'options.eval',
234 options.eval,
235 'must be false when \'filename\' is not a string',
236 );
237 }
238 url = null;
239 doEval = 'classic';
240 } else if (isURL(filename) && filename.protocol === 'data:') {
241 url = null;
242 doEval = 'data-url';
243 filename = `${filename}`;
244 } else {
245 doEval = false;
246 if (isURL(filename)) {
247 url = filename;
248 filename = fileURLToPath(filename);
249 } else if (typeof filename !== 'string') {
250 throw new ERR_INVALID_ARG_TYPE(
251 'filename',
252 ['string', 'URL'],
253 filename,
254 );
255 } else if (path.isAbsolute(filename) ||
256 RegExpPrototypeExec(/^\.\.?[\\/]/, filename) !== null) {
257 filename = path.resolve(filename);
258 url = pathToFileURL(filename);
259 } else {
260 throw new ERR_WORKER_PATH(filename);
261 }
262 }
263
264 let env;

Callers

nothing calls this directly

Calls 15

throwIfBuildingSnapshotFunction · 0.85
fileURLToPathFunction · 0.85
parseResourceLimitsFunction · 0.85
pipeWithoutWarningFunction · 0.85
createMainThreadPortFunction · 0.85
setupPortReferencingFunction · 0.85
isURLFunction · 0.70
pathToFileURLFunction · 0.70
sendMethod · 0.65
debugFunction · 0.50
resolveMethod · 0.45
onMethod · 0.45

Tested by

no test coverage detected