Bug 1427939 - Fix console logging line numbers for paymentRequest.xhtml over HTTP. r=sfoster draft
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Wed, 18 Apr 2018 00:06:49 -0700
changeset 786366 f1f6017bfd640894bfad65f5795769c9b2cb52b5
parent 786365 0df089092eca54127cd8162a54d6827c972169ff
child 786367 fa3119fe5f5d9df1e4ea2628dc9a6ab2dac735bd
push id107441
push usermozilla@noorenberghe.ca
push dateMon, 23 Apr 2018 03:13:24 +0000
reviewerssfoster
bugs1427939
milestone61.0a1
Bug 1427939 - Fix console logging line numbers for paymentRequest.xhtml over HTTP. r=sfoster This fixes the console output to show the lines the log comes from which eases debugging. * Also fix a leftover unused argument always getting logged. MozReview-Commit-ID: 1YxrrinWta2
toolkit/components/payments/res/paymentRequest.js
toolkit/components/payments/res/unprivileged-fallbacks.js
--- a/toolkit/components/payments/res/paymentRequest.js
+++ b/toolkit/components/payments/res/paymentRequest.js
@@ -50,37 +50,37 @@ var paymentRequest = {
       }
       default: {
         throw new Error("Unexpected event type");
       }
     }
   },
 
   sendMessageToChrome(messageType, detail = {}) {
-    log.debug("sendMessageToChrome: ", messageType, detail);
+    log.debug("sendMessageToChrome:", messageType, detail);
     let event = new CustomEvent("paymentContentToChrome", {
       bubbles: true,
       detail: Object.assign({
         messageType,
       }, detail),
     });
     document.dispatchEvent(event);
   },
 
   toggleDebuggingConsole() {
     let debuggingConsole = document.getElementById("debugging-console");
-    if (!debuggingConsole.src) {
+    if (debuggingConsole.hidden && !debuggingConsole.src) {
       debuggingConsole.src = "debugging.html";
     }
     debuggingConsole.hidden = !debuggingConsole.hidden;
   },
 
   onChromeToContent({detail}) {
     let {messageType} = detail;
-    log.debug("onChromeToContent: ", messageType);
+    log.debug("onChromeToContent:", messageType);
 
     switch (messageType) {
       case "responseSent": {
         document.querySelector("payment-dialog").requestStore.setState({
           changesPrevented: true,
           completionState: "processing",
         });
         break;
@@ -91,18 +91,18 @@ var paymentRequest = {
       }
       case "updateState": {
         document.querySelector("payment-dialog").setStateFromParent(detail);
         break;
       }
     }
   },
 
-  onPaymentRequestLoad(requestId) {
-    log.debug("onPaymentRequestLoad:", requestId);
+  onPaymentRequestLoad() {
+    log.debug("onPaymentRequestLoad");
     window.addEventListener("unload", this, {once: true});
     this.sendMessageToChrome("paymentDialogReady");
 
     // Automatically show the debugging console if loaded with a truthy `debug` query parameter.
     if (new URLSearchParams(location.search).get("debug")) {
       this.toggleDebuggingConsole();
     }
   },
--- a/toolkit/components/payments/res/unprivileged-fallbacks.js
+++ b/toolkit/components/payments/res/unprivileged-fallbacks.js
@@ -1,36 +1,29 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /**
  * This file defines fallback objects to be used during development outside
  * of the paymentDialogWrapper. When loaded in the wrapper, a frame script
- * overwrites these methods.
+ * overwrites these methods. Since these methods need to get overwritten in the
+ * global scope, it can't be converted into an ES module.
  */
 
 /* eslint-disable no-console */
 /* exported log, PaymentDialogUtils */
 
 "use strict";
 
 var log = {
-  error(...args) {
-    console.error("log.js", ...args);
-  },
-  warn(...args) {
-    console.warn("log.js", ...args);
-  },
-  info(...args) {
-    console.info("log.js", ...args);
-  },
-  debug(...args) {
-    console.debug("log.js", ...args);
-  },
+  error: console.error.bind(console, "paymentRequest.xhtml:"),
+  warn: console.warn.bind(console, "paymentRequest.xhtml:"),
+  info: console.info.bind(console, "paymentRequest.xhtml:"),
+  debug: console.debug.bind(console, "paymentRequest.xhtml:"),
 };
 
 var PaymentDialogUtils = {
   getAddressLabel(address) {
     return `${address.name} (${address.guid})`;
   },
   isCCNumber(str) {
     return str.length > 0;