summaryrefslogtreecommitdiff
path: root/src/js
diff options
context:
space:
mode:
authorDaniel Wirtz <dcode@dcode.io>2017-07-05 22:28:44 +0200
committerAlon Zakai <alonzakai@gmail.com>2017-07-05 13:28:44 -0700
commit2d289c32cc66c8c289f0b5285d26d4c4240c5ecd (patch)
treef8d0f78584ab49f27a84607d8b1645fe490ae0b0 /src/js
parentd1ccc3d33adb191e6728cd136ef6596d98e2a716 (diff)
downloadbinaryen-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.js41
-rw-r--r--src/js/binaryen.js-pre.js3
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";