net: replace __defineGetter__ with defineProperty
`Object.prototype.__defineGetter__` is deprecated now, use `Object.defineProperty` instead. PR-URL: https://github.com/nodejs/node/pull/6284 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This commit is contained in:
parent
6198472d83
commit
8636af1012
22
lib/net.js
22
lib/net.js
@ -585,19 +585,27 @@ Socket.prototype._getpeername = function() {
|
||||
return this._peername;
|
||||
};
|
||||
|
||||
Socket.prototype.__defineGetter__('bytesRead', function() {
|
||||
function protoGetter(name, callback) {
|
||||
Object.defineProperty(Socket.prototype, name, {
|
||||
configurable: false,
|
||||
enumerable: true,
|
||||
get: callback
|
||||
});
|
||||
}
|
||||
|
||||
protoGetter('bytesRead', function bytesRead() {
|
||||
return this._handle ? this._handle.bytesRead : this[BYTES_READ];
|
||||
});
|
||||
|
||||
Socket.prototype.__defineGetter__('remoteAddress', function() {
|
||||
protoGetter('remoteAddress', function remoteAddress() {
|
||||
return this._getpeername().address;
|
||||
});
|
||||
|
||||
Socket.prototype.__defineGetter__('remoteFamily', function() {
|
||||
protoGetter('remoteFamily', function remoteFamily() {
|
||||
return this._getpeername().family;
|
||||
});
|
||||
|
||||
Socket.prototype.__defineGetter__('remotePort', function() {
|
||||
protoGetter('remotePort', function remotePort() {
|
||||
return this._getpeername().port;
|
||||
});
|
||||
|
||||
@ -616,12 +624,12 @@ Socket.prototype._getsockname = function() {
|
||||
};
|
||||
|
||||
|
||||
Socket.prototype.__defineGetter__('localAddress', function() {
|
||||
protoGetter('localAddress', function localAddress() {
|
||||
return this._getsockname().address;
|
||||
});
|
||||
|
||||
|
||||
Socket.prototype.__defineGetter__('localPort', function() {
|
||||
protoGetter('localPort', function localPort() {
|
||||
return this._getsockname().port;
|
||||
});
|
||||
|
||||
@ -735,7 +743,7 @@ function createWriteReq(req, handle, data, encoding) {
|
||||
}
|
||||
|
||||
|
||||
Socket.prototype.__defineGetter__('bytesWritten', function() {
|
||||
protoGetter('bytesWritten', function bytesWritten() {
|
||||
var bytes = this._bytesDispatched;
|
||||
const state = this._writableState;
|
||||
const data = this._pendingData;
|
||||
|
Loading…
x
Reference in New Issue
Block a user