-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Don't use separate context in repl #1484
Comments
Wouldn't that be a regression of #232?
I didn't even know it existed. :-) |
No, because |
#1834, while we're listing "confusion" bugs. |
-1, personally. This is just going to reinforce “bad assumptions” that many are already making about JavaScript. This sort of half-arsedness might be fine in the browser, where “normal development” only leaves you dealing with a single Instead of trying to “fix” this, why don’t we try and educate the users? Perhaps a section in the documentation (yes, it’s a language issue, not a Node issue, but it still widely affects our users, and is something they’ll come into more contact with Node than they would have in previous interactions with JavaScript), and then include a warning with a link to that subsection under the REPL section, the VM section, the modules section, etc? Describe the concept that Again, ‘feels’ outside the scope of Node, but might be a necessity for user-experience purposes: a set of convenience functions for comparing “types” (constructors.) cross-context, something at a higher ‘outside’ level from the user’s module code or the REPL, possibly even exploiting |
I think you're right, @ELLIOTTCABLE, that this might be outside the scope of node. I've personally never liked that |
elliottcable: Unless you're proposing changing the default behavior of require() in node, I don't think your argument makes sense. Right now, the REPL and code run directly in node behave very differently. The REPL is predominantly used for testing/debugging, so making code behave radically differently while debugging than in production is a recipe for confusing users to no good end. Your argument could be applied to encourage changing the default behavior of require() to create each module in a new context (and I can definitely see arguments for doing so), but good luck with that: you'd break the functionality of a large number of existing modules. |
@sethml You can make node load modules in separate contexts by setting NODE_MODULE_CONTEXTS=1, but no one actually does this. It's slow and terrible, and makes for weird behavior. |
Fix nodejs#1484 Fix nodejs#1834 Fix nodejs#1482 Fix nodejs#771 It's been a while now, and we've seen how this separate context thing works. It constantly confuses people, and no one actually uses '.clear' anyway, so the benefit of that feature does not justify the constant WTFery. This makes repl.context actually be a getter that returns the global object, and prints a deprecation warning. The '.clear' command is gone, and will report that it's an invalid repl keyword. Tests updated to allow the require, module, and exports globals, which are still available in the repl just like they were before, by making them global.
@isaacs, I was under the impression that we were moving towards flipping that on as the default. “Slow?” It’s not remotely slow, or shouldn’t be unless Node’s internals are doing something fairly wrong (at least, so it seems from my knowledge of Anyway, besides possible slow-and-terrible-ness that I’m missing, I certainly understand the ideological arguments for/against it. I’m sure it’s something that’s had a lot of thought put into it, and will have much more yet. For whatever reason, I’d just gotten the impression that the general trend was towards eventually flipping that Big Lever to turn it on by default. Long story short: I think the default behaviour of the REPL and the, er, “module environment” should definitely mirror eachother. In fact, the behaviour of the REPL module should almost certainly mirror the state of the |
Yeah, I'm aware of the NODE_MODULE_CONTEXTS=1 environment variable. I strongly agree that the behavior of the REPL and normal code should match. |
-1. Nothing will then force you to make module system work right with contexts and to fix vm.runInThisContext bug when called from other than main context (#898). Lots of problems may disappear if those are fixed (they are related, of course, module system is strange in multiple context because of #898, among others). Better fix the cause, not the symptom. |
@Herby Bugs in vm.runInThisContext need to be fixed regardless. Causing needless confusion with the repl is harmful. |
@ELLIOTTCABLE I have seen no indication of making NODE_MODULE_CONTEXTS the default any time soon. It's too confusing, for too little benefit. |
@ELLIOTTCABLE Yeah, I know. But that's not the proper priority. The repl issues are much more damaging and confusing, especially to new users who are most susceptible to being confused by node, than the vm bugs. Either we change the module loading default now, or we make the repl not use vm.runInNewContext. The simplest fix, which I really can find no harm in, is to just not make the repl run in new contexts. We can always put the context wrapping back in the repl once the vm bugs are fixed, and the module loading default is changed, but really, I don't see that happening any time soon, and it should not delay this fix, which is easy and simple, and will reduce confusion. |
@isaacs: Well, if it is meant to be temporary, and somehow flagged as such, ok. I just see so many temporary things becoming permanent in this world... :-/ |
@isaacs I think you misunderstood my point. I think neither change should happen, as a specific; instead, I think, the change should be making the REPL implementation use That would solve this issue and make things more intuitive. That also addresses @Herby’s and my concern about fresh contexts not being pervasive enough: we can go ahead and use |
@ELLIOTTCABLE I'm not opposed to making it respond to the env flag. Looks like @ry LGTM'd the patch, so it's going in. |
@isaacs: Awesome, thanks! |
Running the repl code in a separate process is a giant pain that only serves to confuse users.
Suggestion:
vm.runInContext
withvm.runInThisContext
repl.context
(or replace with a link toglobal
?).clear
function (does anyone actually use this anyway?)The text was updated successfully, but these errors were encountered: