Skip to content

Commit

Permalink
Make Board.prototype.sysexResponse handler context equal board. Fixes g…
Browse files Browse the repository at this point in the history
…h-175

Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
  • Loading branch information
rwaldron committed Jun 23, 2017
1 parent 1bce5e1 commit 29a7e75
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/firmata.js
Expand Up @@ -1959,7 +1959,7 @@ Board.prototype.sysexResponse = function(commandByte, handler) {
}

Board.SYSEX_RESPONSE[commandByte] = function(board) {
handler(board.currentBuffer.slice(2, -1));
handler.call(board, board.currentBuffer.slice(2, -1));
};

return this;
Expand Down
12 changes: 12 additions & 0 deletions test/unit/firmata.test.js
Expand Up @@ -3119,6 +3119,18 @@ describe("Board: lifecycle", function() {
transport.emit("data", incoming);
});

it("SYSEX_RESPONSE handler context is board", function(done) {

var incoming = [START_SYSEX, NON_STANDARD_REPLY, 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, END_SYSEX];

board.sysexResponse(NON_STANDARD_REPLY, function(data) {
assert.equal(this, board);
done();
});

transport.emit("data", incoming);
});

it("fail when overwriting SYSEX_RESPONSE command byte", function(done) {
Board.SYSEX_RESPONSE[0xFF] = function() {};

Expand Down

0 comments on commit 29a7e75

Please sign in to comment.