浏览代码

Don't put define in try/catch. Breaks optimizer.

Add check HAS_CSPRNG instead of the previous check
JC Brand 11 年之前
父节点
当前提交
67c99f60fe
共有 1 个文件被更改,包括 14 次插入39 次删除
  1. 14 39
      converse.js

+ 14 - 39
converse.js

@@ -12,19 +12,7 @@
         console = { log: function () {}, error: function () {} };
         console = { log: function () {}, error: function () {} };
     }
     }
     if (typeof define === 'function' && define.amd) {
     if (typeof define === 'function' && define.amd) {
-        var on_load = function(CryptoJS, otr) {
-            // Use Mustache style syntax for variable interpolation
-            _.templateSettings = {
-                evaluate : /\{\[([\s\S]+?)\]\}/g,
-                interpolate : /\{\{([\s\S]+?)\}\}/g
-            };
-            if (typeof otr !== "undefined") {
-                return factory(jQuery, _, CryptoJS, otr.OTR, otr.DSA, console);
-            } else {
-                return factory(jQuery, _, undefined, undefined, undefined, console);
-            }
-        };
-        var dependencies = [
+        define("converse", [
             "crypto",
             "crypto",
             "otr",
             "otr",
             "locales",
             "locales",
@@ -35,26 +23,14 @@
             "strophe.roster",
             "strophe.roster",
             "strophe.vcard",
             "strophe.vcard",
             "strophe.disco"
             "strophe.disco"
-        ];
-        try {
-            define("converse", [
-                "crypto",
-                "otr",
-                "locales",
-                "backbone.localStorage",
-                "jquery.tinysort",
-                "strophe",
-                "strophe.muc",
-                "strophe.roster",
-                "strophe.vcard",
-                "strophe.disco"
-            ], on_load);
-        } catch (e) {
-            console.log(e);
-            // Don't load crypto stuff if the browser doesn't have a CSRNG
-            dependencies.splice(0, 2);
-            define("converse", dependencies, on_load);
-        }
+        ], function(CryptoJS, otr) {
+            // Use Mustache style syntax for variable interpolation
+            _.templateSettings = {
+                evaluate : /\{\[([\s\S]+?)\]\}/g,
+                interpolate : /\{\{([\s\S]+?)\}\}/g
+            };
+            return factory(jQuery, _, CryptoJS, otr.OTR, otr.DSA, console);
+        });
     } else {
     } else {
         // Browser globals
         // Browser globals
         _.templateSettings = {
         _.templateSettings = {
@@ -77,11 +53,10 @@
         var KEY = {
         var KEY = {
             ENTER: 13
             ENTER: 13
         };
         };
-        var HAS_CRYPTO = (
-            (typeof CryptoJS !== "undefined") &&
-            (typeof OTR !== "undefined") &&
-            (typeof DSA !== "undefined")
-        );
+        var HAS_CSPRNG = ((typeof crypto === 'undefined') || (
+            (typeof crypto.randomBytes !== 'function') &&
+            (typeof crypto.getRandomValues !== 'function')
+        ));
 
 
         // Default configuration values
         // Default configuration values
         // ----------------------------
         // ----------------------------
@@ -134,7 +109,7 @@
         ]));
         ]));
 
 
         // Only allow OTR if we have the capability
         // Only allow OTR if we have the capability
-        this.allow_otr = this.allow_otr && HAS_CRYPTO;
+        this.allow_otr = this.allow_otr && HAS_CSPRNG;
 
 
         // Translation machinery
         // Translation machinery
         // ---------------------
         // ---------------------