From 7a29f440714e443a24bfe312ef9c799e0b821b0a Mon Sep 17 00:00:00 2001 From: Lance Ball Date: Mon, 16 Oct 2017 17:24:17 -0400 Subject: [PATCH] repl: deprecate REPLServer.prototype.memory 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: https://github.com/nodejs/node/pull/16242 Reviewed-By: Ruben Bridgewater Reviewed-By: Luigi Pinca Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Jeremiah Senkpiel --- doc/api/deprecations.md | 9 +++++++++ lib/repl.js | 14 +++++++++----- test/parallel/test-repl-memory-deprecation.js | 15 +++++++++++++++ 3 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 test/parallel/test-repl-memory-deprecation.js diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index 2a21d645b6e46c..75c5c0feb57958 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -728,6 +728,15 @@ Type: Runtime deprecated. Please use `fs.ftruncate()` or `fs.ftruncateSync()` to work with file descriptors. + +### 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 diff --git a/lib/repl.js b/lib/repl.js index c98ff7063b0bc1..d4b95bf3a67f45 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -460,7 +460,7 @@ function REPLServer(prompt, self.line = prefix; self.cursor = prefix.length; } - self.memory(cmd); + _memory.call(self, cmd); return; } @@ -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 ' + @@ -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 || []; @@ -1185,7 +1189,7 @@ REPLServer.prototype.memory = function memory(cmd) { } else { self.lines.level = []; } -}; +} function addStandardGlobals(completionGroups, filter) { // Global object properties diff --git a/test/parallel/test-repl-memory-deprecation.js b/test/parallel/test-repl-memory-deprecation.js new file mode 100644 index 00000000000000..9993360a2861cf --- /dev/null +++ b/test/parallel/test-repl-memory-deprecation.js @@ -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(); +}