Skip to content

Commit 0ef363b

Browse files
committed
fix: eliminate for ... of syntax
1 parent 947a949 commit 0ef363b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+544
-199
lines changed

lib/_http_outgoing.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,8 @@ OutgoingMessage.prototype.uncork = function uncork() {
288288
}
289289
}
290290
this._send(crlf_buf, null, callbacks.length ? (err) => {
291-
for (const callback of callbacks) {
291+
for (let i = 0; i < callbacks.length; i++) {
292+
const callback = callbacks[i];
292293
callback(err);
293294
}
294295
} : null);
@@ -675,7 +676,8 @@ OutgoingMessage.prototype.setHeaders = function setHeaders(headers) {
675676
// set-cookie values in array and set them all at once.
676677
const cookies = [];
677678

678-
for (const { 0: key, 1: value } of headers) {
679+
for (let i = 0; i < headers.length; i++) {
680+
const { 0: key, 1: value } = headers[i];
679681
if (key === 'set-cookie') {
680682
if (ArrayIsArray(value)) {
681683
cookies.push(...value);

lib/_http_server.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,9 @@ ServerResponse.prototype.writeEarlyHints = function writeEarlyHints(hints, cb) {
330330

331331
head += 'Link: ' + link + '\r\n';
332332

333-
for (const key of ObjectKeys(hints)) {
333+
const hintKeys = ObjectKeys(hints);
334+
for (let i = 0; i < hintKeys.length; i++) {
335+
const key = hintKeys[i];
334336
if (key !== 'link') {
335337
head += key + ': ' + hints[key] + '\r\n';
336338
}

lib/assert.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,8 @@ assert.partialDeepStrictEqual = function partialDeepStrictEqual(
350350

351351
class Comparison {
352352
constructor(obj, keys, actual) {
353-
for (const key of keys) {
353+
for (let i = 0; i < keys.length; i++) {
354+
const key = keys[i];
354355
if (key in obj) {
355356
if (actual !== undefined &&
356357
typeof actual[key] === 'string' &&
@@ -433,7 +434,8 @@ function expectedException(actual, expected, message, fn) {
433434
expected, 'may not be an empty object');
434435
}
435436
if (isDeepEqual === undefined) lazyLoadComparison();
436-
for (const key of keys) {
437+
for (let i = 0; i < keys.length; i++) {
438+
const key = keys[i];
437439
if (typeof actual[key] === 'string' &&
438440
isRegExp(expected[key]) &&
439441
RegExpPrototypeExec(expected[key], actual[key]) !== null) {
@@ -722,7 +724,8 @@ assert.ifError = function ifError(err) {
722724
);
723725
// Filter all frames existing in err.stack.
724726
let newFrames = StringPrototypeSplit(newErr.stack, '\n');
725-
for (const errFrame of originalFrames) {
727+
for (let i = 0; i < originalFrames.length; i++) {
728+
const errFrame = originalFrames[i];
726729
// Find the first occurrence of the frame.
727730
const pos = ArrayPrototypeIndexOf(newFrames, errFrame);
728731
if (pos !== -1) {

lib/child_process.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -554,8 +554,10 @@ function copyPermissionModelFlagsToEnv(env, key, args) {
554554
}
555555

556556
const flagsToCopy = getPermissionModelFlagsToCopy();
557-
for (const arg of process.execArgv) {
558-
for (const flag of flagsToCopy) {
557+
for (let i = 0; i < process.execArgv.length; i++) {
558+
const arg = process.execArgv[i];
559+
for (let j = 0; j < flagsToCopy.length; j++) {
560+
const flag = flagsToCopy[j];
559561
if (arg.startsWith(flag)) {
560562
env[key] = `${env[key] ? env[key] + ' ' + arg : arg}`;
561563
}
@@ -727,7 +729,8 @@ function normalizeSpawnArguments(file, args, options) {
727729
);
728730
}
729731

730-
for (const key of envKeys) {
732+
for (let i = 0; i < envKeys.length; i++) {
733+
const key = envKeys[i];
731734
const value = env[key];
732735
if (value !== undefined) {
733736
validateArgumentNullCheck(key, `options.env['${key}']`);

lib/dgram.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,8 +591,10 @@ function clearQueue() {
591591
state.queue = undefined;
592592

593593
// Flush the send queue.
594-
for (const queueEntry of queue)
594+
for (let i = 0; i < queue.length; i++) {
595+
const queueEntry = queue[i];
595596
queueEntry();
597+
}
596598
}
597599

598600
// valid combinations

lib/diagnostics_channel.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
const {
4+
ArrayFrom,
45
ArrayPrototypeAt,
56
ArrayPrototypeIndexOf,
67
ArrayPrototypePush,
@@ -162,7 +163,9 @@ class ActiveChannel {
162163
return ReflectApply(fn, thisArg, args);
163164
};
164165

165-
for (const entry of this._stores.entries()) {
166+
const storeEntries = ArrayFrom(this._stores.entries());
167+
for (let i = 0; i < storeEntries.length; i++) {
168+
const entry = storeEntries[i];
166169
const store = entry[0];
167170
const transform = entry[1];
168171
run = wrapStoreRun(store, data, run, transform);

lib/events.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,9 @@ EventEmitter.prototype.removeAllListeners =
751751

752752
// Emit removeListener for all listeners on all events
753753
if (arguments.length === 0) {
754-
for (const key of ReflectOwnKeys(events)) {
754+
const eventKeys = ReflectOwnKeys(events);
755+
for (let i = 0; i < eventKeys.length; i++) {
756+
const key = eventKeys[i];
755757
if (key === 'removeListener') continue;
756758
this.removeAllListeners(key);
757759
}

lib/inspector.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
const {
4+
ArrayFrom,
45
JSONParse,
56
JSONStringify,
67
SafeMap,
@@ -150,8 +151,9 @@ class Session extends EventEmitter {
150151
return;
151152
this.#connection.disconnect();
152153
this.#connection = null;
153-
const remainingCallbacks = this.#messageCallbacks.values();
154-
for (const callback of remainingCallbacks) {
154+
const remainingCallbacks = ArrayFrom(this.#messageCallbacks.values());
155+
for (let i = 0; i < remainingCallbacks.length; i++) {
156+
const callback = remainingCallbacks[i];
155157
process.nextTick(callback, new ERR_INSPECTOR_CLOSED());
156158
}
157159
this.#messageCallbacks.clear();

lib/internal/abort_controller.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// in https://github.com/mysticatea/abort-controller (MIT license)
55

66
const {
7+
ArrayFrom,
78
ArrayPrototypePush,
89
ObjectAssign,
910
ObjectDefineProperties,
@@ -296,7 +297,9 @@ class AbortSignal extends EventTarget {
296297
} else if (!signal[kSourceSignals]) {
297298
continue;
298299
} else {
299-
for (const sourceSignalWeakRef of signal[kSourceSignals]) {
300+
const sourceSignalWeakRefs = ArrayFrom(signal[kSourceSignals]);
301+
for (let i = 0; i < sourceSignalWeakRefs.length; i++) {
302+
const sourceSignalWeakRef = sourceSignalWeakRefs[i];
300303
const sourceSignal = sourceSignalWeakRef.deref();
301304
if (!sourceSignal) {
302305
continue;

lib/internal/assert/utils.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
const {
4+
ArrayFrom,
45
ArrayPrototypeShift,
56
Error,
67
ErrorCaptureStackTrace,
@@ -126,7 +127,9 @@ function parseCode(code, offset) {
126127
let node;
127128
let start;
128129
// Parse the read code until the correct expression is found.
129-
for (const token of tokenizer(code, { ecmaVersion: 'latest' })) {
130+
const tokens = ArrayFrom(tokenizer(code, { ecmaVersion: 'latest' }));
131+
for (let i = 0; i < tokens.length; i++) {
132+
const token = tokens[i];
130133
start = token.start;
131134
if (start > offset) {
132135
// No matching expression found. This could happen if the assert
@@ -222,7 +225,8 @@ function getErrMessage(message, fn) {
222225
}
223226
const frames = StringPrototypeSplit(message, '\n');
224227
message = ArrayPrototypeShift(frames);
225-
for (const frame of frames) {
228+
for (let i = 0; i < frames.length; i++) {
229+
const frame = frames[i];
226230
let pos = 0;
227231
while (pos < column && (frame[pos] === ' ' || frame[pos] === '\t')) {
228232
pos++;

0 commit comments

Comments
 (0)