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.

PR-URL: #72
  • Loading branch information
aqrln committed Feb 13, 2017
1 parent 51c763f commit 9759d84
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;

let nextConnectionId = 0;

// Mapping of packet types to handler function names (forward declaration, see
// definition below the Connection class).
//
let PACKET_HANDLERS; // eslint-disable-line prefer-const

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

const handler = Connection.PACKET_HANDLERS[kind];
const handler = PACKET_HANDLERS[kind];
if (handler) {
handler.call(this, packet, keys);
} else {
Expand Down Expand Up @@ -619,9 +624,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 9759d84

Please sign in to comment.