From 1bf807bf33b2a407e4d8a3f9785b522b5d384913 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Mon, 12 Dec 2016 16:52:03 +0000 Subject: Better handling of exceptions during loading If we get an exception during load, don't define half of window.Olm (which confuses apps). This is a partial fix to https://github.com/vector-im/riot-web/issues/2726. --- javascript/olm_post.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'javascript/olm_post.js') diff --git a/javascript/olm_post.js b/javascript/olm_post.js index 8951c11..54e42c5 100644 --- a/javascript/olm_post.js +++ b/javascript/olm_post.js @@ -419,4 +419,22 @@ olm_exports["get_library_version"] = restore_stack(function() { getValue(buf+2, 'i8'), ]; }); -}(); + +})(); + +// export the olm functions into the environment. +// +// make sure that we do this *after* populating olm_exports, so that we don't +// get a half-built window.Olm if there is an exception. + +if (typeof module !== 'undefined' && module.exports) { + // node / browserify + module.exports = olm_exports; +} + +if (typeof(window) !== 'undefined') { + // We've been imported directly into a browser. Define the global 'Olm' object. + // (we do this even if module.exports was defined, because it's useful to have + // Olm in the global scope for browserified and webpacked apps.) + window["Olm"] = olm_exports; +} -- cgit v1.2.3