mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 19:04:45 +00:00
Bug 1299411 - Pass port parameter to port.onMessage r=kmag
This should have been a part of bug 1298810, but that only set the argument for native messaging ports, which does not use Port from ExtensionUtils. The port parameter must also be included in runtime's Port.onMessage to avoid regressions when the port implementations are unified and native messaging starts using runtime's Port. Note that starting from this commit, multiple onMessage listeners receive the same (cloned) message instead of a new clone per listener. This is a side effect of using `fire.withoutClone` instead of `fire`: `fire` clones all parameters, but ports are not cloneable so we have to use `fire.withoutClone` instead. This change with regards to message cloning is fully compatible with Chrome's messaging API (which also passes the same message object to all `port.onMessage` calls). MozReview-Commit-ID: AUDuUKHkXCM --HG-- extra : rebase_source : b91d701bba21f376935961a6eeb1a8489ac5591b
This commit is contained in:
parent
5749ce4557
commit
ca2c1cf947
@ -20,8 +20,9 @@ add_task(function* () {
|
||||
ports_received++;
|
||||
browser.test.assertEq(1, ports_received, "1 port received");
|
||||
|
||||
port.onMessage.addListener((msg, sender) => {
|
||||
port.onMessage.addListener((msg, msgPort) => {
|
||||
browser.test.assertEq("port message", msg, "listener1 port message received");
|
||||
browser.test.assertEq(port, msgPort, "onMessage should receive port as second argument");
|
||||
|
||||
port_messages_received++;
|
||||
browser.test.assertEq(1, port_messages_received, "1 port message received");
|
||||
@ -33,8 +34,9 @@ add_task(function* () {
|
||||
ports_received++;
|
||||
browser.test.assertEq(2, ports_received, "2 ports received");
|
||||
|
||||
port.onMessage.addListener((msg, sender) => {
|
||||
port.onMessage.addListener((msg, msgPort) => {
|
||||
browser.test.assertEq("port message", msg, "listener2 port message received");
|
||||
browser.test.assertEq(port, msgPort, "onMessage should receive port as second argument");
|
||||
|
||||
port_messages_received++;
|
||||
browser.test.assertEq(2, port_messages_received, "2 port messages received");
|
||||
|
@ -1262,7 +1262,8 @@ Port.prototype = {
|
||||
}).api(),
|
||||
onMessage: new EventManager(this.context, "Port.onMessage", fire => {
|
||||
return this.registerOnMessage(msg => {
|
||||
fire(msg);
|
||||
msg = Cu.cloneInto(msg, this.context.cloneScope);
|
||||
fire.withoutClone(msg, portObj);
|
||||
});
|
||||
}).api(),
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user