Skip to content

Commit 4e46931

Browse files
JacksonTianbnoordhuis
authored andcommitted
src: deprecate undocumented variables
The `root` and `GLOBAL` were never documented. PR-URL: #1838 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Сковорода Никита Андреевич <[email protected]> Reviewed-By: Roman Reiss <[email protected]> Reviewed By: Sakthipriyan Vairamani <[email protected]>
1 parent b212be0 commit 4e46931

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/node.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,27 @@
222222
startup.globalVariables = function() {
223223
global.process = process;
224224
global.global = global;
225-
global.GLOBAL = global;
226-
global.root = global;
225+
const util = NativeModule.require('util');
226+
227+
// Deprecate GLOBAL and root
228+
['GLOBAL', 'root'].forEach(function(name) {
229+
// getter
230+
const get = util.deprecate(function() {
231+
return this;
232+
}, `'${name}' is deprecated, use 'global'`);
233+
// setter
234+
const set = util.deprecate(function(value) {
235+
Object.defineProperty(this, name, {
236+
configurable: true,
237+
writable: true,
238+
enumerable: true,
239+
value: value
240+
});
241+
}, `'${name}' is deprecated, use 'global'`);
242+
// define property
243+
Object.defineProperty(global, name, { get, set, configurable: true });
244+
});
245+
227246
global.Buffer = NativeModule.require('buffer').Buffer;
228247
process.domain = null;
229248
process._exiting = false;

0 commit comments

Comments
 (0)