Uh oh!
There was an error while loading. Please reload this page.
src: deprecate root and GLOBAL variables - #1838
Conversation
silverwind
commented
May 29, 2015
I think these should be pretty low risk to remove. If someone has an idea on how to print a deprecation warning when accessing the global or its properties, we could also go that route. |
Fishrock123
commented
May 29, 2015
Use a Getter? |
brendanashworth
commented
May 29, 2015
There shouldn't be much code relying on this but there may be some so we do need a deprecation message. edit: btw the commit log should be |
silverwind
commented
May 29, 2015
Won't work for usage like |
Fishrock123
commented
May 29, 2015
@silverwind isn't that still accessing |
silverwind
commented
May 29, 2015
@Fishrock123 right, something like this should work: Object.defineProperty(global,'GLOBAL',{get: function(){util.deprecate(function(){},"'GLOBAL' is deprecated, use 'global'");returnglobal;}});@JacksonTian could you try incorporating such a print to both globals instead of removing them? |
silverwind
commented
May 29, 2015
Better one: Object.defineProperty(global,'GLOBAL',{get: util.deprecate(function(){returnglobal;},"'GLOBAL' is deprecated, use 'global'")}); |
targos
commented
May 29, 2015
maybe also make the property writable ? |
silverwind
commented
May 29, 2015
Right, this is getting interesting now. Below code should only print once on first read/write access: varg=r=global;varaccessGlobal=util.deprecate(function(val){if(val)g=val;returng;},"'GLOBAL' is deprecated, use 'global'");varaccessRoot=util.deprecate(function(val){if(val)r=val;returnr;},"'root' is deprecated, use 'global'");Object.defineProperty(global,'GLOBAL',{get: accessGlobal,set: accessGlobal});Object.defineProperty(global,'root',{get: accessRoot,set: accessRoot}); |
silverwind
commented
May 29, 2015
One more revision: constholders={GLOBAL: global,root: global};constaccessGlobal=util.deprecate(function(val){if(val)holders.GLOBAL=val;returnholders.GLOBAL;},"'GLOBAL' is deprecated, use 'global'");constaccessRoot=util.deprecate(function(val){if(val)holders.root=val;returnholders.root;},"'root' is deprecated, use 'global'");Object.defineProperty(global,'GLOBAL',{get: accessGlobal,set: accessGlobal});Object.defineProperty(global,'root',{get: accessRoot,set: accessRoot});@JacksonTian feel free to use something like that. Otherwise, I could do a PR that succeeds this one :) |
acbdbcf to
233d4f8CompareJacksonTian
commented
May 30, 2015
@silverwind The PR is updated, please review it again. |
bnoordhuis
commented
May 30, 2015
Apropos assignment, I'd replace the getter/setter inside the setter, e.g.: Object.defineProperty(global,'GLOBAL',{configurable: true,// but not enumerableget: util.deprecate(function(){returnthis;},`'GLOBAL' is deprecated, use 'global'`),set: function(value){constdesc={configurable: true,enumerable: true,value: value};Object.defineProperty(this,'GLOBAL',desc);},});Ditto for get: util.deprecate(function(){constdesc={configurable: true,enumerable: true,value: this};Object.defineProperty(this,'GLOBAL',desc);returnthis;},`'GLOBAL' is deprecated, use 'global'`)That prints a warning on the first access and then gets out of the way. It won't regress code that uses |
silverwind
commented
May 30, 2015
+1 for using @bnoordhuis I have a bit of a hard time understanding why running |
bnoordhuis
commented
May 30, 2015
@silverwind The getter calls |
silverwind
commented
May 30, 2015
@bnoordhuis oh right, thats quite genius! |
targos
commented
May 31, 2015
@bnoordhuis 👍 very clever The setter can be simplified using shorthand property: set(value){constdesc={configurable: true,enumerable: true,value: value};Object.defineProperty(this,'GLOBAL',desc);} |
targos
commented
May 31, 2015
and maybe it should be |
bnoordhuis
commented
May 31, 2015
Good point, it should be writable when setting the value (but not when setting the getter/setter pair.) |
JacksonTian
commented
Jun 1, 2015
Hi everyone, I updated the PR by your comments, thanks. |
There was a problem hiding this comment.
Should be Object.defineProperty(this, name, desc);
There was a problem hiding this comment.
Tiny suggestion: the code might look a little better if you pulled the NativeModule.require('util') out into a variable. Feel free to ignore if you want.
cjihrig
commented
Feb 4, 2016
LGTM with the same suggestions. And +1 to this being semver-major. |
ChALkeR
commented
Feb 4, 2016
|
jasnell
commented
Feb 4, 2016
LGTM as semver-major |
silverwind
commented
Feb 4, 2016
ping @JacksonTian |
brendanashworth
commented
Feb 5, 2016
@bnoordhuis back then, |
The `root` and `GLOBAL` never be documented.
JacksonTian
commented
Feb 8, 2016
Updated. Thanks all. |
thefourtheye
commented
Feb 8, 2016
LGTM |
ChALkeR
commented
Feb 8, 2016
LGTM (if passes CI) |
silverwind
commented
Feb 9, 2016
The `root` and `GLOBAL` were never documented. PR-URL: #1838 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
bnoordhuis
commented
Feb 10, 2016
Unrelated lint error addressed by #5161. Landed in 4e46931, thanks @JacksonTian! |
is removed from node nodejs/node#1838
The
rootandGLOBALnever be documented.