[xpcom] Catch errors from method calls and propagate if possible
authorKalle Vahlman <kalle.vahlman@movial.com>
Thu, 30 Apr 2009 05:46:41 +0000 (08:46 +0300)
committerKalle Vahlman <kalle.vahlman@movial.com>
Thu, 30 Apr 2009 05:46:41 +0000 (08:46 +0300)
html/dbus.js

index f3233944904f0e581022d57f804514447bc9cb81..bea3193449b963b4c8d8abbc8e791d462eddcdd6 100644 (file)
@@ -148,9 +148,16 @@ if (!window.DBus)
          */
         var method = function() {
             ep("UniversalXPConnect");
-            // FIXME: Is the copy really necessary? Why?
-            method.dbusmethod.doCall(Array.prototype.slice.call(arguments),
-                                     arguments.length);
+            try {
+              // The Array.prototype dance converts the "sort of Array but not
+              // quite" 'arguments' to a real Array object
+              method.dbusmethod.doCall(Array.prototype.slice.call(arguments),
+                                       arguments.length);
+            } catch (e) {
+              if (method._onerror) {
+                method._onerror.apply(method.user_data, [e.toString()]);
+              }
+            }
         };
 
         // Store the user specified "this" object
@@ -180,6 +187,8 @@ if (!window.DBus)
         method.watch("onerror", function(id, oldval, newval) {
             ep("UniversalXPConnect");
             method.dbusmethod.onError = unWrap(newval, method.user_data);
+            // We need to shadow the property for some reason...
+            method._onerror = newval;
         });
 
         // Mirror the async property