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

REPLServer.createContext() has unexpected side effects #14226

Closed
lance opened this issue Jul 13, 2017 · 0 comments
Closed

REPLServer.createContext() has unexpected side effects #14226

lance opened this issue Jul 13, 2017 · 0 comments
Labels
repl Issues and PRs related to the REPL subsystem.

Comments

@lance
Copy link
Member

lance commented Jul 13, 2017

  • Version: 8.1.4
  • Platform: Darwin Callisto 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

Calling the undocumented REPLServer.createContext() has unexpected side effects. When the method is called, the value for the server instance's underscoreAssigned and lines properties reset. Here is a reproducible test case.

const repl = require('repl');
const util = require('util');
const assert = require('assert');

const server = repl.start({ prompt: '> ' });
assert.ok(!server.underscoreAssigned);
assert.strictEqual(server.lines.length, 0);

server.write('_ = 500;\n');
assert.ok(server.underscoreAssigned);
assert.strictEqual(server.lines.length, 1);

const context = server.createContext();

assert.ok(server.underscoreAssigned);
assert.strictEqual(server.lines.length, 1);

The overwriting of underscoreAssigned was introduced in ad8257f, while the overwriting of lines is 6 years old at least.

I discovered this when looking for usages of createContext() in the interest of deprecating it and REPLServer.resetContext() for #7619.

@lance lance added the repl Issues and PRs related to the REPL subsystem. label Jul 13, 2017
@lance lance closed this as completed in ed1ba45 Aug 30, 2017
cjihrig pushed a commit to cjihrig/node that referenced this issue Aug 31, 2017
The internal method `REPLServer.createContext()` had
unexpected side effects. When called, the value for the
`underscoreAssigned` and `lines` properties were reset.

This change ensures that those properties are not modified
when a context is created.

Fixes: nodejs#14226
Refs: nodejs#7619

PR-URL: nodejs#14331
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
addaleax pushed a commit to addaleax/ayo that referenced this issue Sep 5, 2017
The internal method `REPLServer.createContext()` had
unexpected side effects. When called, the value for the
`underscoreAssigned` and `lines` properties were reset.

This change ensures that those properties are not modified
when a context is created.

Fixes: nodejs/node#14226
Refs: nodejs/node#7619

PR-URL: nodejs/node#14331
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
repl Issues and PRs related to the REPL subsystem.
Projects
None yet
Development

No branches or pull requests

1 participant