Bug 1394580 - 5. Lazy-load Task.jsm in Messaging.jsm; r=esawin draft
authorJim Chen <nchen@mozilla.com>
Tue, 05 Sep 2017 21:26:31 -0400
changeset 659407 3593910c4add9d99009b76f724ee6c6f5da94a66
parent 659406 e485845b1e4e7b90c9c41f98e4713609f53f00be
child 659408 222c91f787e6d3578f9c1121bad2ec442835b3df
push id78126
push userbmo:nchen@mozilla.com
push dateWed, 06 Sep 2017 01:26:43 +0000
reviewersesawin
bugs1394580
milestone57.0a1
Bug 1394580 - 5. Lazy-load Task.jsm in Messaging.jsm; r=esawin We're not lazy-loading Task.jsm in Messaging.jsm right now (despite declaring it through XPCOMUtils.defineLazyModuleGetter) because we unnecessarily reference `Task` when Messaging.jsm is loading. This patch makes us load Task.jsm only when `Task` is really needed. MozReview-Commit-ID: 9rrnLQLaW4y
mobile/android/modules/geckoview/Messaging.jsm
--- a/mobile/android/modules/geckoview/Messaging.jsm
+++ b/mobile/android/modules/geckoview/Messaging.jsm
@@ -191,30 +191,30 @@ DispatcherDelegate.prototype = {
 
     this._requestHandler.listeners[event] = undefined;
     this.unregisterListener(this._requestHandler, event);
   },
 
   _requestHandler: {
     listeners: {},
 
-    onEvent: Task.async(function* (event, data, callback) {
-      try {
-        let response = yield this.listeners[event](data.data);
+    onEvent: function(event, data, callback) {
+      let self = this;
+      Task.spawn(function* () {
+        return yield self.listeners[event](data.data);
+      }).then(response => {
         callback.onSuccess(response);
-
-      } catch (e) {
+      }, error => {
         Cu.reportError("Error in Messaging handler for " + event + ": " + e);
-
         callback.onError({
           message: e.message || (e && e.toString()),
           stack: e.stack || Components.stack.formattedStack,
         });
-      }
-    }),
+      });
+    },
   },
 };
 
 var EventDispatcher = {
   instance: new DispatcherDelegate(IS_PARENT_PROCESS ? Services.androidBridge : undefined),
 
   for: function(aWindow) {
     let view = aWindow && aWindow.arguments && aWindow.arguments[0] &&