Skip to content

Commit 989713d

Browse files
committed
lib: avoid using forEach
PR-URL: #11582 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent f6dbead commit 989713d

File tree

1 file changed

+40
-25
lines changed

1 file changed

+40
-25
lines changed

lib/internal/bootstrap_node.js

+40-25
Original file line numberDiff line numberDiff line change
@@ -208,23 +208,34 @@
208208
global.process = process;
209209
const util = NativeModule.require('util');
210210

211-
// Deprecate GLOBAL and root
212-
['GLOBAL', 'root'].forEach(function(name) {
213-
// getter
214-
const get = util.deprecate(function() {
211+
function makeGetter(name) {
212+
return util.deprecate(function() {
215213
return this;
216214
}, `'${name}' is deprecated, use 'global'`, 'DEP0016');
217-
// setter
218-
const set = util.deprecate(function(value) {
215+
}
216+
217+
function makeSetter(name) {
218+
return util.deprecate(function(value) {
219219
Object.defineProperty(this, name, {
220220
configurable: true,
221221
writable: true,
222222
enumerable: true,
223223
value: value
224224
});
225225
}, `'${name}' is deprecated, use 'global'`, 'DEP0016');
226-
// define property
227-
Object.defineProperty(global, name, { get, set, configurable: true });
226+
}
227+
228+
Object.defineProperties(global, {
229+
GLOBAL: {
230+
configurable: true,
231+
get: makeGetter('GLOBAL'),
232+
set: makeSetter('GLOBAL')
233+
},
234+
root: {
235+
configurable: true,
236+
get: makeGetter('root'),
237+
set: makeSetter('root')
238+
}
228239
});
229240

230241
global.Buffer = NativeModule.require('buffer').Buffer;
@@ -328,27 +339,31 @@
328339
// With no argument, getVersion() returns a comma separated list
329340
// of possible types.
330341
const versionTypes = icu.getVersion().split(',');
331-
versionTypes.forEach((name) => {
332-
// Copied from module.js:addBuiltinLibsToObject
342+
343+
function makeGetter(name) {
344+
return () => {
345+
// With an argument, getVersion(type) returns
346+
// the actual version string.
347+
const version = icu.getVersion(name);
348+
// Replace the current getter with a new property.
349+
delete process.versions[name];
350+
Object.defineProperty(process.versions, name, {
351+
value: version,
352+
writable: false,
353+
enumerable: true
354+
});
355+
return version;
356+
};
357+
}
358+
359+
for (var n = 0; n < versionTypes.length; n++) {
360+
var name = versionTypes[n];
333361
Object.defineProperty(process.versions, name, {
334362
configurable: true,
335363
enumerable: true,
336-
get: () => {
337-
// With an argument, getVersion(type) returns
338-
// the actual version string.
339-
const version = icu.getVersion(name);
340-
// Replace the current getter with a new
341-
// property.
342-
delete process.versions[name];
343-
Object.defineProperty(process.versions, name, {
344-
value: version,
345-
writable: false,
346-
enumerable: true
347-
});
348-
return version;
349-
}
364+
get: makeGetter(name)
350365
});
351-
});
366+
}
352367
}
353368

354369
function tryGetCwd(path) {

0 commit comments

Comments
 (0)