Skip to content

Commit

Permalink
lib: fix behavior with util.inspect
Browse files Browse the repository at this point in the history
If one tried to print the result of `require('metarhia-jstp')` in
general or the `Connection` class itself to console, it resulted in
invocation of internal logic of the `Connection` and crashing with
an exception.

A similar issue had been fixed in
f7c393b and
76e4323 but was introduced again in
4a7941a.

Backport-of: #72
PR-URL: #114
Reviewed-by: Mykola Bilochub <nbelochub@gmail.com>
  • Loading branch information
aqrln committed Apr 2, 2017
1 parent 73fc2e9 commit d2bcb1e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ module.exports = Connection;

var nextConnectionId = 0;

// Mapping of packet types to handler function names (forward declaration, see
// definition below the Connection class).
//
var PACKET_HANDLERS;

// JSTP connection class
// transport - an abstract socket
// server - JSTP server instance, used only for server-side parts
Expand Down Expand Up @@ -332,7 +337,7 @@ Connection.prototype._processPacket = function(packet) {
return;
}

var handler = Connection.PACKET_HANDLERS[kind];
var handler = PACKET_HANDLERS[kind];
if (handler) {
handler.call(this, packet, keys);
} else {
Expand Down Expand Up @@ -632,9 +637,7 @@ Connection.prototype._emitPacketEvent = function(kind, packet, packetId, args) {
this.emit(kind, eventArgs);
};

// Mapping of packet types to handler function names
//
Connection.PACKET_HANDLERS = {
PACKET_HANDLERS = {
handshake: Connection.prototype._processHandshakePacket,
call: Connection.prototype._processCallPacket,
callback: Connection.prototype._processCallbackPacket,
Expand Down

0 comments on commit d2bcb1e

Please sign in to comment.