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: make REPLServer.bufferedCommand private #13687

Closed
wants to merge 4 commits into from
Closed

repl: make REPLServer.bufferedCommand private #13687

wants to merge 4 commits into from

Conversation

lance
Copy link
Member

@lance lance commented Jun 14, 2017

The REPLServer.bufferedCommand property was undocumented, except
for its usage appearing, unexplained, in an example for
REPLServer.defineCommand. This commit deprecates that property,
privatizes it, and adds a REPLServer.clearBufferedCommand()
function that will clear the buffer.

Refs: #12686

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
Affected core subsystem(s)

repl, doc

@lance lance added doc Issues and PRs related to the documentations. repl Issues and PRs related to the REPL subsystem. labels Jun 14, 2017
@refack refack added the semver-major PRs that contain breaking changes and should be released in the next major version. label Jun 14, 2017
lib/repl.js Outdated
self.lines.level = [];

self.clearBufferedCommand = function clearBufferedCommand() {
Copy link
Contributor

Choose a reason for hiding this comment

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

IMHO it would be better to add clearBufferedCommand to REPLServer.prototype.

About Object.defineProperty(this, 'bufferedCommand' I'm not sure since that will change the .hasOwnProperty('bufferedCommand')

Copy link
Contributor

Choose a reason for hiding this comment

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

Does this function need to be exposed at all? Would it work to create a function in this file that has the symbol in scope and takes the REPL as an argument?

lib/repl.js Outdated
@@ -72,6 +72,7 @@ for (var n = 0; n < GLOBAL_OBJECT_PROPERTIES.length; n++) {
GLOBAL_OBJECT_PROPERTY_MAP[GLOBAL_OBJECT_PROPERTIES[n]] =
GLOBAL_OBJECT_PROPERTIES[n];
}
const BUFFERED_COMMAND = Symbol('bufferedCommand');
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: in general kBufferedCommandSymbol is prefered to ALL_CAPS.

doc/api/repl.md Outdated
@@ -375,6 +375,16 @@ The `replServer.displayPrompt` method is primarily intended to be called from
within the action function for commands registered using the
`replServer.defineCommand()` method.

### replServer.clearBufferedCommand()
<!-- YAML
added: v8.1.0
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this probably be REPLACEME till landing? Anyway, even 8.1.1 has not this fix.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. I wasn't sure what to put here (and didn't realize 8.1.1 was released yesterday).

Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure about rules here. Maybe it is usually replaced on backporting from master to current?

@refack
Copy link
Contributor

refack commented Jun 14, 2017

Added some comments.
As for the PR in general I'm +1, but we'll need a wide consensus.

Copy link
Contributor

@cjihrig cjihrig left a comment

Choose a reason for hiding this comment

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

Do you foresee this being something that is needed at all outside of core? Also, I'm not sure that we can just remove bufferedCommand with no notice.

doc/api/repl.md Outdated
-->

The `replServer.clearBufferedComand()` method clears any command that has been
buffered but not yet executed.This method is primarily intended to be
Copy link
Contributor

Choose a reason for hiding this comment

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

Space after the period please.

lib/repl.js Outdated
self.lines.level = [];

self.clearBufferedCommand = function clearBufferedCommand() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this function need to be exposed at all? Would it work to create a function in this file that has the symbol in scope and takes the REPL as an argument?

@lance
Copy link
Member Author

lance commented Jun 14, 2017

@cjihrig I really only see the bufferedCommand being useful outside of core in cases where users have used REPLServer.defineCommand and want to clear what may exist within the buffer. This is the doc example in which it was exposed, and it seems more break-y to remove it completely vs. a deprecation.

Copy link
Contributor

@cjihrig cjihrig 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 this isn't being used.

@lance
Copy link
Member Author

lance commented Jun 15, 2017

Love to get another LGTM on this - @jasnell @addaleax?

lib/repl.js Outdated
'REPLServer.bufferedCommand is deprecated'),
set: util.deprecate((val) => self[kBufferedCommandSymbol] = val,
'REPLServer.bufferedCommand is deprecated')
});
Copy link
Member

Choose a reason for hiding this comment

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

add enumerable: true here.

lib/repl.js Outdated
get: util.deprecate(() => self[kBufferedCommandSymbol],
'REPLServer.bufferedCommand is deprecated'),
set: util.deprecate((val) => self[kBufferedCommandSymbol] = val,
'REPLServer.bufferedCommand is deprecated')
Copy link
Member

Choose a reason for hiding this comment

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

This would need an assigned deprecation code. See doc/api/deprecations.md.
Before this lands, make the code DEP00XX and whom ever does the landing would assign the actual code.
The code would be passed in as the third argument for the util.deprecate() method.

Copy link
Member

@jasnell jasnell left a comment

Choose a reason for hiding this comment

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

Needs a bit more work. Left a couple comments.

@lance
Copy link
Member Author

lance commented Jun 15, 2017

@jasnell thanks - I've added a temporary deprecation code to util.deprecate but it wasn't clear from your comment if I should also add this to deprecations.md or if that happens when the PR lands.

@jasnell
Copy link
Member

jasnell commented Jun 16, 2017

Yes, an entry should be added to deprecations.md using the temporary code.

@lance
Copy link
Member Author

lance commented Jun 19, 2017

CI: https://ci.nodejs.org/job/node-test-pull-request/8741/

@jasnell documentation bits added.
@Fishrock123 any opinion on this?

@lance
Copy link
Member Author

lance commented Jun 19, 2017

Hmnm feebsd test failed with

not ok 535 parallel/test-http-agent-keepalive
  ---
  duration_ms: 0.753
  severity: crashed
  stack: |-
    oh no!
    exit code: CRASHED (Signal: 11)

which seems unrelated.

@lance
Copy link
Member Author

lance commented Jun 21, 2017

'nother CI https://ci.nodejs.org/job/node-test-commit/10701/

@jasnell look ok to you?

@jasnell jasnell dismissed their stale review June 22, 2017 04:02

Issues addressed

@jasnell
Copy link
Member

jasnell commented Jun 22, 2017

I've cleared my review. I'd like to get more input from @nodejs/ctc about whether this is something we definitely want to do.

@jasnell
Copy link
Member

jasnell commented Jun 22, 2017

ping @ChALkeR ... any way to get a usage analysis

@lance
Copy link
Member Author

lance commented Jun 27, 2017

Awaiting CTC review @nodejs/ctc

@lance
Copy link
Member Author

lance commented Jul 27, 2017

@Trott any movement on this from @nodjs/ctc?

@Trott
Copy link
Member

Trott commented Jul 27, 2017

@lance Can you rebase to get rid of conflicts? (I'm guessing it's all white-space stuff based on new stricter indentation linting. Be sure to run make jslint before pushing to GitHub to resolve the conflicts.)

@Trott
Copy link
Member

Trott commented Jul 27, 2017

Needs one more CTC approval. Pinging some CTC folks who have several commits modifying lib/repl.js: @indutny @bnoordhuis @mscdex @addaleax @thefourtheye @evanlucas

@evanlucas
Copy link
Contributor

https://github.com/search?l=JavaScript&p=2&q=bufferedCommand&type=Code&utf8=%E2%9C%93 has some real world use cases for this currently. Are we sure that we can justify this breaking change? I'm on the fence

Relates to #12686

The `REPLServer.bufferedCommand` property was undocumented, except
for its usage appearing, unexplained, in an example for
`REPLServer.defineCommand`. This commit deprecates that property,
privatizes it, and adds a `REPLServer.clearBufferedCommand()`
function that will clear the buffer.
Change to kBufferedCommandSymbol instead of BUFFERED_COMMAND. Made
`clearBufferedCommand` exist on `REPLServer.prototype`. Minor typo
corrections.
and make REPLServer.bufferedCommand enumerable
@lance
Copy link
Member Author

lance commented Jul 28, 2017

@evanlucas there are a lot of results returned from that query, but the vast majority of them are for jquery-buffer.js which is unrelated. I skimmed through the first 10 pages of results, and other than jquery-buffer.js, most of the references fall into two categories.

  • Setting replServer.bufferedCommand to ''.
  • Clones or other copies of the Node.js codebase - not forks, copies.

The first case is covered by the addition of REPLServer.clearBufferedCommand(), and the second will not be affected by this change.

I tried to figure out a way to eliminate jquery-buffer.js from search results, but my GitHub search foo is not quite there.

Copy link
Member

@mhdawson mhdawson left a comment

Choose a reason for hiding this comment

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

Given the usage data and that its only deprecation at this point it seems reasonable to me.

@lance
Copy link
Member Author

lance commented Aug 1, 2017

Landed in f037cbf

@lance lance closed this Aug 1, 2017
@lance lance deleted the 12686-hide-buffered-command-repl branch August 1, 2017 19:46
@addaleax
Copy link
Member

addaleax commented Aug 1, 2017

@lance I un-landed this PR because the DEP00XX should have been replaced while landing… if you want to re-land with that, please do so, otherwise I can. :)

@addaleax
Copy link
Member

addaleax commented Aug 1, 2017

Re-landed in 2ca9f94

I realized I made the same mistake a couple of days ago, maybe that was a bit confusing … sorry!

addaleax pushed a commit that referenced this pull request Aug 1, 2017
The `REPLServer.bufferedCommand` property was undocumented, except
for its usage appearing, unexplained, in an example for
`REPLServer.defineCommand`. This commit deprecates that property,
privatizes it, and adds a `REPLServer.clearBufferedCommand()`
function that will clear the buffer.

PR-URL: #13687
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: James Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <mhdawson@ibm.com>
Reviewed-By: Ruben Bridgewater <ruben.bridgewater@fintura.de>

Refs: #12686
@lance
Copy link
Member Author

lance commented Aug 2, 2017

@addaleax I realized my mistake after I walked away from my computer today. Thanks for fixing it up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Issues and PRs related to the documentations. repl Issues and PRs related to the REPL subsystem. 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.