Skip to content

Commit 95c28f8

Browse files
committed
lib: remove multiple noop definition
Define `noop` in `internal/util`. And use it elsewhere.
1 parent 978b57d commit 95c28f8

File tree

11 files changed

+20
-25
lines changed

11 files changed

+20
-25
lines changed

lib/_http_server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ const {
8080
} = codes;
8181
const {
8282
kEmptyObject,
83+
noop,
8384
} = require('internal/util');
8485
const {
8586
validateInteger,
@@ -809,7 +810,6 @@ function onParserTimeout(server, socket) {
809810
socket.destroy();
810811
}
811812

812-
const noop = () => {};
813813
const badRequestResponse = Buffer.from(
814814
`HTTP/1.1 400 ${STATUS_CODES[400]}\r\n` +
815815
'Connection: close\r\n\r\n', 'ascii',

lib/_tls_wrap.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ const {
2525
ArrayPrototypeForEach,
2626
ArrayPrototypeJoin,
2727
ArrayPrototypePush,
28-
FunctionPrototype,
2928
ObjectAssign,
3029
ObjectDefineProperty,
3130
ObjectSetPrototypeOf,
@@ -43,6 +42,7 @@ const {
4342
assertCrypto,
4443
deprecate,
4544
kEmptyObject,
45+
noop,
4646
} = require('internal/util');
4747

4848
assertCrypto();
@@ -114,8 +114,6 @@ const kPskIdentityHint = Symbol('pskidentityhint');
114114
const kPendingSession = Symbol('pendingSession');
115115
const kIsVerified = Symbol('verified');
116116

117-
const noop = FunctionPrototype;
118-
119117
let ipServernameWarned = false;
120118
let tlsTracingWarned = false;
121119

lib/internal/assert/calltracker.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const {
44
ArrayPrototypePush,
55
ArrayPrototypeSlice,
66
Error,
7-
FunctionPrototype,
87
ObjectFreeze,
98
Proxy,
109
ReflectApply,
@@ -19,12 +18,11 @@ const {
1918
},
2019
} = require('internal/errors');
2120
const AssertionError = require('internal/assert/assertion_error');
21+
const { noop } = require('internal/util');
2222
const {
2323
validateUint32,
2424
} = require('internal/validators');
2525

26-
const noop = FunctionPrototype;
27-
2826
class CallTrackerContext {
2927
#expected;
3028
#calls;

lib/internal/cluster/child.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
const {
44
ArrayPrototypeJoin,
5-
FunctionPrototype,
65
ObjectAssign,
76
ReflectApply,
87
SafeMap,
@@ -17,12 +16,12 @@ const Worker = require('internal/cluster/worker');
1716
const { internal, sendHelper } = require('internal/cluster/utils');
1817
const { exitCodes: { kNoFailure } } = internalBinding('errors');
1918
const { TIMEOUT_MAX } = require('internal/timers');
19+
const { noop } = require('internal/util');
2020
const { setInterval, clearInterval } = require('timers');
2121

2222
const cluster = new EventEmitter();
2323
const handles = new SafeMap();
2424
const indexes = new SafeMap();
25-
const noop = FunctionPrototype;
2625

2726
module.exports = cluster;
2827

lib/internal/modules/esm/module_job.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const {
44
ArrayPrototypeJoin,
55
ArrayPrototypePush,
66
ArrayPrototypeSome,
7-
FunctionPrototype,
87
ObjectSetPrototypeOf,
98
PromiseResolve,
109
PromisePrototypeThen,
@@ -21,15 +20,16 @@ const {
2120

2221
const { ModuleWrap } = internalBinding('module_wrap');
2322

24-
const { decorateErrorStack } = require('internal/util');
23+
const {
24+
decorateErrorStack,
25+
noop,
26+
} = require('internal/util');
2527
const {
2628
getSourceMapsEnabled,
2729
} = require('internal/source_map/source_map_cache');
2830
const assert = require('internal/assert');
2931
const resolvedPromise = PromiseResolve();
3032

31-
const noop = FunctionPrototype;
32-
3333
let hasPausedEntry = false;
3434

3535
const CJSGlobalLike = [

lib/internal/repl/await.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const {
66
ArrayPrototypeJoin,
77
ArrayPrototypePop,
88
ArrayPrototypePush,
9-
FunctionPrototype,
109
ObjectKeys,
1110
RegExpPrototypeSymbolReplace,
1211
StringPrototypeEndsWith,
@@ -21,12 +20,12 @@ const {
2120
const parser = require('internal/deps/acorn/acorn/dist/acorn').Parser;
2221
const walk = require('internal/deps/acorn/acorn-walk/dist/walk');
2322
const { Recoverable } = require('internal/repl');
23+
const { noop } = require('internal/util');
2424

2525
function isTopLevelDeclaration(state) {
2626
return state.ancestors[state.ancestors.length - 2] === state.body;
2727
}
2828

29-
const noop = FunctionPrototype;
3029
const visitorsWithoutAncestors = {
3130
ClassDeclaration(node, state, c) {
3231
if (isTopLevelDeclaration(state)) {

lib/internal/repl/history.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
const {
44
ArrayPrototypeJoin,
55
Boolean,
6-
FunctionPrototype,
76
RegExpPrototypeSymbolSplit,
87
StringPrototypeTrim,
98
} = primordials;
@@ -16,10 +15,9 @@ let debug = require('internal/util/debuglog').debuglog('repl', (fn) => {
1615
debug = fn;
1716
});
1817
const permission = require('internal/process/permission');
18+
const { noop } = require('internal/util');
1919
const { clearTimeout, setTimeout } = require('timers');
2020

21-
const noop = FunctionPrototype;
22-
2321
// XXX(chrisdickinson): The 15ms debounce value is somewhat arbitrary.
2422
// The debounce is to guard against code pasted into the REPL.
2523
const kDebounceHistoryMS = 15;

lib/internal/test_runner/test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const {
66
ArrayPrototypeSlice,
77
ArrayPrototypeSome,
88
ArrayPrototypeUnshift,
9-
FunctionPrototype,
109
MathMax,
1110
Number,
1211
ObjectSeal,
@@ -41,6 +40,7 @@ const {
4140
const {
4241
createDeferredPromise,
4342
kEmptyObject,
43+
noop,
4444
once: runOnce,
4545
} = require('internal/util');
4646
const { isPromise } = require('internal/util/types');
@@ -63,7 +63,6 @@ const kTestCodeFailure = 'testCodeFailure';
6363
const kTestTimeoutFailure = 'testTimeoutFailure';
6464
const kHookFailure = 'hookFailed';
6565
const kDefaultTimeout = null;
66-
const noop = FunctionPrototype;
6766
const kShouldAbort = Symbol('kShouldAbort');
6867
const kFilename = process.argv?.[1];
6968
const kHookNames = ObjectSeal(['before', 'after', 'beforeEach', 'afterEach']);

lib/internal/util.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const {
88
ArrayPrototypeSlice,
99
ArrayPrototypeSort,
1010
Error,
11+
FunctionPrototype,
1112
FunctionPrototypeCall,
1213
ObjectDefineProperties,
1314
ObjectDefineProperty,
@@ -65,6 +66,8 @@ const { isNativeError } = internalBinding('types');
6566

6667
const noCrypto = !process.versions.openssl;
6768

69+
const noop = FunctionPrototype;
70+
6871
const experimentalWarnings = new SafeSet();
6972

7073
const colorRegExp = /\u001b\[\d\d?m/g; // eslint-disable-line no-control-regex
@@ -777,6 +780,7 @@ module.exports = {
777780
join,
778781
lazyDOMException,
779782
lazyDOMExceptionClass,
783+
noop,
780784
normalizeEncoding,
781785
once,
782786
promisify,

lib/internal/util/debuglog.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const {
99
StringPrototypeToUpperCase,
1010
} = primordials;
1111

12+
const { noop } = require('internal/util');
1213
const { inspect, format, formatWithOptions } = require('internal/util/inspect');
1314

1415
// `debugImpls` and `testEnabled` are deliberately not initialized so any call
@@ -43,8 +44,6 @@ function emitWarningIfNeeded(set) {
4344
}
4445
}
4546

46-
const noop = () => {};
47-
4847
function debuglogImpl(enabled, set) {
4948
if (debugImpls[set] === undefined) {
5049
if (enabled) {

lib/net.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,10 @@ const {
109109
} = require('internal/errors');
110110
const { isUint8Array } = require('internal/util/types');
111111
const { queueMicrotask } = require('internal/process/task_queues');
112-
const { kEmptyObject } = require('internal/util');
112+
const {
113+
kEmptyObject,
114+
noop,
115+
} = require('internal/util');
113116
const {
114117
validateAbortSignal,
115118
validateBoolean,
@@ -139,8 +142,6 @@ const DEFAULT_IPV6_ADDR = '::';
139142

140143
const isWindows = process.platform === 'win32';
141144

142-
const noop = () => {};
143-
144145
const kPerfHooksNetConnectContext = Symbol('kPerfHooksNetConnectContext');
145146

146147
const dc = require('diagnostics_channel');

0 commit comments

Comments
 (0)