[Pkg-mozext-commits] [tabmixplus] 21/61: Replace in our log.jsm module logStringMessage with logMessage and add reportError to log error message to the console with the error file and line number

David Prévot taffit at moszumanska.debian.org
Fri Aug 28 19:09:18 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository tabmixplus.

commit 38369cb5d06c137f35435f7175d7090cd7fc709b
Author: onemen <tabmix.onemen at gmail.com>
Date:   Mon Jul 27 18:48:55 2015 +0300

    Replace in our log.jsm module logStringMessage with logMessage and add reportError to log error message to the console with the error file and line number
---
 chrome/content/changecode.js                       |   5 +-
 chrome/content/places/places.js                    |   2 +-
 .../preferences/overlay/overlaySanitizeUI.js       |   2 +-
 chrome/content/session/session.js                  |   4 +-
 chrome/content/session/sessionStore.js             |   2 +-
 chrome/content/tabmix.js                           |   2 +-
 chrome/content/utils.js                            |   4 +-
 modules/log.jsm                                    | 102 +++++++++++++++------
 8 files changed, 86 insertions(+), 37 deletions(-)

diff --git a/chrome/content/changecode.js b/chrome/content/changecode.js
index f396d73..f792a63 100644
--- a/chrome/content/changecode.js
+++ b/chrome/content/changecode.js
@@ -84,9 +84,8 @@ Tabmix.changeCode = function(aParent, aName, aOptions) {
         if (aShow)
           this.show(obj, fnName);
       } catch (ex) {
-        Components.utils.reportError("Tabmix " + console.callerName() +
-                                     " failed to change " + this.fullName +
-                                     "\nError: " + ex.message);
+        console.reportError(ex, console.callerName() + " failed to change " +
+                            this.fullName + "\nError: ");
       }
     },
 
diff --git a/chrome/content/places/places.js b/chrome/content/places/places.js
index 0a3de80..dc02971 100644
--- a/chrome/content/places/places.js
+++ b/chrome/content/places/places.js
@@ -472,7 +472,7 @@ var TMP_Places = {
         PlacesUtils.addLazyBookmarkObserver(this);
         this._hasBookmarksObserver = true;
       } catch(ex) {
-        Components.utils.reportError("Tabmix failed adding a bookmarks observer: " + ex);
+        Tabmix.reportError(ex, "Failed to add bookmarks observer:");
       }
     }
   },
diff --git a/chrome/content/preferences/overlay/overlaySanitizeUI.js b/chrome/content/preferences/overlay/overlaySanitizeUI.js
index d1bed05..5f3768c 100644
--- a/chrome/content/preferences/overlay/overlaySanitizeUI.js
+++ b/chrome/content/preferences/overlay/overlaySanitizeUI.js
@@ -24,7 +24,7 @@ Tabmix.setSanitizer = {
           let win = Tabmix.getTopWin();
           win.Tabmix.Sanitizer.sanitize();
         } catch (ex) {
-          try { Components.utils.reportError(ex); } catch(e) {}
+          try {Tabmix.reportError(ex);} catch(e) { }
         }
       },
       get canClear() {
diff --git a/chrome/content/session/session.js b/chrome/content/session/session.js
index 3b46c24..527a51f 100644
--- a/chrome/content/session/session.js
+++ b/chrome/content/session/session.js
@@ -275,7 +275,7 @@ var TabmixSessionManager = { // jshint ignore:line
       if (Tabmix.isVersion(250, 250) && !TabmixSvc.sm.promiseInitialized) {
         Tabmix.ssPromise = aPromise || TabmixSvc.ss.promiseInitialized;
         Tabmix.ssPromise.then(initializeSM)
-                        .then(null, Cu.reportError);
+                        .then(null, Tabmix.reportError);
       }
       else
         initializeSM();
@@ -982,7 +982,7 @@ if (container == "error") { Tabmix.log("wrapContainer error path " + path + "\n"
          let msg = "Tabmix is unable to decode " + key;
          if (node)
             msg += " from " + node.QueryInterface(Ci.nsIRDFResource).Value;
-         Components.utils.reportError(msg + "\n" + er);
+         Tabmix.reportError(msg + "\n" + er);
          return "";
        }
        if (node && key) {
diff --git a/chrome/content/session/sessionStore.js b/chrome/content/session/sessionStore.js
index c0dab7d..f043722 100644
--- a/chrome/content/session/sessionStore.js
+++ b/chrome/content/session/sessionStore.js
@@ -252,7 +252,7 @@ var TMP_SessionStore = { // jshint ignore:line
               return ss.doRestore();
             ss.onceInitialized.then(function() {
               Tabmix.isWindowAfterSessionRestore = ss.doRestore();
-            }).then(null, Cu.reportError);
+            }).then(null, Tabmix.reportError);
             // until sessionstartup initialized just return the pref value,
             // we only use isWindowAfterSessionRestore when our Session Manager enable
             return Services.prefs.getBoolPref("browser.sessionstore.resume_session_once");
diff --git a/chrome/content/tabmix.js b/chrome/content/tabmix.js
index 1881019..949965e 100644
--- a/chrome/content/tabmix.js
+++ b/chrome/content/tabmix.js
@@ -179,7 +179,7 @@ Tabmix.delayedStartup = function TMP_delayedStartup() {
   TabmixTabbar._enablePositionCheck = true;
 
   if (this.isVersion(250) && this.ssPromise && !TabmixSvc.sm.promiseInitialized)
-    this.ssPromise.then(this.sessionInitialized.bind(this), Cu.reportError);
+    this.ssPromise.then(this.sessionInitialized.bind(this), Tabmix.reportError);
   else
     this.sessionInitialized();
 
diff --git a/chrome/content/utils.js b/chrome/content/utils.js
index 6a69cfd..9f77d8e 100644
--- a/chrome/content/utils.js
+++ b/chrome/content/utils.js
@@ -247,11 +247,11 @@ var Tabmix = { // jshint ignore:line
 
     var methods = ["changeCode", "setNewFunction", "nonStrictMode",
                    "getObject", "log", "getCallerNameByIndex", "callerName",
-                   "clog", "isCallerInList", "obj", "assert", "trace"];
+                   "clog", "isCallerInList", "obj", "assert", "trace", "reportError"];
     methods.forEach(function(id) {
       this[id] = function TMP_console_wrapper() {
         return this._getMethod(id, arguments);
-      };
+      }.bind(this);
     }, this);
   },
 
diff --git a/modules/log.jsm b/modules/log.jsm
index 9fb8088..406230b 100644
--- a/modules/log.jsm
+++ b/modules/log.jsm
@@ -54,7 +54,7 @@ this.console = {
                 this.getObject(aWindow, aMethod);
           result = " = " + result.toString();
         }
-        this.clog((isObj ? aMethod.fullName : aMethod) + result);
+        this.clog((isObj ? aMethod.fullName : aMethod) + result, this.caller);
       }.bind(this);
 
       if (aDelay >= 0) {
@@ -85,22 +85,6 @@ this.console = {
     } catch (ex) {this.assert(ex, "Error we can't show " + aMethod + " in Tabmix.show");}
   },
 
-  _logStringMessage: function(aMessage) {
-    Services.console.logStringMessage(aMessage.replace(/\r\n/g, "\n"));
-  },
-
-  clog: function(aMessage) {
-    this._logStringMessage("TabMix :\n" + aMessage);
-  },
-
-  log: function TMP_console_log(aMessage, aShowCaller, offset) {
-    offset = !offset ? 0 : 1;
-    let names = this._getNames(aShowCaller ? 2 + offset : 1 + offset);
-    let callerName = names[offset+0];
-    let callerCallerName = aShowCaller && names[offset+1] ? " (caller was " + names[offset+1] + ")" : "";
-    this._logStringMessage("TabMix " + callerName + callerCallerName + " :\n" + aMessage);
-  },
-
   // get functions names from Error().stack
   // excluding any internal caller (name start with TMP_console_)
   _getNames: function(aCount, stack) {
@@ -226,8 +210,10 @@ options = {
     }
     if (aDisallowLog)
       objS = aMessage + "======================\n" + objS;
-    else
-      this.log(aMessage + "=============== Object Properties ===============\n" + objS, true);
+    else {
+      let msg = aMessage + "=============== Object Properties ===============\n";
+      this.log(msg + objS, true, false, this.caller);
+    }
     return objS;
   },
 
@@ -269,22 +255,86 @@ options = {
     return lines.join("\n");
   },
 
+  /* logMessage */
+
+  clog: function(aMessage, caller) {
+    this._logMessage(":\n" + aMessage, "infoFlag", caller);
+  },
+
+  log: function TMP_console_log(aMessage, aShowCaller, offset, caller) {
+    offset = !offset ? 0 : 1;
+    let names = this._getNames(aShowCaller ? 2 + offset : 1 + offset);
+    let callerName = names[offset+0];
+    let callerCallerName = aShowCaller && names[offset+1] ? " (caller was " + names[offset+1] + ")" : "";
+    this._logMessage(" " + callerName + callerCallerName + ":\n" + aMessage, "infoFlag", caller);
+  },
+
   assert: function TMP_console_assert(aError, aMsg) {
     if (!aError || typeof aError.stack != "string") {
-      this.trace((aMsg || "") + "\n" + (aError || ""), 2);
+      let msg = aMsg ? aMsg + "\n" : "";
+      this.trace(msg + (aError || ""), "errorFlag", this.caller);
       return;
     }
+    if (/Error/.test(Object.getPrototypeOf(aError))) {
+      this.reportError(aError, aMsg);
+    }
 
     let names = this._getNames(1, aError.stack);
     let errAt = " at " + names[0];
     let location = aError.location ? "\n" + aError.location : "";
-    let assertionText = "Tabmix Plus ERROR" + errAt + ":\n" + (aMsg ? aMsg + "\n" : "") + aError.message + location;
-    let stackText = "\nStack Trace: \n" + this._formatStack(aError.stack.split("\n"));
-    this._logStringMessage(assertionText + stackText);
+    let assertionText = " ERROR" + errAt + ":\n" + (aMsg ? aMsg + "\n" : "") + aError.message + location;
+    let stackText = "\nStack Trace:\n" + this._formatStack(aError.stack.split("\n"));
+    this._logMessage(assertionText + stackText, "errorFlag");
   },
 
-  trace: function TMP_console_trace(aMsg) {
+  trace: function TMP_console_trace(aMsg, flag="infoFlag", caller=null) {
     let stack = this._formatStack(this._getStackExcludingInternal());
-    this._logStringMessage("Tabmix Trace: " + (aMsg || "") + '\n' + stack);
-  }
+    let msg = aMsg ? aMsg + "\n" : "";
+    this._logMessage(":\n" + msg + "Stack Trace:\n" + stack, flag, caller);
+  },
+
+  get caller() {
+    let parent = Components.stack.caller;
+    parent = parent.name == "_logMessage" ? parent.caller.caller : parent.caller;
+    if (parent.name == "TMP_console_wrapper")
+      parent = parent.caller.caller;
+    return parent;
+  },
+
+  reportError: function(ex=null, msg="") {
+    if (ex === null) {
+      ex = "reportError was called with null";
+    }
+    msg = ":\n" + (msg ? msg + "\n" : "");
+    if (typeof ex != "object" || ex instanceof OS.File.Error ||
+        typeof ex.message != "string") {
+      this._logMessage(msg + ex.toString(), "errorFlag");
+    }
+    else {
+      if (typeof ex.filename == "undefined") {
+        ex.filename = ex.fileName;
+      }
+      this._logMessage(msg + ex.message, "errorFlag", ex);
+    }
+  },
+
+  _logMessage: function _logMessage(msg, flag="infoFlag", caller=null) {
+    msg = msg.replace(/\r\n/g, "\n");
+    if (typeof Ci.nsIScriptError[flag] == "undefined") {
+      Services.console.logStringMessage("Tabmix" + msg);
+      return;
+    }
+    if (!caller)
+      caller = this.caller;
+    let {filename, lineNumber, columnNumber} = caller;
+    let consoleMsg = Cc["@mozilla.org/scripterror;1"].createInstance(Ci.nsIScriptError);
+    consoleMsg.init("Tabmix" + msg, filename, null, lineNumber, columnNumber,
+                    Ci.nsIScriptError[flag], "component javascript");
+    Services.console.logMessage(consoleMsg);
+  },
+
 };
+
+(function(self){
+  self.reportError = self.reportError.bind(self);
+}(this.console));

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/tabmixplus.git



More information about the Pkg-mozext-commits mailing list