From f293d0b0c85b2d1b9e0d3938dd38cf1cacac6970 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Sat, 14 May 2016 22:29:19 -0700 Subject: [PATCH] lib: replace legacy uses of __defineGetter__ Minor clean up. There are still some places in core that use the legacy __defineGetter__ syntax. This updates most of those. PR-URL: https://github.com/nodejs/node/pull/6768 Reviewed-By: Rich Trott --- lib/_tls_legacy.js | 51 ++++++++++++++++++++++++---------- lib/crypto.js | 21 +++++++++----- lib/internal/bootstrap_node.js | 8 ++++-- lib/readline.js | 14 ++++++---- 4 files changed, 65 insertions(+), 29 deletions(-) diff --git a/lib/_tls_legacy.js b/lib/_tls_legacy.js index 3043c031121f37..b064b245d65a1b 100644 --- a/lib/_tls_legacy.js +++ b/lib/_tls_legacy.js @@ -350,8 +350,12 @@ CryptoStream.prototype.setKeepAlive = function(enable, initialDelay) { if (this.socket) this.socket.setKeepAlive(enable, initialDelay); }; -CryptoStream.prototype.__defineGetter__('bytesWritten', function() { - return this.socket ? this.socket.bytesWritten : 0; +Object.defineProperty(CryptoStream.prototype, 'bytesWritten', { + configurable: true, + enumerable: true, + get: function() { + return this.socket ? this.socket.bytesWritten : 0; + } }); CryptoStream.prototype.getPeerCertificate = function(detailed) { @@ -526,27 +530,44 @@ CleartextStream.prototype.address = function() { return this.socket && this.socket.address(); }; - -CleartextStream.prototype.__defineGetter__('remoteAddress', function() { - return this.socket && this.socket.remoteAddress; +Object.defineProperty(CleartextStream.prototype, 'remoteAddress', { + configurable: true, + enumerable: true, + get: function() { + return this.socket && this.socket.remoteAddress; + } }); -CleartextStream.prototype.__defineGetter__('remoteFamily', function() { - return this.socket && this.socket.remoteFamily; +Object.defineProperty(CleartextStream.prototype, 'remoteFamily', { + configurable: true, + enumerable: true, + get: function() { + return this.socket && this.socket.remoteFamily; + } }); -CleartextStream.prototype.__defineGetter__('remotePort', function() { - return this.socket && this.socket.remotePort; +Object.defineProperty(CleartextStream.prototype, 'remotePort', { + configurable: true, + enumerable: true, + get: function() { + return this.socket && this.socket.remotePort; + } }); - -CleartextStream.prototype.__defineGetter__('localAddress', function() { - return this.socket && this.socket.localAddress; +Object.defineProperty(CleartextStream.prototype, 'localAddress', { + configurable: true, + enumerable: true, + get: function() { + return this.socket && this.socket.localAddress; + } }); - -CleartextStream.prototype.__defineGetter__('localPort', function() { - return this.socket && this.socket.localPort; +Object.defineProperty(CleartextStream.prototype, 'localPort', { + configurable: true, + enumerable: true, + get: function() { + return this.socket && this.socket.localPort; + } }); diff --git a/lib/crypto.js b/lib/crypto.js index 688ac34e4ad767..0f5652c9c946ef 100644 --- a/lib/crypto.js +++ b/lib/crypto.js @@ -662,13 +662,20 @@ function filterDuplicates(names) { } // Legacy API -exports.__defineGetter__('createCredentials', - internalUtil.deprecate(function() { +Object.defineProperty(exports, 'createCredentials', { + configurable: true, + enumerable: true, + get: internalUtil.deprecate(function() { return require('tls').createSecureContext; }, 'crypto.createCredentials is deprecated. ' + - 'Use tls.createSecureContext instead.')); + 'Use tls.createSecureContext instead.') +}); -exports.__defineGetter__('Credentials', internalUtil.deprecate(function() { - return require('tls').SecureContext; -}, 'crypto.Credentials is deprecated. ' + - 'Use tls.SecureContext instead.')); +Object.defineProperty(exports, 'Credentials', { + configurable: true, + enumerable: true, + get: internalUtil.deprecate(function() { + return require('tls').SecureContext; + }, 'crypto.Credentials is deprecated. ' + + 'Use tls.SecureContext instead.') +}); diff --git a/lib/internal/bootstrap_node.js b/lib/internal/bootstrap_node.js index 7143ff2720d4cb..d0077df63c5980 100644 --- a/lib/internal/bootstrap_node.js +++ b/lib/internal/bootstrap_node.js @@ -251,8 +251,12 @@ } function setupGlobalConsole() { - global.__defineGetter__('console', function() { - return NativeModule.require('console'); + Object.defineProperty(global, 'console', { + configurable: true, + enumerable: true, + get: function() { + return NativeModule.require('console'); + } }); } diff --git a/lib/readline.js b/lib/readline.js index 096929f8858230..ee2fe1de86ed63 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -165,11 +165,15 @@ function Interface(input, output, completer, terminal) { inherits(Interface, EventEmitter); -Interface.prototype.__defineGetter__('columns', function() { - var columns = Infinity; - if (this.output && this.output.columns) - columns = this.output.columns; - return columns; +Object.defineProperty(Interface.prototype, 'columns', { + configurable: true, + enumerable: true, + get: function() { + var columns = Infinity; + if (this.output && this.output.columns) + columns = this.output.columns; + return columns; + } }); Interface.prototype.setPrompt = function(prompt) {