summaryrefslogtreecommitdiff
path: root/test/binaryen.js/global.js
diff options
context:
space:
mode:
Diffstat (limited to 'test/binaryen.js/global.js')
-rw-r--r--test/binaryen.js/global.js42
1 files changed, 23 insertions, 19 deletions
diff --git a/test/binaryen.js/global.js b/test/binaryen.js/global.js
index 562de7360..48571ef93 100644
--- a/test/binaryen.js/global.js
+++ b/test/binaryen.js/global.js
@@ -12,30 +12,34 @@ function cleanInfo(info) {
return ret;
}
-var module = new Binaryen.Module();
-module.setFeatures(Binaryen.Features.MVP | Binaryen.Features.MutableGlobals);
+function test() {
+ var module = new Binaryen.Module();
+ module.setFeatures(Binaryen.Features.MVP | Binaryen.Features.MutableGlobals);
-var initExpr = module.i32.const(1);
-var global = module.addGlobal("a-global", Binaryen.i32, false, initExpr);
+ var initExpr = module.i32.const(1);
+ var global = module.addGlobal("a-global", Binaryen.i32, false, initExpr);
-console.log("GetGlobal is equal: " + (global === module.getGlobal("a-global")));
+ console.log("GetGlobal is equal: " + (global === module.getGlobal("a-global")));
-var globalInfo = Binaryen.getGlobalInfo(global);
-console.log("getGlobalInfo=" + JSON.stringify(cleanInfo(globalInfo)));
+ var globalInfo = Binaryen.getGlobalInfo(global);
+ console.log("getGlobalInfo=" + JSON.stringify(cleanInfo(globalInfo)));
-var initExpInfo = Binaryen.getExpressionInfo(globalInfo.init);
-console.log("getExpressionInfo(init)=" + JSON.stringify(cleanInfo(initExpInfo)));
-console.log(Binaryen.emitText(globalInfo.init));
+ var initExpInfo = Binaryen.getExpressionInfo(globalInfo.init);
+ console.log("getExpressionInfo(init)=" + JSON.stringify(cleanInfo(initExpInfo)));
+ console.log(Binaryen.emitText(globalInfo.init));
-module.addGlobalExport("a-global", "a-global-exp");
-module.addGlobalImport("a-global-imp", "module", "base", Binaryen.i32, false);
-module.addGlobalImport("a-mut-global-imp", "module", "base", Binaryen.i32, true);
+ module.addGlobalExport("a-global", "a-global-exp");
+ module.addGlobalImport("a-global-imp", "module", "base", Binaryen.i32, false);
+ module.addGlobalImport("a-mut-global-imp", "module", "base", Binaryen.i32, true);
-assert(module.validate());
-console.log(module.emitText());
+ assert(module.validate());
+ console.log(module.emitText());
-module.removeGlobal("a-global");
-module.removeExport("a-global-exp");
+ module.removeGlobal("a-global");
+ module.removeExport("a-global-exp");
-assert(module.validate());
-console.log(module.emitText());
+ assert(module.validate());
+ console.log(module.emitText());
+}
+
+Binaryen.ready.then(test);