Skip to content

Commit

Permalink
lib: avoid using forEach
Browse files Browse the repository at this point in the history
PR-URL: #11582
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
  • Loading branch information
jasnell committed Mar 17, 2017
1 parent f6dbead commit 989713d
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 989713d

Please sign in to comment.