Bug 1394580 - 5. Lazy-load Task.jsm in Messaging.jsm; r=esawin
authorJim Chen <nchen@mozilla.com>
Tue, 05 Sep 2017 21:26:31 -0400
changeset 428579 b3b76444d58d39739c4b41ebe236023b57c55449
parent 428578 dd645a7a4f81fc40928e504f942c125b8469fea8
child 428580 be2d4180503168ed1ec5b657b312ca37bfbc2efb
push id7761
push userjlund@mozilla.com
push dateFri, 15 Sep 2017 00:19:52 +0000
treeherdermozilla-beta@c38455951db4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersesawin
bugs1394580
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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] &&