Skip to content
Permalink
Browse files

lib: avoid using forEach

PR-URL: #11582
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information...
jasnell committed Feb 27, 2017
1 parent f6dbead commit 989713d34362945c9b075ccbc62139977c6c1af0
Showing with 40 additions and 25 deletions.
  1. +40 −25 lib/internal/bootstrap_node.js
@@ -208,23 +208,34 @@
global.process = process; global.process = process;
const util = NativeModule.require('util'); const util = NativeModule.require('util');


// Deprecate GLOBAL and root function makeGetter(name) {
['GLOBAL', 'root'].forEach(function(name) { return util.deprecate(function() {
// getter
const get = util.deprecate(function() {
return this; return this;
}, `'${name}' is deprecated, use 'global'`, 'DEP0016'); }, `'${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, { Object.defineProperty(this, name, {
configurable: true, configurable: true,
writable: true, writable: true,
enumerable: true, enumerable: true,
value: value value: value
}); });
}, `'${name}' is deprecated, use 'global'`, 'DEP0016'); }, `'${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; global.Buffer = NativeModule.require('buffer').Buffer;
@@ -328,27 +339,31 @@
// With no argument, getVersion() returns a comma separated list // With no argument, getVersion() returns a comma separated list
// of possible types. // of possible types.
const versionTypes = icu.getVersion().split(','); 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, { Object.defineProperty(process.versions, name, {
configurable: true, configurable: true,
enumerable: true, enumerable: true,
get: () => { get: makeGetter(name)
// 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;
}
}); });
}); }
} }


function tryGetCwd(path) { function tryGetCwd(path) {

0 comments on commit 989713d

Please sign in to comment.
You can’t perform that action at this time.