-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The repl module's default setting for useGlobal invites hard-to-isolate bugs #13827
Comments
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. |
This was causing all our metaprogramming that checked types to break. See: nodejs/node#13827
Hi, I would like to work on this. |
@vishwasrao looks like @starkwang already raised a Pull Request for this (#13866). I'll take off the |
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, thenode
CLI sets this value manually totrue
, 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 haveObject
orFunction
in their prototype chain (which, of course, everyfunction
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:Of course, it's ridiculous that
setTimeout
, or any built-in/host method would fail aninstanceof
check withFunction
. With thenode
CLI or theuseGlobal
option manually set totrue
, however, things behave much more akin to a real-world Node.js program.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?The text was updated successfully, but these errors were encountered: