Commit 67c99f60 authored by JC Brand's avatar JC Brand

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

Add check HAS_CSPRNG instead of the previous check
parent 518c0fca
...@@ -12,19 +12,7 @@ ...@@ -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) { define("converse", [
// 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 = [
"crypto", "crypto",
"otr", "otr",
"locales", "locales",
...@@ -35,26 +23,14 @@ ...@@ -35,26 +23,14 @@
"strophe.roster", "strophe.roster",
"strophe.vcard", "strophe.vcard",
"strophe.disco" "strophe.disco"
]; ], function(CryptoJS, otr) {
try { // Use Mustache style syntax for variable interpolation
define("converse", [ _.templateSettings = {
"crypto", evaluate : /\{\[([\s\S]+?)\]\}/g,
"otr", interpolate : /\{\{([\s\S]+?)\}\}/g
"locales", };
"backbone.localStorage", return factory(jQuery, _, CryptoJS, otr.OTR, otr.DSA, console);
"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);
}
} else { } else {
// Browser globals // Browser globals
_.templateSettings = { _.templateSettings = {
...@@ -77,11 +53,10 @@ ...@@ -77,11 +53,10 @@
var KEY = { var KEY = {
ENTER: 13 ENTER: 13
}; };
var HAS_CRYPTO = ( var HAS_CSPRNG = ((typeof crypto === 'undefined') || (
(typeof CryptoJS !== "undefined") && (typeof crypto.randomBytes !== 'function') &&
(typeof OTR !== "undefined") && (typeof crypto.getRandomValues !== 'function')
(typeof DSA !== "undefined") ));
);
// Default configuration values // Default configuration values
// ---------------------------- // ----------------------------
...@@ -134,7 +109,7 @@ ...@@ -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
// --------------------- // ---------------------
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment