| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c480559 commit 3e6e3ab
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2420,6 +2420,13 @@ error indicates that the idle loop has failed to stop. | |||
| 2420 | 2420 | An attempt was made to use operations that can only be used when building | |
| 2421 | 2421 | V8 startup snapshot even though Node.js isn't building one. | |
| 2422 | 2422 | ||
| 2423 | + <a id="ERR_NOT_SUPPORTED_IN_SNAPSHOT"></a> | ||
| 2424 | + | ||
| 2425 | + ### `ERR_NOT_SUPPORTED_IN_SNAPSHOT` | ||
| 2426 | + | ||
| 2427 | + An attempt was made to perform operations that are not supported when | ||
| 2428 | + building a startup snapshot. | ||
| 2429 | + | ||
| 2423 | 2430 | <a id="ERR_NO_CRYPTO"></a> | |
| 2424 | 2431 | ||
| 2425 | 2432 | ### `ERR_NO_CRYPTO` | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1469,6 +1469,8 @@ E('ERR_NETWORK_IMPORT_DISALLOWED', | |||
| 1469 | 1469 | "import of '%s' by %s is not supported: %s", Error); | |
| 1470 | 1470 | E('ERR_NOT_BUILDING_SNAPSHOT', | |
| 1471 | 1471 | 'Operation cannot be invoked when not building startup snapshot', Error); | |
| 1472 | + E('ERR_NOT_SUPPORTED_IN_SNAPSHOT', | ||
| 1473 | + '%s is not supported in startup snapshot', Error); | ||
| 1472 | 1474 | E('ERR_NO_CRYPTO', | |
| 1473 | 1475 | 'Node.js is not compiled with OpenSSL crypto support', Error); | |
| 1474 | 1476 | E('ERR_NO_ICU', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,6 +6,7 @@ const { | |||
| 6 | 6 | const { | |
| 7 | 7 | codes: { | |
| 8 | 8 | ERR_NOT_BUILDING_SNAPSHOT, | |
| 9 | + ERR_NOT_SUPPORTED_IN_SNAPSHOT, | ||
| 9 | 10 | ERR_DUPLICATE_STARTUP_SNAPSHOT_MAIN_FUNCTION, | |
| 10 | 11 | }, | |
| 11 | 12 | } = require('internal/errors'); | |
@@ -14,7 +15,7 @@ const { | |||
| 14 | 15 | setSerializeCallback, | |
| 15 | 16 | setDeserializeCallback, | |
| 16 | 17 | setDeserializeMainFunction: _setDeserializeMainFunction, | |
| 17 | - isBuildingSnapshotBuffer | ||
| 18 | + isBuildingSnapshotBuffer, | ||
| 18 | 19 | } = internalBinding('mksnapshot'); | |
| 19 | 20 | ||
| 20 | 21 | function isBuildingSnapshot() { | |
@@ -27,6 +28,12 @@ function throwIfNotBuildingSnapshot() { | |||
| 27 | 28 | } | |
| 28 | 29 | } | |
| 29 | 30 | ||
| 31 | + function throwIfBuildingSnapshot(reason) { | ||
| 32 | + if (isBuildingSnapshot()) { | ||
| 33 | + throw new ERR_NOT_SUPPORTED_IN_SNAPSHOT(reason); | ||
| 34 | + } | ||
| 35 | + } | ||
| 36 | + | ||
| 30 | 37 | const deserializeCallbacks = []; | |
| 31 | 38 | let deserializeCallbackIsSet = false; | |
| 32 | 39 | function runDeserializeCallbacks() { | |
@@ -102,6 +109,7 @@ function setDeserializeMainFunction(callback, data) { | |||
| 102 | 109 | module.exports = { | |
| 103 | 110 | initializeCallbacks, | |
| 104 | 111 | runDeserializeCallbacks, | |
| 112 | + throwIfBuildingSnapshot, | ||
| 105 | 113 | // Exposed to require('v8').startupSnapshot | |
| 106 | 114 | namespace: { | |
| 107 | 115 | addDeserializeCallback, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -60,7 +60,9 @@ const { deserializeError } = require('internal/error_serdes'); | |||
| 60 | 60 | const { fileURLToPath, isURL, pathToFileURL } = require('internal/url'); | |
| 61 | 61 | const { kEmptyObject } = require('internal/util'); | |
| 62 | 62 | const { validateArray, validateString } = require('internal/validators'); | |
| 63 | - | ||
| 63 | + const { | ||
| 64 | + throwIfBuildingSnapshot, | ||
| 65 | + } = require('internal/v8/startup_snapshot'); | ||
| 64 | 66 | const { | |
| 65 | 67 | ownsProcessState, | |
| 66 | 68 | isMainThread, | |
@@ -129,6 +131,7 @@ function assignEnvironmentData(data) { | |||
| 129 | 131 | ||
| 130 | 132 | class Worker extends EventEmitter { | |
| 131 | 133 | constructor(filename, options = kEmptyObject) { | |
| 134 | + throwIfBuildingSnapshot('Creating workers'); | ||
| 132 | 135 | super(); | |
| 133 | 136 | const isInternal = arguments[2] === kIsInternal; | |
| 134 | 137 | debug( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,5 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const { Worker } = require('worker_threads'); | ||
| 4 | + | ||
| 5 | + new Worker('1', { eval: true }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,34 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + // This tests snapshot JS API using the example in the docs. | ||
| 4 | + | ||
| 5 | + require('../common'); | ||
| 6 | + const assert = require('assert'); | ||
| 7 | + const { spawnSync } = require('child_process'); | ||
| 8 | + const tmpdir = require('../common/tmpdir'); | ||
| 9 | + const fixtures = require('../common/fixtures'); | ||
| 10 | + const path = require('path'); | ||
| 11 | + const fs = require('fs'); | ||
| 12 | + | ||
| 13 | + tmpdir.refresh(); | ||
| 14 | + const blobPath = path.join(tmpdir.path, 'snapshot.blob'); | ||
| 15 | + const entry = fixtures.path('snapshot', 'worker.js'); | ||
| 16 | + { | ||
| 17 | + const child = spawnSync(process.execPath, [ | ||
| 18 | + '--snapshot-blob', | ||
| 19 | + blobPath, | ||
| 20 | + '--build-snapshot', | ||
| 21 | + entry, | ||
| 22 | + ], { | ||
| 23 | + cwd: tmpdir.path | ||
| 24 | + }); | ||
| 25 | + const stderr = child.stderr.toString(); | ||
| 26 | + assert.match( | ||
| 27 | + stderr, | ||
| 28 | + /Error: Creating workers is not supported in startup snapshot/); | ||
| 29 | + assert.match( | ||
| 30 | + stderr, | ||
| 31 | + /ERR_NOT_SUPPORTED_IN_SNAPSHOT/); | ||
| 32 | + assert.strictEqual(child.status, 1); | ||
| 33 | + assert(!fs.existsSync(blobPath)); | ||
| 34 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments