Skip to content

Commit 74582aa

Browse files
jasnellevanlucas
authored andcommitted
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: #6768 Reviewed-By: Rich Trott <[email protected]>
1 parent 897934a commit 74582aa

File tree

4 files changed

+65
-29
lines changed

4 files changed

+65
-29
lines changed

lib/_tls_legacy.js

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,12 @@ CryptoStream.prototype.setKeepAlive = function(enable, initialDelay) {
350350
if (this.socket) this.socket.setKeepAlive(enable, initialDelay);
351351
};
352352

353-
CryptoStream.prototype.__defineGetter__('bytesWritten', function() {
354-
return this.socket ? this.socket.bytesWritten : 0;
353+
Object.defineProperty(CryptoStream.prototype, 'bytesWritten', {
354+
configurable: true,
355+
enumerable: true,
356+
get: function() {
357+
return this.socket ? this.socket.bytesWritten : 0;
358+
}
355359
});
356360

357361
CryptoStream.prototype.getPeerCertificate = function(detailed) {
@@ -526,27 +530,44 @@ CleartextStream.prototype.address = function() {
526530
return this.socket && this.socket.address();
527531
};
528532

529-
530-
CleartextStream.prototype.__defineGetter__('remoteAddress', function() {
531-
return this.socket && this.socket.remoteAddress;
533+
Object.defineProperty(CleartextStream.prototype, 'remoteAddress', {
534+
configurable: true,
535+
enumerable: true,
536+
get: function() {
537+
return this.socket && this.socket.remoteAddress;
538+
}
532539
});
533540

534-
CleartextStream.prototype.__defineGetter__('remoteFamily', function() {
535-
return this.socket && this.socket.remoteFamily;
541+
Object.defineProperty(CleartextStream.prototype, 'remoteFamily', {
542+
configurable: true,
543+
enumerable: true,
544+
get: function() {
545+
return this.socket && this.socket.remoteFamily;
546+
}
536547
});
537548

538-
CleartextStream.prototype.__defineGetter__('remotePort', function() {
539-
return this.socket && this.socket.remotePort;
549+
Object.defineProperty(CleartextStream.prototype, 'remotePort', {
550+
configurable: true,
551+
enumerable: true,
552+
get: function() {
553+
return this.socket && this.socket.remotePort;
554+
}
540555
});
541556

542-
543-
CleartextStream.prototype.__defineGetter__('localAddress', function() {
544-
return this.socket && this.socket.localAddress;
557+
Object.defineProperty(CleartextStream.prototype, 'localAddress', {
558+
configurable: true,
559+
enumerable: true,
560+
get: function() {
561+
return this.socket && this.socket.localAddress;
562+
}
545563
});
546564

547-
548-
CleartextStream.prototype.__defineGetter__('localPort', function() {
549-
return this.socket && this.socket.localPort;
565+
Object.defineProperty(CleartextStream.prototype, 'localPort', {
566+
configurable: true,
567+
enumerable: true,
568+
get: function() {
569+
return this.socket && this.socket.localPort;
570+
}
550571
});
551572

552573

lib/crypto.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -662,13 +662,20 @@ function filterDuplicates(names) {
662662
}
663663

664664
// Legacy API
665-
exports.__defineGetter__('createCredentials',
666-
internalUtil.deprecate(function() {
665+
Object.defineProperty(exports, 'createCredentials', {
666+
configurable: true,
667+
enumerable: true,
668+
get: internalUtil.deprecate(function() {
667669
return require('tls').createSecureContext;
668670
}, 'crypto.createCredentials is deprecated. ' +
669-
'Use tls.createSecureContext instead.'));
671+
'Use tls.createSecureContext instead.')
672+
});
670673

671-
exports.__defineGetter__('Credentials', internalUtil.deprecate(function() {
672-
return require('tls').SecureContext;
673-
}, 'crypto.Credentials is deprecated. ' +
674-
'Use tls.SecureContext instead.'));
674+
Object.defineProperty(exports, 'Credentials', {
675+
configurable: true,
676+
enumerable: true,
677+
get: internalUtil.deprecate(function() {
678+
return require('tls').SecureContext;
679+
}, 'crypto.Credentials is deprecated. ' +
680+
'Use tls.SecureContext instead.')
681+
});

lib/internal/bootstrap_node.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,12 @@
251251
}
252252

253253
function setupGlobalConsole() {
254-
global.__defineGetter__('console', function() {
255-
return NativeModule.require('console');
254+
Object.defineProperty(global, 'console', {
255+
configurable: true,
256+
enumerable: true,
257+
get: function() {
258+
return NativeModule.require('console');
259+
}
256260
});
257261
}
258262

lib/readline.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,15 @@ function Interface(input, output, completer, terminal) {
165165

166166
inherits(Interface, EventEmitter);
167167

168-
Interface.prototype.__defineGetter__('columns', function() {
169-
var columns = Infinity;
170-
if (this.output && this.output.columns)
171-
columns = this.output.columns;
172-
return columns;
168+
Object.defineProperty(Interface.prototype, 'columns', {
169+
configurable: true,
170+
enumerable: true,
171+
get: function() {
172+
var columns = Infinity;
173+
if (this.output && this.output.columns)
174+
columns = this.output.columns;
175+
return columns;
176+
}
173177
});
174178

175179
Interface.prototype.setPrompt = function(prompt) {

0 commit comments

Comments
 (0)