Skip to content

Commit

Permalink
lib: avoid using forEach
Browse files Browse the repository at this point in the history
PR-URL: nodejs#11582
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
jasnell authored and jungx098 committed Mar 21, 2017
1 parent 09dbaef commit 5b0fd7e
Showing 1 changed file with 40 additions and 25 deletions.
65 changes: 40 additions & 25 deletions lib/internal/bootstrap_node.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,23 +208,34 @@
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,
enumerable: true,
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;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 5b0fd7e

Please sign in to comment.