Bug 1227539: allow a single argument to be passed to push message subscribers. r=Standard8

This commit is contained in:
Mike de Boer 2015-11-30 16:22:30 +01:00
parent e0a4c47e8a
commit 19ebfdffc2
2 changed files with 15 additions and 1 deletions

View File

@ -151,7 +151,11 @@ var loop = loop || {};
return; return;
} }
gSubscriptionsMap[eventName].forEach(function(cb) { gSubscriptionsMap[eventName].forEach(function(cb) {
cb.apply(null, message.data[1]); var data = message.data[1];
if (!Array.isArray(data)) {
data = [data];
}
cb.apply(null, data);
}); });
}); });
} }

View File

@ -243,6 +243,16 @@ describe("loopapi-client", function() {
sinon.assert.calledOnce(stub3); sinon.assert.calledOnce(stub3);
sinon.assert.calledWithExactly(stub3, "Foo", "Bar"); sinon.assert.calledWithExactly(stub3, "Foo", "Bar");
}); });
it("should invoke subscription with non-array arguments too", function() {
var stub = sinon.stub();
loop.subscribe("LoopStatusChanged", stub);
sendMessage({ data: ["LoopStatusChanged", "Foo"] });
sinon.assert.calledOnce(stub);
sinon.assert.calledWithExactly(stub, "Foo");
});
}); });
describe("unsubscribe", function() { describe("unsubscribe", function() {