diff options
author | Guilherme Goncalves <gsg@ggoncalves.me> | 2019-11-12 16:55:42 +0000 |
---|---|---|
committer | Gireesh Punathil <gpunathi@in.ibm.com> | 2019-11-19 17:54:39 +0530 |
commit | 5e4d99ae6e3b32b8c30404f77c33fa9cfc5ca22d (patch) | |
tree | dc57e81a59f44faee82f8c7e08ad4f9a6dd5b7fb /lib/net.js | |
parent | b351d307018809d2e3b92f08a41e7abcdb7f3202 (diff) | |
download | android-node-v8-5e4d99ae6e3b32b8c30404f77c33fa9cfc5ca22d.tar.gz android-node-v8-5e4d99ae6e3b32b8c30404f77c33fa9cfc5ca22d.tar.bz2 android-node-v8-5e4d99ae6e3b32b8c30404f77c33fa9cfc5ca22d.zip |
net: destructure primordials
Refs: https://github.com/nodejs/node/issues/29766
PR-URL: https://github.com/nodejs/node/pull/30447
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Diffstat (limited to 'lib/net.js')
-rw-r--r-- | lib/net.js | 39 |
1 files changed, 22 insertions, 17 deletions
diff --git a/lib/net.js b/lib/net.js index c0d2576afc..bdb77fdacb 100644 --- a/lib/net.js +++ b/lib/net.js @@ -21,7 +21,12 @@ 'use strict'; -const { Object } = primordials; +const { + Object: { + defineProperty: ObjectDefineProperty, + setPrototypeOf: ObjectSetPrototypeOf + } +} = primordials; const EventEmitter = require('events'); const stream = require('stream'); @@ -336,7 +341,7 @@ function Socket(options) { // makeSyncWrite adjusts this value like the original handle would, so // we need to let it do that by turning it into a writable, own // property. - Object.defineProperty(this._handle, 'bytesWritten', { + ObjectDefineProperty(this._handle, 'bytesWritten', { value: 0, writable: true }); } @@ -372,8 +377,8 @@ function Socket(options) { this[kBytesRead] = 0; this[kBytesWritten] = 0; } -Object.setPrototypeOf(Socket.prototype, stream.Duplex.prototype); -Object.setPrototypeOf(Socket, stream.Duplex); +ObjectSetPrototypeOf(Socket.prototype, stream.Duplex.prototype); +ObjectSetPrototypeOf(Socket, stream.Duplex); // Refresh existing timeouts. Socket.prototype._unrefTimer = function _unrefTimer() { @@ -503,13 +508,13 @@ Socket.prototype.address = function() { }; -Object.defineProperty(Socket.prototype, '_connecting', { +ObjectDefineProperty(Socket.prototype, '_connecting', { get: function() { return this.connecting; } }); -Object.defineProperty(Socket.prototype, 'pending', { +ObjectDefineProperty(Socket.prototype, 'pending', { get() { return !this._handle || this.connecting; }, @@ -517,7 +522,7 @@ Object.defineProperty(Socket.prototype, 'pending', { }); -Object.defineProperty(Socket.prototype, 'readyState', { +ObjectDefineProperty(Socket.prototype, 'readyState', { get: function() { if (this.connecting) { return 'opening'; @@ -534,15 +539,15 @@ Object.defineProperty(Socket.prototype, 'readyState', { }); -Object.defineProperty(Socket.prototype, 'bufferSize', { - get: function() { // eslint-disable-line getter-return +ObjectDefineProperty(Socket.prototype, 'bufferSize', { + get: function() { if (this._handle) { return this[kLastWriteQueueSize] + this.writableLength; } } }); -Object.defineProperty(Socket.prototype, kUpdateTimer, { +ObjectDefineProperty(Socket.prototype, kUpdateTimer, { get: function() { return this._unrefTimer; } @@ -690,7 +695,7 @@ Socket.prototype._getpeername = function() { }; function protoGetter(name, callback) { - Object.defineProperty(Socket.prototype, name, { + ObjectDefineProperty(Socket.prototype, name, { configurable: false, enumerable: true, get: callback @@ -1162,7 +1167,7 @@ function Server(options, connectionListener) { this._connections = 0; - Object.defineProperty(this, 'connections', { + ObjectDefineProperty(this, 'connections', { get: deprecate(() => { if (this._usingWorkers) { @@ -1186,8 +1191,8 @@ function Server(options, connectionListener) { this.allowHalfOpen = options.allowHalfOpen || false; this.pauseOnConnect = !!options.pauseOnConnect; } -Object.setPrototypeOf(Server.prototype, EventEmitter.prototype); -Object.setPrototypeOf(Server, EventEmitter); +ObjectSetPrototypeOf(Server.prototype, EventEmitter.prototype); +ObjectSetPrototypeOf(Server, EventEmitter); function toNumber(x) { return (x = Number(x)) >= 0 ? x : false; } @@ -1491,7 +1496,7 @@ function lookupAndListen(self, port, address, backlog, exclusive, flags) { }); } -Object.defineProperty(Server.prototype, 'listening', { +ObjectDefineProperty(Server.prototype, 'listening', { get: function() { return !!this._handle; }, @@ -1648,12 +1653,12 @@ function emitCloseNT(self) { // Legacy alias on the C++ wrapper object. This is not public API, so we may // want to runtime-deprecate it at some point. There's no hurry, though. -Object.defineProperty(TCP.prototype, 'owner', { +ObjectDefineProperty(TCP.prototype, 'owner', { get() { return this[owner_symbol]; }, set(v) { return this[owner_symbol] = v; } }); -Object.defineProperty(Socket.prototype, '_handle', { +ObjectDefineProperty(Socket.prototype, '_handle', { get() { return this[kHandle]; }, set(v) { return this[kHandle] = v; } }); |