|
208 | 208 | global.process = process;
|
209 | 209 | const util = NativeModule.require('util');
|
210 | 210 |
|
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() { |
215 | 213 | return this;
|
216 | 214 | }, `'${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) { |
219 | 219 | Object.defineProperty(this, name, {
|
220 | 220 | configurable: true,
|
221 | 221 | writable: true,
|
222 | 222 | enumerable: true,
|
223 | 223 | value: value
|
224 | 224 | });
|
225 | 225 | }, `'${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 | + } |
228 | 239 | });
|
229 | 240 |
|
230 | 241 | global.Buffer = NativeModule.require('buffer').Buffer;
|
|
328 | 339 | // With no argument, getVersion() returns a comma separated list
|
329 | 340 | // of possible types.
|
330 | 341 | 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]; |
333 | 361 | Object.defineProperty(process.versions, name, {
|
334 | 362 | configurable: true,
|
335 | 363 | 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) |
350 | 365 | });
|
351 |
| - }); |
| 366 | + } |
352 | 367 | }
|
353 | 368 |
|
354 | 369 | function tryGetCwd(path) {
|
|
0 commit comments