Skip to content
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

repl: properly handle repl.repl #30981

Closed
wants to merge 2 commits into from

Conversation

BridgeAR
Copy link
Member

The repl property is set so that it's possible to inspect the
instances own properties during runtime. This was never tested and
it was also only exported in case the instance was started with
.start() instead of using the constructor directly. In case that
more than a single instance was created, all instances got access
to the first instance.

From now on the repl property is only exported in case the repl is
starte as standalone program.

Refs: #30928 (comment)

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

@BridgeAR BridgeAR added the semver-major PRs that contain breaking changes and should be released in the next major version. label Dec 15, 2019
@BridgeAR BridgeAR requested a review from addaleax December 15, 2019 17:20
@nodejs-github-bot nodejs-github-bot added the repl Issues and PRs related to the REPL subsystem. label Dec 15, 2019
@addaleax
Copy link
Member

From now on the repl property is only exported in case the repl is
starte as standalone program.

Why is this not useful for other REPLs?

@BridgeAR
Copy link
Member Author

@addaleax I tried to think of ways to expose the correct instance in case multiple instances are used but I could not come up with a proper solution.
If you can think of a good implementation, please let me know!
The only other easy implementation would be to expose this property only as long as a single REPL instance is started and as soon as a second one is started, that it's removed completely. That would be surprising behavior though in case someone from the first one did access the property before and can't afterwards (unlikely but possible).

@Trott
Copy link
Member

Trott commented Dec 17, 2019

The doc checkbox is checked, but there are no doc changes. Seems like this would warrant a documentation change?

@BridgeAR
Copy link
Member Author

@Trott I am hesitant to document this feature. It should only be useful for people who actually work on the REPL itself (as in change the REPLs code). I added a code comment to indicate that.

@BridgeAR BridgeAR added the review wanted PRs that need reviews. label Dec 19, 2019
@BridgeAR
Copy link
Member Author

@nodejs/tsc this could use another review :)

Copy link
Member

@Trott Trott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM if CITGM and CI are green. (CITGM seems unlikely to uncover something here, but I'd prefer to be especially cautious anyway.)

@Trott
Copy link
Member

Trott commented Dec 30, 2019

@addaleax Is Ruben's explanation above persuasive for you? Or would you prefer we not make this change?

@addaleax
Copy link
Member

@Trott I mean, not really, but it doesn’t make a huge difference anyway, I think? It’s not like many people use the REPL module programmatically. But for those, this seems like this change is making things a tiny bit more difficult without a real need to do so.

@BridgeAR
Copy link
Member Author

@addaleax

this seems like this change is making things a tiny bit more difficult without a real need to do so.

I strongly disagree on that. The current behavior seems very wrong. It is possible to change from one REPL instance the internal state of another REPL instance. That should never be possible.
This property should only be useful for users who actually work on the REPL code and who ever does that is still able to access the property in case we are able to verify that the accessing REPL instance is indeed the correct one.

@BridgeAR
Copy link
Member Author

BridgeAR commented Jan 2, 2020

@addaleax please use the request changes in case you are against landing this as is. I will wait a couple more days and land it afterwards otherwise.

@nodejs-github-bot
Copy link
Collaborator

nodejs-github-bot commented Jan 2, 2020

The repl property is set so that it's possible to inspect the
instances own properties during runtime. This was never tested and
it was also only exported in case the instance was started with
`.start()` instead of using the constructor directly. In case that
more than a single instance was created, all instances got access
to the first instance.

From now on the repl property is only exported in case the repl is
starte as standalone program.
@BridgeAR BridgeAR force-pushed the standalone-repl-property branch from 569c2aa to b87844c Compare January 2, 2020 17:15
@BridgeAR
Copy link
Member Author

BridgeAR commented Jan 2, 2020

As a note: this does actually improve the experience for me as someone who works on the REPL by exposing the correct instance during testing. That did not work properly before.

@nodejs-github-bot
Copy link
Collaborator

@addaleax
Copy link
Member

addaleax commented Jan 2, 2020

@BridgeAR As you can see, I’m not blocking this.

It is possible to change from one REPL instance the internal state of another REPL instance. That should never be possible.

That just doesn’t seem to be true.

@BridgeAR
Copy link
Member Author

BridgeAR commented Jan 2, 2020

@addaleax

That just doesn’t seem to be true.

Please elaborate. The following is for example possible:

  1. Create two dummy files replIn and replOut.
  2. Start:
const fs = require('fs');
const repl = require('repl');

// First REPL instance
repl.start({
  input: fs.ReadStream('./replIn'),
  output: fs.WriteStream('./replOut')
});

// This should not access the state of `firstRepl`, but it does!
repl.start();
  1. Then execute e.g.,: repl.repl.output.write('foobar')

There's no output in the current (second) instance. Instead, it's written directly to the first REPL instances output stream (replOut).

@BridgeAR BridgeAR added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Jan 2, 2020
@addaleax
Copy link
Member

addaleax commented Jan 2, 2020

@BridgeAR I don’t consider repl.repl to be internal state of any REPL instance. It’s simply (until now) an utility that helps access the first-started REPL instance. I don’t see how setting it in fewer cases than we do now, which is what this PR does, improves something.

However, this is really not worth arguing about imo – I’m unsubscribing from this thread, and you can feel free to go ahead with what you think is right.

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

BridgeAR added a commit that referenced this pull request Jan 3, 2020
The repl property is set so that it's possible to inspect the
instances own properties during runtime. This was never tested and
it was also only exported in case the instance was started with
`.start()` instead of using the constructor directly. In case that
more than a single instance was created, all instances got access
to the first instance.

From now on the repl property is only exported in case the repl is
starte as standalone program.

PR-URL: #30981
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
@BridgeAR
Copy link
Member Author

BridgeAR commented Jan 3, 2020

Landed in 84c426c 🎉

@BridgeAR BridgeAR closed this Jan 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. repl Issues and PRs related to the REPL subsystem. review wanted PRs that need reviews. semver-major PRs that contain breaking changes and should be released in the next major version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants