mirror of
https://github.com/nodejs/node.git
synced 2025-05-08 16:45:11 +00:00

Previously to throw errors from C++ land, sync versions of the fs were created by copying C++ code from the original implementation and moving JS code to a separate file. This can lead to several problems: 1. By moving code to a new file for the sake of moving, it would be harder to use git blame to trace changes and harder to backport changes to older branches. 2. Scattering the async and sync versions of fs methods in different files makes it harder to keep them in sync and share code in the prologues and epilogues. 3. Having two copies of code doing almost the same thing results in duplication and can be prone to out-of-sync problems when the prologue and epilogue get updated. 4. There is a minor cost to startup in adding an additional file. This can add up even with the help of snapshots. This patch moves the JS code back to lib/fs.js to stop 1, 2 & 4 and introduces C++ helpers SyncCallAndThrowIf() and SyncCallAndThrowOnError() so that the original implementations can be easily tweaked to allow throwing from C++ and stop 3. PR-URL: https://github.com/nodejs/node/pull/49913 Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
163 lines
5.7 KiB
JavaScript
163 lines
5.7 KiB
JavaScript
// Flags: --expose-internals
|
|
'use strict';
|
|
|
|
// This list must be computed before we require any modules to
|
|
// to eliminate the noise.
|
|
const actualModules = new Set(process.moduleLoadList.slice());
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
|
|
const expectedModules = new Set([
|
|
'Internal Binding builtins',
|
|
'Internal Binding encoding_binding',
|
|
'Internal Binding errors',
|
|
'Internal Binding util',
|
|
'NativeModule internal/errors',
|
|
'Internal Binding config',
|
|
'Internal Binding timers',
|
|
'Internal Binding async_wrap',
|
|
'Internal Binding task_queue',
|
|
'Internal Binding symbols',
|
|
'NativeModule internal/async_hooks',
|
|
'Internal Binding constants',
|
|
'Internal Binding types',
|
|
'NativeModule internal/util',
|
|
'NativeModule internal/util/types',
|
|
'NativeModule internal/validators',
|
|
'NativeModule internal/linkedlist',
|
|
'NativeModule internal/priority_queue',
|
|
'NativeModule internal/assert',
|
|
'NativeModule internal/util/inspect',
|
|
'NativeModule internal/util/debuglog',
|
|
'NativeModule internal/timers',
|
|
'NativeModule events',
|
|
'Internal Binding buffer',
|
|
'Internal Binding string_decoder',
|
|
'NativeModule internal/buffer',
|
|
'NativeModule buffer',
|
|
'Internal Binding messaging',
|
|
'NativeModule internal/worker/js_transferable',
|
|
'Internal Binding process_methods',
|
|
'NativeModule internal/process/per_thread',
|
|
'Internal Binding credentials',
|
|
'NativeModule internal/process/promises',
|
|
'NativeModule internal/fixed_queue',
|
|
'NativeModule async_hooks',
|
|
'NativeModule internal/process/task_queues',
|
|
'NativeModule timers',
|
|
'Internal Binding trace_events',
|
|
'NativeModule internal/constants',
|
|
'NativeModule path',
|
|
'NativeModule internal/process/execution',
|
|
'NativeModule internal/process/permission',
|
|
'NativeModule internal/process/warning',
|
|
'NativeModule internal/console/constructor',
|
|
'NativeModule internal/console/global',
|
|
'NativeModule internal/querystring',
|
|
'NativeModule querystring',
|
|
'Internal Binding url',
|
|
'Internal Binding blob',
|
|
'NativeModule internal/url',
|
|
'NativeModule util',
|
|
'NativeModule internal/webidl',
|
|
'Internal Binding performance',
|
|
'Internal Binding permission',
|
|
'NativeModule internal/perf/utils',
|
|
'NativeModule internal/event_target',
|
|
'Internal Binding mksnapshot',
|
|
'NativeModule internal/v8/startup_snapshot',
|
|
'NativeModule internal/process/signal',
|
|
'Internal Binding fs',
|
|
'NativeModule internal/encoding',
|
|
'NativeModule internal/webstreams/util',
|
|
'NativeModule internal/webstreams/queuingstrategies',
|
|
'NativeModule internal/blob',
|
|
'NativeModule internal/fs/utils',
|
|
'NativeModule fs',
|
|
'Internal Binding options',
|
|
'NativeModule internal/options',
|
|
'NativeModule internal/source_map/source_map_cache',
|
|
'Internal Binding contextify',
|
|
'NativeModule internal/vm',
|
|
'NativeModule internal/modules/helpers',
|
|
'NativeModule internal/modules/package_json_reader',
|
|
'Internal Binding module_wrap',
|
|
'NativeModule internal/modules/cjs/loader',
|
|
'NativeModule internal/vm/module',
|
|
'NativeModule internal/modules/esm/utils',
|
|
'Internal Binding wasm_web_api',
|
|
'Internal Binding worker',
|
|
'NativeModule internal/modules/run_main',
|
|
'NativeModule internal/net',
|
|
'NativeModule internal/dns/utils',
|
|
'NativeModule internal/process/pre_execution',
|
|
]);
|
|
|
|
if (common.isMainThread) {
|
|
[
|
|
'NativeModule internal/idna',
|
|
'NativeModule url',
|
|
].forEach(expectedModules.add.bind(expectedModules));
|
|
} else {
|
|
[
|
|
'NativeModule diagnostics_channel',
|
|
'NativeModule internal/abort_controller',
|
|
'NativeModule internal/error_serdes',
|
|
'NativeModule internal/perf/event_loop_utilization',
|
|
'NativeModule internal/process/worker_thread_only',
|
|
'NativeModule internal/streams/add-abort-signal',
|
|
'NativeModule internal/streams/buffer_list',
|
|
'NativeModule internal/streams/compose',
|
|
'NativeModule internal/streams/destroy',
|
|
'NativeModule internal/streams/duplex',
|
|
'NativeModule internal/streams/end-of-stream',
|
|
'NativeModule internal/streams/from',
|
|
'NativeModule internal/streams/legacy',
|
|
'NativeModule internal/streams/operators',
|
|
'NativeModule internal/streams/passthrough',
|
|
'NativeModule internal/streams/pipeline',
|
|
'NativeModule internal/streams/readable',
|
|
'NativeModule internal/streams/state',
|
|
'NativeModule internal/streams/transform',
|
|
'NativeModule internal/streams/utils',
|
|
'NativeModule internal/streams/writable',
|
|
'NativeModule internal/worker',
|
|
'NativeModule internal/worker/io',
|
|
'NativeModule stream',
|
|
'NativeModule stream/promises',
|
|
'NativeModule string_decoder',
|
|
'NativeModule worker_threads',
|
|
].forEach(expectedModules.add.bind(expectedModules));
|
|
}
|
|
|
|
if (common.isWindows) {
|
|
// On Windows fs needs SideEffectFreeRegExpPrototypeExec which uses vm.
|
|
expectedModules.add('NativeModule vm');
|
|
}
|
|
|
|
if (common.hasIntl) {
|
|
expectedModules.add('Internal Binding icu');
|
|
}
|
|
|
|
if (process.features.inspector) {
|
|
expectedModules.add('Internal Binding inspector');
|
|
expectedModules.add('NativeModule internal/inspector_async_hook');
|
|
expectedModules.add('NativeModule internal/util/inspector');
|
|
}
|
|
|
|
const difference = (setA, setB) => {
|
|
return new Set([...setA].filter((x) => !setB.has(x)));
|
|
};
|
|
const missingModules = difference(expectedModules, actualModules);
|
|
const extraModules = difference(actualModules, expectedModules);
|
|
const printSet = (s) => { return `${[...s].sort().join(',\n ')}\n`; };
|
|
|
|
assert.deepStrictEqual(actualModules, expectedModules,
|
|
(missingModules.size > 0 ?
|
|
'These modules were not loaded:\n ' +
|
|
printSet(missingModules) : '') +
|
|
(extraModules.size > 0 ?
|
|
'These modules were unexpectedly loaded:\n ' +
|
|
printSet(extraModules) : ''));
|