aboutsummaryrefslogtreecommitdiff
path: root/javascript/olm_pre.js
diff options
context:
space:
mode:
authorRichard van der Hoff <github@rvanderhoff.org.uk>2016-12-14 14:34:39 +0000
committerGitHub <noreply@github.com>2016-12-14 14:34:39 +0000
commit2e04868c468ba4d0362a209f8f261df649598a07 (patch)
tree9a3a2f60fed411f9e6fca867691fa63a1db39d79 /javascript/olm_pre.js
parentf6c05be8c5d35e725a8a2ed5ad661398ac9f8cd2 (diff)
parent51b141ecb6b473dd4fd8425ca08f8dbc590a01c0 (diff)
Merge pull request #38 from matrix-org/rav/handle_load_exceptions
Better handling of exceptions during loading, and import OLM_OPTIONS
Diffstat (limited to 'javascript/olm_pre.js')
-rw-r--r--javascript/olm_pre.js30
1 files changed, 15 insertions, 15 deletions
diff --git a/javascript/olm_pre.js b/javascript/olm_pre.js
index 50bf8c2..ae7aba5 100644
--- a/javascript/olm_pre.js
+++ b/javascript/olm_pre.js
@@ -2,32 +2,32 @@ var olm_exports = {};
var get_random_values;
var process; // Shadow the process object so that emscripten won't get
// confused by browserify
-if (typeof(global) !== 'undefined' && global["window"]) {
- // We're running with browserify
- module["exports"] = olm_exports;
- global["window"]["Olm"] = olm_exports;
- get_random_values = function(buf) {
- window.crypto.getRandomValues(buf);
- };
-} else if (typeof(window) !== 'undefined') {
- // We've been imported directly into a browser.
- window["Olm"] = olm_exports;
+
+if (typeof(window) !== 'undefined') {
+ // We've in a browser (directly, via browserify, or via webpack).
get_random_values = function(buf) {
window.crypto.getRandomValues(buf);
};
} else if (module["exports"]) {
// We're running in node.
- module["exports"] = olm_exports;
var nodeCrypto = require("crypto");
get_random_values = function(buf) {
var bytes = nodeCrypto.randomBytes(buf.length);
buf.set(bytes);
- }
+ };
process = global["process"];
} else {
throw new Error("Cannot find global to attach library to");
}
-var init = function() {
- var module; // Shadow the Node 'module' object so that emscripten won't try
- // to fiddle with it.
+(function() {
+ /* applications should define OLM_OPTIONS in the environment to override
+ * emscripten module settings */
+ var Module = {};
+ if (typeof(OLM_OPTIONS) !== 'undefined') {
+ for (var key in OLM_OPTIONS) {
+ if (OLM_OPTIONS.hasOwnProperty(key)) {
+ Module[key] = OLM_OPTIONS[key];
+ }
+ }
+ }