Skip to content

Commit 63f0d86

Browse files
committed
src: deprecate undocumented variables
The `root` and `GLOBAL` never be documented.
1 parent 2c686fd commit 63f0d86

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/node.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,28 @@
159159
startup.globalVariables = function() {
160160
global.process = process;
161161
global.global = global;
162-
global.GLOBAL = global;
163-
global.root = global;
162+
163+
// Deprecate GLOBAL and root
164+
['GLOBAL', 'root'].forEach(function (name) {
165+
// getter
166+
const get = NativeModule.require('util').deprecate(function() {
167+
const desc = { configurable: true, enumerable: true, value: this };
168+
Object.defineProperty(this, 'GLOBAL', desc);
169+
return this;
170+
}, "'" + name + "' is deprecated, use 'global'");
171+
// setter
172+
const set = function(value) {
173+
const desc = { configurable: true, enumerable: true, value: value };
174+
Object.defineProperty(this, name, desc);
175+
};
176+
// define property
177+
Object.defineProperty(global, name, {
178+
configurable: true, // but not enumerable
179+
get: get,
180+
set: set
181+
});
182+
});
183+
164184
global.Buffer = NativeModule.require('buffer').Buffer;
165185
process.domain = null;
166186
process._exiting = false;

0 commit comments

Comments
 (0)