(filename, options = kEmptyObject)
| 205 | |
| 206 | class 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; |
nothing calls this directly
no test coverage detected