From 936135f0ac73a26797065e98b98d7e4f3a8f0e2d Mon Sep 17 00:00:00 2001 From: Andreas Tolfsen Date: Thu, 5 Oct 2017 17:50:34 +0100 Subject: [PATCH] Bug 1400256 - Serialise IPC messages with evaluate.toJSON. r=whimboo Instead of having commands serialising their own JSON-safe messages when communicating with the content frame script, this patch changes the AsyncMessageChannel to use evaluate.toJSON. MozReview-Commit-ID: LmAVGEjqMTB --HG-- extra : rebase_source : 7f39cccc1468217a8a6bcf107241fd5648cb24d2 --- testing/marionette/proxy.js | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/testing/marionette/proxy.js b/testing/marionette/proxy.js index 2b1cb48e7b31..331f1ecc7778 100644 --- a/testing/marionette/proxy.js +++ b/testing/marionette/proxy.js @@ -13,6 +13,7 @@ const { error, WebDriverError, } = Cu.import("chrome://marionette/content/error.js", {}); +Cu.import("chrome://marionette/content/evaluate.js"); Cu.import("chrome://marionette/content/modal.js"); this.EXPORTED_SYMBOLS = ["proxy"]; @@ -126,30 +127,31 @@ proxy.AsyncMessageChannel = class { let path = proxy.AsyncMessageChannel.makePath(uuid); let cb = msg => { this.activeMessageId = null; + let {data, type} = msg.json; switch (msg.json.type) { case proxy.AsyncMessageChannel.ReplyType.Ok: case proxy.AsyncMessageChannel.ReplyType.Value: - resolve(msg.json.data); + let payload = evaluate.fromJSON(data); + resolve(payload); break; case proxy.AsyncMessageChannel.ReplyType.Error: - let err = WebDriverError.fromJSON(msg.json.data); + let err = WebDriverError.fromJSON(data); reject(err); break; default: - throw new TypeError( - `Unknown async response type: ${msg.json.type}`); + throw new TypeError(`Unknown async response type: ${type}`); } }; // The currently selected tab or window has been closed. No clean-up // is necessary to do because all loaded listeners are gone. - this.closeHandler = event => { - logger.debug(`Received DOM event ${event.type} for ${event.target}`); + this.closeHandler = ({type, target}) => { + logger.debug(`Received DOM event ${type} for ${target}`); - switch (event.type) { + switch (type) { case "TabClose": case "unload": this.removeHandlers(); @@ -162,7 +164,7 @@ proxy.AsyncMessageChannel = class { // the active command has to be aborted. Therefore remove all handlers, // and cancel any ongoing requests in the listener. this.dialogueObserver_ = (subject, topic) => { - logger.debug(`Received observer notification "${topic}"`); + logger.debug(`Received observer notification ${topic}`); this.removeAllListeners_(); // TODO(ato): It's not ideal to have listener specific behaviour here: @@ -259,17 +261,11 @@ proxy.AsyncMessageChannel = class { } } - sendReply_(uuid, type, data = undefined) { + sendReply_(uuid, type, payload = undefined) { const path = proxy.AsyncMessageChannel.makePath(uuid); - let payload; - if (data && typeof data.toJSON == "function") { - payload = data.toJSON(); - } else { - payload = data; - } - - const msg = {type, data: payload}; + let data = evaluate.toJSON(payload); + const msg = {type, data}; // here sendAsync is actually the content frame's // sendAsyncMessage(path, message) global