Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
symbol
  • Loading branch information
indutny committed Apr 20, 2016
commit 6357f469a89ab1f6fbf7560aebff545b66785d69
10 changes: 7 additions & 3 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ function initSocketHandle(self) {
}
}


const BYTES_READ = Symbol('bytesRead');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the naming preference is something like kBytesRead

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it?

lib/readline.js:const KEYPRESS_DECODER = Symbol('keypress-decoder');
lib/readline.js:const ESCAPE_DECODER = Symbol('escape-decoder');
lib/repl.js:exports.REPL_MODE_SLOPPY = Symbol('repl-sloppy');
lib/repl.js:exports.REPL_MODE_STRICT = Symbol('repl-strict');
lib/repl.js:exports.REPL_MODE_MAGIC = Symbol('repl-magic');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, yep, I've seen comments both ways but the code doesn't lie ;-)



function Socket(options) {
if (!(this instanceof Socket)) return new Socket(options);

Expand Down Expand Up @@ -180,7 +184,7 @@ function Socket(options) {
this._server = null;

// Used after `.destroy()`
this._bytesRead = 0;
this[BYTES_READ] = 0;
}
util.inherits(Socket, stream.Duplex);

Expand Down Expand Up @@ -473,7 +477,7 @@ Socket.prototype._destroy = function(exception, cb) {
debug('close handle');
var isException = exception ? true : false;
// `bytesRead` should be accessible after `.destroy()`
this._bytesRead = this._handle.bytesRead;
this[BYTES_READ] = this._handle.bytesRead;

this._handle.close(() => {
debug('emit close');
Expand Down Expand Up @@ -582,7 +586,7 @@ Socket.prototype._getpeername = function() {
};

Socket.prototype.__defineGetter__('bytesRead', function() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since __defineGetter__ is deprecated now, can these be turned into proper Object.defineProperty() calls? Perhaps as a separate commit in this PR?

e.g.

Object.defineProperty(Socket.prototype, 'bytesRead', {
  configurable: false,
  enumerable: true,
  get: function() {
    return this._handle ? this.handle.bytesRead : this[BYTES_READ];
  }
});

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack.

return this._handle ? this._handle.bytesRead : this._bytesRead;
return this._handle ? this._handle.bytesRead : this[BYTES_READ];
});

Socket.prototype.__defineGetter__('remoteAddress', function() {
Expand Down