summaryrefslogtreecommitdiff
path: root/lib/net.js
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2018-07-27 14:35:39 +0200
committerAnna Henningsen <anna@addaleax.net>2018-08-05 13:46:13 +0200
commitaf7164ebccd21d9fc5b0782e0427257f7637a4db (patch)
tree589f506811cb65293b88fcd8984ae7ac0e5a80be /lib/net.js
parenta196aa2e24ef7069289fa4a9aa8c6862d82e6b5f (diff)
downloadandroid-node-v8-af7164ebccd21d9fc5b0782e0427257f7637a4db.tar.gz
android-node-v8-af7164ebccd21d9fc5b0782e0427257f7637a4db.tar.bz2
android-node-v8-af7164ebccd21d9fc5b0782e0427257f7637a4db.zip
lib,src: standardize `owner_symbol` for handles
Instead of somtimes using an `owner` string to link from a native handle object to the corresponding JS object, standardize on a single symbol that fulfills this role. PR-URL: https://github.com/nodejs/node/pull/22002 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Jon Moss <me@jonathanmoss.me> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Minwoo Jung <minwoo@nodesource.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
Diffstat (limited to 'lib/net.js')
-rw-r--r--lib/net.js24
1 files changed, 16 insertions, 8 deletions
diff --git a/lib/net.js b/lib/net.js
index 889f28b0aa..8c05f2c07b 100644
--- a/lib/net.js
+++ b/lib/net.js
@@ -56,7 +56,7 @@ const {
const {
newAsyncId,
defaultTriggerAsyncIdScope,
- symbols: { async_id_symbol }
+ symbols: { async_id_symbol, owner_symbol }
} = require('internal/async_hooks');
const {
createWriteWrap,
@@ -207,7 +207,7 @@ function initSocketHandle(self) {
// Handle creation may be deferred to bind() or connect() time.
if (self._handle) {
- self._handle.owner = self;
+ self._handle[owner_symbol] = self;
self._handle.onread = onread;
self[async_id_symbol] = getNewAsyncId(self._handle);
}
@@ -371,7 +371,7 @@ Socket.prototype._final = function(cb) {
function afterShutdown(status, handle) {
- var self = handle.owner;
+ var self = handle[owner_symbol];
debug('afterShutdown destroyed=%j', self.destroyed,
self._readableState);
@@ -620,7 +620,7 @@ Socket.prototype._destroy = function(exception, cb) {
// buffer, or when there's an error reading.
function onread(nread, buffer) {
var handle = this;
- var self = handle.owner;
+ var self = handle[owner_symbol];
assert(handle === self._handle, 'handle != self._handle');
self._unrefTimer();
@@ -819,7 +819,7 @@ protoGetter('bytesWritten', function bytesWritten() {
function afterWrite(status, handle, err) {
- var self = handle.owner;
+ var self = handle[owner_symbol];
if (self !== process.stderr && self !== process.stdout)
debug('afterWrite', status);
@@ -1123,7 +1123,7 @@ Socket.prototype.unref = function() {
function afterConnect(status, handle, req, readable, writable) {
- var self = handle.owner;
+ var self = handle[owner_symbol];
// callback may come after call to destroy
if (self.destroyed) {
@@ -1325,7 +1325,7 @@ function setupListenHandle(address, port, addressType, backlog, fd) {
this[async_id_symbol] = getNewAsyncId(this._handle);
this._handle.onconnection = onconnection;
- this._handle.owner = this;
+ this._handle[owner_symbol] = this;
// Use a backlog of 512 entries. We pass 511 to the listen() call because
// the kernel does: backlogsize = roundup_pow_of_two(backlogsize + 1);
@@ -1538,7 +1538,7 @@ Server.prototype.address = function() {
function onconnection(err, clientHandle) {
var handle = this;
- var self = handle.owner;
+ var self = handle[owner_symbol];
debug('onconnection');
@@ -1669,6 +1669,14 @@ 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', {
+ get() { return this[owner_symbol]; },
+ set(v) { return this[owner_symbol] = v; }
+});
+
+
Server.prototype.listenFD = internalUtil.deprecate(function(fd, type) {
return this.listen({ fd: fd });
}, 'Server.listenFD is deprecated. Use Server.listen({fd: <number>}) instead.',