Bug 971255 - [AccessFu] Allow providing a callable argument to Logger log calls. r=yzen
authorEitan Isaacson <eitan@monotonous.org>
Thu, 27 Feb 2014 10:42:45 -0500
changeset 171330 9e33d25de087f36da0a07fba3c85fa387992acf3
parent 171329 192efb36136aec8f4436d0b1b7cb630db6ca5d96
child 171331 1e610fc98cb9dc26e892d5c1498291ae3b617ec5
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewersyzen
bugs971255
milestone30.0a1
Bug 971255 - [AccessFu] Allow providing a callable argument to Logger log calls. r=yzen
accessible/src/jsat/AccessFu.jsm
accessible/src/jsat/EventManager.jsm
accessible/src/jsat/Utils.jsm
accessible/src/jsat/content-script.js
--- a/accessible/src/jsat/AccessFu.jsm
+++ b/accessible/src/jsat/AccessFu.jsm
@@ -192,18 +192,19 @@ this.AccessFu = {
       else
         this._disable();
     } catch (x) {
       dump('Error ' + x.message + ' ' + x.fileName + ':' + x.lineNumber);
     }
   },
 
   receiveMessage: function receiveMessage(aMessage) {
-    if (Logger.logLevel >= Logger.DEBUG)
-      Logger.debug('Recieved', aMessage.name, JSON.stringify(aMessage.json));
+    Logger.debug(() => {
+      return ['Recieved', aMessage.name, JSON.stringify(aMessage.json)];
+    });
 
     switch (aMessage.name) {
       case 'AccessFu:Ready':
         let mm = Utils.getMessageManager(aMessage.target);
         if (this._enabled) {
           mm.sendAsyncMessage('AccessFu:Start',
                               {method: 'start', buildApp: Utils.MozBuildApp});
         }
--- a/accessible/src/jsat/EventManager.jsm
+++ b/accessible/src/jsat/EventManager.jsm
@@ -84,16 +84,20 @@ this.EventManager.prototype = {
     } catch (x) {
       // contentScope is dead.
     } finally {
       this._started = false;
     }
   },
 
   handleEvent: function handleEvent(aEvent) {
+    Logger.debug(() => {
+      return ['DOMEvent', aEvent.type];
+    });
+
     try {
       switch (aEvent.type) {
       case 'wheel':
       {
         let attempts = 0;
         let vc = Utils.getVirtualCursor(this.contentScope.content.document);
         let intervalId = this.contentScope.content.setInterval(() => {
           if (!Utils.isAliveAndVisible(vc.position, true)) {
@@ -124,19 +128,20 @@ this.EventManager.prototype = {
       }
       }
     } catch (x) {
       Logger.logException(x, 'Error handling DOM event');
     }
   },
 
   handleAccEvent: function handleAccEvent(aEvent) {
-    if (Logger.logLevel >= Logger.DEBUG)
-      Logger.debug('A11yEvent', Logger.eventToString(aEvent),
-                   Logger.accessibleToString(aEvent.accessible));
+    Logger.debug(() => {
+      return ['A11yEvent', Logger.eventToString(aEvent),
+              Logger.accessibleToString(aEvent.accessible)];
+    });
 
     // Don't bother with non-content events in firefox.
     if (Utils.MozBuildApp == 'browser' &&
         aEvent.eventType != Events.VIRTUALCURSOR_CHANGED &&
         // XXX Bug 442005 results in DocAccessible::getDocType returning
         // NS_ERROR_FAILURE. Checking for aEvent.accessibleDocument.docType ==
         // 'window' does not currently work.
         (aEvent.accessibleDocument.DOMDocument.doctype &&
--- a/accessible/src/jsat/Utils.jsm
+++ b/accessible/src/jsat/Utils.jsm
@@ -346,17 +346,18 @@ this.Logger = {
   logLevel: 1, // INFO;
 
   test: false,
 
   log: function log(aLogLevel) {
     if (aLogLevel < this.logLevel)
       return;
 
-    let message = Array.prototype.slice.call(arguments, 1).join(' ');
+    let args = Array.prototype.slice.call(arguments, 1);
+    let message = (typeof(args[0]) === 'function' ? args[0]() : args).join(' ');
     message = '[' + Utils.ScriptName + '] ' + this._LEVEL_NAMES[aLogLevel] +
       ' ' + message + '\n';
     dump(message);
     // Note: used for testing purposes. If |this.test| is true, also log to
     // the console service.
     if (this.test) {
       try {
         Services.console.logStringMessage(message);
--- a/accessible/src/jsat/content-script.js
+++ b/accessible/src/jsat/content-script.js
@@ -111,19 +111,19 @@ function moveToPoint(aMessage) {
     vc.moveToPoint(rule, details.x * dpr, details.y * dpr, true);
     forwardToChild(aMessage, moveToPoint, vc.position);
   } catch (x) {
     Logger.logException(x, 'Failed move to point');
   }
 }
 
 function showCurrent(aMessage) {
-  if (Logger.logLevel >= Logger.DEBUG) {
-    Logger.debug(aMessage.name, JSON.stringify(aMessage.json, null, ' '));
-  }
+  Logger.debug(() => {
+    return [aMessage.name, JSON.stringify(aMessage.json, null, ' ')];
+  });
 
   let vc = Utils.getVirtualCursor(content.document);
 
   if (!forwardToChild(vc, showCurrent, aMessage)) {
     if (!vc.position && aMessage.json.move) {
       vc.moveFirst(TraversalRules.Simple);
     } else {
       sendAsyncMessage('AccessFu:Present', Presentation.pivotChanged(
@@ -142,20 +142,20 @@ function forwardToParent(aMessage) {
 
 function forwardToChild(aMessage, aListener, aVCPosition) {
   let acc = aVCPosition || Utils.getVirtualCursor(content.document).position;
 
   if (!Utils.isAliveAndVisible(acc) || acc.role != Roles.INTERNAL_FRAME) {
     return false;
   }
 
-  if (Logger.logLevel >= Logger.DEBUG) {
-    Logger.debug('forwardToChild', Logger.accessibleToString(acc),
-                 aMessage.name, JSON.stringify(aMessage.json, null, '  '));
-  }
+  Logger.debug(() => {
+    return ['forwardToChild', Logger.accessibleToString(acc),
+            aMessage.name, JSON.stringify(aMessage.json, null, '  ')];
+  });
 
   let mm = Utils.getMessageManager(acc.DOMNode);
 
   if (aListener) {
     mm.addMessageListener(aMessage.name, aListener);
   }
 
   // XXX: This is a silly way to make a deep copy