Skip to content

Commit

Permalink
repl: deprecate REPLServer.prototype.memory
Browse files Browse the repository at this point in the history
This method is only useful for the internal mechanics of the REPLServer
and does not need to be exposed in user space. It was previously not
documented, so I believe a Runtime deprecation makes sense.

PR-URL: #16242
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Jeremiah Senkpiel <fishrock123@rocketmail.com>
  • Loading branch information
lance committed Oct 19, 2017
1 parent 76abf0f commit 7a29f44
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
9 changes: 9 additions & 0 deletions doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,15 @@ Type: Runtime
deprecated. Please use `fs.ftruncate()` or `fs.ftruncateSync()` to work with
file descriptors.
<a id="DEP0082"></a>
### DEP0082: REPLServer.prototype.memory()
Type: Runtime
`REPLServer.prototype.memory()` is a function only necessary for the
internal mechanics of the `REPLServer` itself, and is therefore not
necessary in user space.
[`Buffer.allocUnsafeSlow(size)`]: buffer.html#buffer_class_method_buffer_allocunsafeslow_size
[`Buffer.from(array)`]: buffer.html#buffer_class_method_buffer_from_array
Expand Down
14 changes: 9 additions & 5 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ function REPLServer(prompt,
self.line = prefix;
self.cursor = prefix.length;
}
self.memory(cmd);
_memory.call(self, cmd);
return;
}

Expand Down Expand Up @@ -493,7 +493,7 @@ function REPLServer(prompt,

function finish(e, ret) {
debug('finish', e, ret);
self.memory(cmd);
_memory.call(self, cmd);

if (e && !self[kBufferedCommandSymbol] && cmd.trim().startsWith('npm ')) {
self.outputStream.write('npm should be run outside of the ' +
Expand Down Expand Up @@ -1113,9 +1113,13 @@ REPLServer.prototype.defineCommand = function(keyword, cmd) {
this.commands[keyword] = cmd;
};

REPLServer.prototype.memory = function memory(cmd) {
var self = this;
REPLServer.prototype.memory = util.deprecate(
_memory,
'REPLServer.memory() is deprecated',
'DEP0082');

function _memory(cmd) {
const self = this;
self.lines = self.lines || [];
self.lines.level = self.lines.level || [];

Expand Down Expand Up @@ -1185,7 +1189,7 @@ REPLServer.prototype.memory = function memory(cmd) {
} else {
self.lines.level = [];
}
};
}

function addStandardGlobals(completionGroups, filter) {
// Global object properties
Expand Down
15 changes: 15 additions & 0 deletions test/parallel/test-repl-memory-deprecation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const repl = require('repl');

testMemory();

function testMemory() {
const server = repl.start({ prompt: '> ' });
const warn = 'REPLServer.memory() is deprecated';

common.expectWarning('DeprecationWarning', warn);
assert.strictEqual(server.memory(), undefined);
server.close();
}

0 comments on commit 7a29f44

Please sign in to comment.