cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject [1/8] js commit: [android] Don't catch exceptions wihtin the bridge since the browser does better logging of them when uncaught.
Date Wed, 11 Sep 2013 23:30:42 GMT
Updated Branches:
  refs/heads/ffos 3be32a335 -> 062730881


[android] Don't catch exceptions wihtin the bridge since the browser does better logging of
them when uncaught.


Project: http://git-wip-us.apache.org/repos/asf/cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-js/commit/8937f29e
Tree: http://git-wip-us.apache.org/repos/asf/cordova-js/tree/8937f29e
Diff: http://git-wip-us.apache.org/repos/asf/cordova-js/diff/8937f29e

Branch: refs/heads/ffos
Commit: 8937f29ee8aa58568db94865860c86615acf23ca
Parents: 7d5f6f6
Author: Andrew Grieve <agrieve@chromium.org>
Authored: Fri Aug 30 16:12:50 2013 -0400
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Fri Aug 30 16:12:50 2013 -0400

----------------------------------------------------------------------
 lib/android/exec.js | 89 +++++++++++++++++++++++-------------------------
 1 file changed, 43 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-js/blob/8937f29e/lib/android/exec.js
----------------------------------------------------------------------
diff --git a/lib/android/exec.js b/lib/android/exec.js
index 0d35ff1..a68608f 100644
--- a/lib/android/exec.js
+++ b/lib/android/exec.js
@@ -169,50 +169,44 @@ androidExec.setNativeToJsBridgeMode = function(mode) {
 
 // Processes a single message, as encoded by NativeToJsMessageQueue.java.
 function processMessage(message) {
-    try {
-        var firstChar = message.charAt(0);
-        if (firstChar == 'J') {
-            eval(message.slice(1));
-        } else if (firstChar == 'S' || firstChar == 'F') {
-            var success = firstChar == 'S';
-            var keepCallback = message.charAt(1) == '1';
-            var spaceIdx = message.indexOf(' ', 2);
-            var status = +message.slice(2, spaceIdx);
-            var nextSpaceIdx = message.indexOf(' ', spaceIdx + 1);
-            var callbackId = message.slice(spaceIdx + 1, nextSpaceIdx);
-            var payloadKind = message.charAt(nextSpaceIdx + 1);
-            var payload;
-            if (payloadKind == 's') {
-                payload = message.slice(nextSpaceIdx + 2);
-            } else if (payloadKind == 't') {
-                payload = true;
-            } else if (payloadKind == 'f') {
-                payload = false;
-            } else if (payloadKind == 'N') {
-                payload = null;
-            } else if (payloadKind == 'n') {
-                payload = +message.slice(nextSpaceIdx + 2);
-            } else if (payloadKind == 'A') {
-                var data = message.slice(nextSpaceIdx + 2);
-                var bytes = window.atob(data);
-                var arraybuffer = new Uint8Array(bytes.length);
-                for (var i = 0; i < bytes.length; i++) {
-                    arraybuffer[i] = bytes.charCodeAt(i);
-                }
-                payload = arraybuffer.buffer;
-            } else if (payloadKind == 'S') {
-                payload = window.atob(message.slice(nextSpaceIdx + 2));
-            } else {
-                payload = JSON.parse(message.slice(nextSpaceIdx + 1));
+    var firstChar = message.charAt(0);
+    if (firstChar == 'J') {
+        eval(message.slice(1));
+    } else if (firstChar == 'S' || firstChar == 'F') {
+        var success = firstChar == 'S';
+        var keepCallback = message.charAt(1) == '1';
+        var spaceIdx = message.indexOf(' ', 2);
+        var status = +message.slice(2, spaceIdx);
+        var nextSpaceIdx = message.indexOf(' ', spaceIdx + 1);
+        var callbackId = message.slice(spaceIdx + 1, nextSpaceIdx);
+        var payloadKind = message.charAt(nextSpaceIdx + 1);
+        var payload;
+        if (payloadKind == 's') {
+            payload = message.slice(nextSpaceIdx + 2);
+        } else if (payloadKind == 't') {
+            payload = true;
+        } else if (payloadKind == 'f') {
+            payload = false;
+        } else if (payloadKind == 'N') {
+            payload = null;
+        } else if (payloadKind == 'n') {
+            payload = +message.slice(nextSpaceIdx + 2);
+        } else if (payloadKind == 'A') {
+            var data = message.slice(nextSpaceIdx + 2);
+            var bytes = window.atob(data);
+            var arraybuffer = new Uint8Array(bytes.length);
+            for (var i = 0; i < bytes.length; i++) {
+                arraybuffer[i] = bytes.charCodeAt(i);
             }
-            cordova.callbackFromNative(callbackId, success, status, [payload], keepCallback);
+            payload = arraybuffer.buffer;
+        } else if (payloadKind == 'S') {
+            payload = window.atob(message.slice(nextSpaceIdx + 2));
         } else {
-            console.log("processMessage failed: invalid message:" + message);
+            payload = JSON.parse(message.slice(nextSpaceIdx + 1));
         }
-    } catch (e) {
-        console.log("processMessage failed: Message: " + message);
-        console.log("processMessage failed: Error: " + e);
-        console.log("processMessage failed: Stack: " + e.stack);
+        cordova.callbackFromNative(callbackId, success, status, [payload], keepCallback);
+    } else {
+        console.log("processMessage failed: invalid message:" + message);
     }
 }
 
@@ -239,11 +233,14 @@ androidExec.processMessages = function(messages) {
             var msgLen = +messages.slice(0, spaceIdx);
             var message = messages.substr(spaceIdx + 1, msgLen);
             messages = messages.slice(spaceIdx + msgLen + 1);
-            processMessage(message);
-            if (messages) {
-                messagesFromNative[0] = messages;
-            } else {
-                messagesFromNative.shift();
+            try {
+                processMessage(message);
+            } finally {
+                if (messages) {
+                    messagesFromNative[0] = messages;
+                } else {
+                    messagesFromNative.shift();
+                }
             }
         }
     }


Mime
View raw message