You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
The repl module's default setting for useGlobal invites hard-to-isolate bugs #13827
Platform: Darwin bayswater.local 16.6.0 Darwin Kernel Version 16.6.0: Fri Apr 14 16:21:16 PDT 2017; root:xnu-3789.60.24~6/RELEASE_X86_64 x86_64
Subsystem: repl
I think the built-in repl module's default option value of useGlobal: false is likely very surprising for many use cases, and should be reconsidered. For reference, the node CLI sets this value manually to true, so the REPL that Node users are accustomed to has their code run in a single shared context.
What I just discovered today, while working on testdouble.js with its little repl script is that the consequences of useGlobal defaulting to false are quite striking. We found a very insiduous bug that manifested itself as functions defined in the REPL not seeming to have Object or Function in their prototype chain (which, of course, every function does).
After lots of digging, we discovered it was due to the fact that useGlobal is false by default. For a minimal example of how absurd this seems, see the following output:
$ node -e 'require("repl").start()'
> setTimeout instanceof Function
false
Of course, it's ridiculous that setTimeout, or any built-in/host method would fail an instanceof check with Function. With the node CLI or the useGlobal option manually set to true, however, things behave much more akin to a real-world Node.js program.
$ node -e 'require("repl").start({useGlobal: true})'
> setTimeout instanceof Function
true
$ node
> setTimeout instanceof Function
true
As a result, it seems to me that useGlobal: true would have been a more sensible default for the built-in repl module, but since it's stable, maybe we can at least document the ramifications of this quirk in behavior. Thoughts?
Activity
bnoordhuis commentedon Jun 21, 2017
A documentation pull request would be welcome.
That's due to how stuff is copied over from the main context. Should probably be fixed but that's going to be a fair bit of work.
Fix the repl by using useGlobal
vishwasrao commentedon Jul 12, 2017
Hi, I would like to work on this.
Eager to work on my first contribution.
gibfahn commentedon Jul 13, 2017
@vishwasrao looks like @starkwang already raised a Pull Request for this (#13866).
I'll take off the
good first contributionlabeldoc: add notice about useGlobal option in repl docs
doc: add notice about useGlobal option in repl docs
doc: add notice about useGlobal option in repl docs