diff options
author | Daniel Wirtz <dcode@dcode.io> | 2017-07-05 22:28:44 +0200 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2017-07-05 13:28:44 -0700 |
commit | 2d289c32cc66c8c289f0b5285d26d4c4240c5ecd (patch) | |
tree | f8d0f78584ab49f27a84607d8b1645fe490ae0b0 /src/js | |
parent | d1ccc3d33adb191e6728cd136ef6596d98e2a716 (diff) | |
download | binaryen-2d289c32cc66c8c289f0b5285d26d4c4240c5ecd.tar.gz binaryen-2d289c32cc66c8c289f0b5285d26d4c4240c5ecd.tar.bz2 binaryen-2d289c32cc66c8c289f0b5285d26d4c4240c5ecd.zip |
Unified module loader support in binaryen.js (#1074)
* Unified module loader support in binaryen.js
* Recompiled binaryen.js and wasm.js
Diffstat (limited to 'src/js')
-rw-r--r-- | src/js/binaryen.js-post.js | 41 | ||||
-rw-r--r-- | src/js/binaryen.js-pre.js | 3 |
2 files changed, 15 insertions, 29 deletions
diff --git a/src/js/binaryen.js-post.js b/src/js/binaryen.js-post.js index 9b2527fc5..cda00742c 100644 --- a/src/js/binaryen.js-post.js +++ b/src/js/binaryen.js-post.js @@ -911,34 +911,19 @@ return Module['_BinaryenSetAPITracing'](on); }; - return Module; -}; + // Support AMD-compatible loaders by defining a factory function that returns 'Module' + if (typeof define === "function" && define["amd"]) + define(function() { return Module; }); -if (typeof exports != 'undefined') { - (function(){ - var a = Binaryen(); - if (typeof module === 'object') { - module.exports = a; - } else { - for (var k in a) { - exports[k] = a[k]; - } - } - })(); -} -(typeof window !== 'undefined' ? window : - typeof global !== 'undefined' && ( - typeof process === 'undefined' || + // Support CommonJS-compatible loaders by checking for 'require' and 'module.exports' + else if (typeof require === "function" && typeof module !== "undefined" && module && module.exports) + module.exports = Module; - // Note: We must export "Binaryen" even inside a CommonJS/AMD/UMD module - // space because check.py generates a.js which requires Binaryen global var - ( process.argv && - Array.isArray(process.argv) && - process.argv[1] && - (process.argv[1].substr(-5) === '/a.js' || - process.argv[1].substr(-5) === '\\a.js') - ) + // Otherwise expose as 'Binaryen' globally checking for common names of the global object + // first (namely 'global' and 'window') and fall back to 'this' (i.e. within web workers). + else + (typeof global !== "undefined" && global || + typeof window !== "undefined" && window || + this)["Binaryen"] = Module; - ) ? global : - this -)['Binaryen'] = Binaryen(); +})();
\ No newline at end of file diff --git a/src/js/binaryen.js-pre.js b/src/js/binaryen.js-pre.js index aebb5326c..0f9293e16 100644 --- a/src/js/binaryen.js-pre.js +++ b/src/js/binaryen.js-pre.js @@ -1 +1,2 @@ -var Binaryen = function(Module) { +(function() { + "use strict"; |