| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 90abdd3 commit b73943e
7 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -621,6 +621,13 @@ if (isMainThread) { | |||
| 621 | 621 | <!-- YAML | |
| 622 | 622 | added: v10.5.0 | |
| 623 | 623 | changes: | |
| 624 | + - version: REPLACEME | ||
| 625 | + pr-url: https://github.com/nodejs/node/pull/34584 | ||
| 626 | + description: The `filename` parameter can be a WHATWG `URL` object using | ||
| 627 | + `data:` protocol. | ||
| 628 | + - version: REPLACEME | ||
| 629 | + pr-url: https://github.com/nodejs/node/pull/34394 | ||
| 630 | + description: The `trackUnmanagedFds` option was set to `true` by default. | ||
| 624 | 631 | - version: | |
| 625 | 632 | - v14.6.0 | |
| 626 | 633 | pr-url: https://github.com/nodejs/node/pull/34303 | |
@@ -647,7 +654,9 @@ changes: | |||
| 647 | 654 | * `filename` {string|URL} The path to the Worker’s main script or module. Must | |
| 648 | 655 | be either an absolute path or a relative path (i.e. relative to the | |
| 649 | 656 | current working directory) starting with `./` or `../`, or a WHATWG `URL` | |
| 650 | - object using `file:` protocol. | ||
| 657 | + object using `file:` or `data:` protocol. | ||
| 658 | + When using a [`data:` URL][], the data is interpreted based on MIME type using | ||
| 659 | + the [ECMAScript module loader][]. | ||
| 651 | 660 | If `options.eval` is `true`, this is a string containing JavaScript code | |
| 652 | 661 | rather than a path. | |
| 653 | 662 | * `options` {Object} | |
@@ -893,6 +902,7 @@ active handle in the event system. If the worker is already `unref()`ed calling | |||
| 893 | 902 | [`AsyncResource`]: async_hooks.html#async_hooks_class_asyncresource | |
| 894 | 903 | [`Buffer`]: buffer.html | |
| 895 | 904 | [`Buffer.allocUnsafe()`]: buffer.html#buffer_static_method_buffer_allocunsafe_size | |
| 905 | + [ECMAScript module loader]: esm.html#esm_data_imports | ||
| 896 | 906 | [`ERR_MISSING_MESSAGE_PORT_IN_TRANSFER_LIST`]: errors.html#errors_err_missing_message_port_in_transfer_list | |
| 897 | 907 | [`ERR_WORKER_NOT_RUNNING`]: errors.html#ERR_WORKER_NOT_RUNNING | |
| 898 | 908 | [`EventEmitter`]: events.html | |
@@ -944,3 +954,4 @@ active handle in the event system. If the worker is already `unref()`ed calling | |||
| 944 | 954 | [child processes]: child_process.html | |
| 945 | 955 | [contextified]: vm.html#vm_what_does_it_mean_to_contextify_an_object | |
| 946 | 956 | [v8.serdes]: v8.html#v8_serialization_api | |
| 957 | + [`data:` URL]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1451,6 +1451,9 @@ E('ERR_WORKER_PATH', (filename) => | |||
| 1451 | 1451 | (filename.startsWith('file://') ? | |
| 1452 | 1452 | ' Wrap file:// URLs with `new URL`.' : '' | |
| 1453 | 1453 | ) + | |
| 1454 | + (filename.startsWith('data:text/javascript') ? | ||
| 1455 | + ' Wrap data: URLs with `new URL`.' : '' | ||
| 1456 | + ) + | ||
| 1454 | 1457 | ` Received "${filename}"`, | |
| 1455 | 1458 | TypeError); | |
| 1456 | 1459 | E('ERR_WORKER_UNSERIALIZABLE_ERROR', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -149,7 +149,7 @@ port.on('message', (message) => { | |||
| 149 | 149 | debug(`[${threadId}] starts worker script ${filename} ` + | |
| 150 | 150 | `(eval = ${eval}) at cwd = ${process.cwd()}`); | |
| 151 | 151 | port.postMessage({ type: UP_AND_RUNNING }); | |
| 152 | - if (doEval) { | ||
| 152 | + if (doEval === 'classic') { | ||
| 153 | 153 | const { evalScript } = require('internal/process/execution'); | |
| 154 | 154 | const name = '[worker eval]'; | |
| 155 | 155 | // This is necessary for CJS module compilation. | |
@@ -161,6 +161,11 @@ port.on('message', (message) => { | |||
| 161 | 161 | }); | |
| 162 | 162 | process.argv.splice(1, 0, name); | |
| 163 | 163 | evalScript(name, filename); | |
| 164 | + } else if (doEval === 'module') { | ||
| 165 | + const { evalModule } = require('internal/process/execution'); | ||
| 166 | + evalModule(filename).catch((e) => { | ||
| 167 | + workerOnGlobalUncaughtException(e, true); | ||
| 168 | + }); | ||
| 164 | 169 | } else { | |
| 165 | 170 | // script filename | |
| 166 | 171 | // runMain here might be monkey-patched by users in --require. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -45,7 +45,7 @@ function evalModule(source, print) { | |||
| 45 | 45 | const { log } = require('internal/console/global'); | |
| 46 | 46 | const { loadESM } = require('internal/process/esm_loader'); | |
| 47 | 47 | const { handleMainPromise } = require('internal/modules/run_main'); | |
| 48 | - handleMainPromise(loadESM(async (loader) => { | ||
| 48 | + return handleMainPromise(loadESM(async (loader) => { | ||
| 49 | 49 | const { result } = await loader.eval(source); | |
| 50 | 50 | if (print) { | |
| 51 | 51 | log(result); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,6 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | 5 | const { | |
| 6 | 6 | ArrayIsArray, | |
| 7 | + JSONStringify, | ||
| 7 | 8 | MathMax, | |
| 8 | 9 | ObjectCreate, | |
| 9 | 10 | ObjectEntries, | |
@@ -100,7 +101,7 @@ class Worker extends EventEmitter { | |||
| 100 | 101 | argv = options.argv.map(String); | |
| 101 | 102 | } | |
| 102 | 103 | ||
| 103 | - let url; | ||
| 104 | + let url, doEval; | ||
| 104 | 105 | if (options.eval) { | |
| 105 | 106 | if (typeof filename !== 'string') { | |
| 106 | 107 | throw new ERR_INVALID_ARG_VALUE( | |
@@ -110,7 +111,13 @@ class Worker extends EventEmitter { | |||
| 110 | 111 | ); | |
| 111 | 112 | } | |
| 112 | 113 | url = null; | |
| 114 | + doEval = 'classic'; | ||
| 115 | + } else if (isURLInstance(filename) && filename.protocol === 'data:') { | ||
| 116 | + url = null; | ||
| 117 | + doEval = 'module'; | ||
| 118 | + filename = `import ${JSONStringify(`${filename}`)}`; | ||
| 113 | 119 | } else { | |
| 120 | + doEval = false; | ||
| 114 | 121 | if (isURLInstance(filename)) { | |
| 115 | 122 | url = filename; | |
| 116 | 123 | filename = fileURLToPath(filename); | |
@@ -201,7 +208,7 @@ class Worker extends EventEmitter { | |||
| 201 | 208 | argv, | |
| 202 | 209 | type: messageTypes.LOAD_SCRIPT, | |
| 203 | 210 | filename, | |
| 204 | - doEval: !!options.eval, | ||
| 211 | + doEval, | ||
| 205 | 212 | cwdCounter: cwdCounter || workerIo.sharedCwdCounter, | |
| 206 | 213 | workerData: options.workerData, | |
| 207 | 214 | publicPort: port2, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,25 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common'); | ||
| 4 | + const { Worker } = require('worker_threads'); | ||
| 5 | + const assert = require('assert'); | ||
| 6 | + | ||
| 7 | + new Worker(new URL('data:text/javascript,')) | ||
| 8 | + .on('error', common.mustNotCall(() => {})); | ||
| 9 | + new Worker(new URL('data:text/javascript,export{}')) | ||
| 10 | + .on('error', common.mustNotCall(() => {})); | ||
| 11 | + | ||
| 12 | + new Worker(new URL('data:text/plain,')) | ||
| 13 | + .on('error', common.mustCall(() => {})); | ||
| 14 | + new Worker(new URL('data:text/javascript,module.exports={}')) | ||
| 15 | + .on('error', common.mustCall(() => {})); | ||
| 16 | + | ||
| 17 | + new Worker(new URL('data:text/javascript,await Promise.resolve()')) | ||
| 18 | + .on('error', common.mustNotCall(() => {})); | ||
| 19 | + new Worker(new URL('data:text/javascript,await Promise.reject()')) | ||
| 20 | + .on('error', common.mustCall(() => {})); | ||
| 21 | + new Worker(new URL('data:text/javascript,await new Promise(()=>{})')) | ||
| 22 | + .on( | ||
| 23 | + 'exit', | ||
| 24 | + common.mustCall((exitCode) => { assert.strictEqual(exitCode, 13); }) | ||
| 25 | + ); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -33,6 +33,10 @@ const { Worker } = require('worker_threads'); | |||
| 33 | 33 | () => { new Worker('file:///file_url'); }, | |
| 34 | 34 | /Wrap file:\/\/ URLs with `new URL`/ | |
| 35 | 35 | ); | |
| 36 | + assert.throws( | ||
| 37 | + () => { new Worker('data:text/javascript,'); }, | ||
| 38 | + /Wrap data: URLs with `new URL`/ | ||
| 39 | + ); | ||
| 36 | 40 | assert.throws( | |
| 37 | 41 | () => { new Worker('relative_no_dot'); }, | |
| 38 | 42 | // eslint-disable-next-line node-core/no-unescaped-regexp-dot | |
@@ -47,6 +51,4 @@ const { Worker } = require('worker_threads'); | |||
| 47 | 51 | }; | |
| 48 | 52 | assert.throws(() => { new Worker(new URL('https://www.url.com')); }, | |
| 49 | 53 | expectedErr); | |
| 50 | - assert.throws(() => { new Worker(new URL('data:application/javascript,')); }, | ||
| 51 | - expectedErr); | ||
| 52 | 54 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments