mirror of
https://github.com/nodejs/node.git
synced 2026-10-14 10:26:26 -04:00
lib: avoid using forEach
PR-URL: https://github.com/nodejs/node/pull/11582 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
1 parent
f6dbead126
commit
989713d343
1 file changed
+40
-25
Vendored
+40
-25
@@ -208,14 +208,14 @@
|
||||
global.process = process;
|
||||
const util = NativeModule.require('util');
|
||||
|
||||
// Deprecate GLOBAL and root
|
||||
['GLOBAL', 'root'].forEach(function(name) {
|
||||
// getter
|
||||
const get = util.deprecate(function() {
|
||||
function makeGetter(name) {
|
||||
return util.deprecate(function() {
|
||||
return this;
|
||||
}, `'${name}' is deprecated, use 'global'`, 'DEP0016');
|
||||
// setter
|
||||
const set = util.deprecate(function(value) {
|
||||
}
|
||||
|
||||
function makeSetter(name) {
|
||||
return util.deprecate(function(value) {
|
||||
Object.defineProperty(this, name, {
|
||||
configurable: true,
|
||||
writable: true,
|
||||
@@ -223,8 +223,19 @@
|
||||
value: value
|
||||
});
|
||||
}, `'${name}' is deprecated, use 'global'`, 'DEP0016');
|
||||
// define property
|
||||
Object.defineProperty(global, name, { get, set, configurable: true });
|
||||
}
|
||||
|
||||
Object.defineProperties(global, {
|
||||
GLOBAL: {
|
||||
configurable: true,
|
||||
get: makeGetter('GLOBAL'),
|
||||
set: makeSetter('GLOBAL')
|
||||
},
|
||||
root: {
|
||||
configurable: true,
|
||||
get: makeGetter('root'),
|
||||
set: makeSetter('root')
|
||||
}
|
||||
});
|
||||
|
||||
global.Buffer = NativeModule.require('buffer').Buffer;
|
||||
@@ -328,27 +339,31 @@
|
||||
// With no argument, getVersion() returns a comma separated list
|
||||
// of possible types.
|
||||
const versionTypes = icu.getVersion().split(',');
|
||||
versionTypes.forEach((name) => {
|
||||
// Copied from module.js:addBuiltinLibsToObject
|
||||
|
||||
function makeGetter(name) {
|
||||
return () => {
|
||||
// With an argument, getVersion(type) returns
|
||||
// the actual version string.
|
||||
const version = icu.getVersion(name);
|
||||
// Replace the current getter with a new property.
|
||||
delete process.versions[name];
|
||||
Object.defineProperty(process.versions, name, {
|
||||
value: version,
|
||||
writable: false,
|
||||
enumerable: true
|
||||
});
|
||||
return version;
|
||||
};
|
||||
}
|
||||
|
||||
for (var n = 0; n < versionTypes.length; n++) {
|
||||
var name = versionTypes[n];
|
||||
Object.defineProperty(process.versions, name, {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
get: () => {
|
||||
// With an argument, getVersion(type) returns
|
||||
// the actual version string.
|
||||
const version = icu.getVersion(name);
|
||||
// Replace the current getter with a new
|
||||
// property.
|
||||
delete process.versions[name];
|
||||
Object.defineProperty(process.versions, name, {
|
||||
value: version,
|
||||
writable: false,
|
||||
enumerable: true
|
||||
});
|
||||
return version;
|
||||
}
|
||||
get: makeGetter(name)
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function tryGetCwd(path) {
|
||||
|
||||
Reference in new issue
Block a user