summaryrefslogtreecommitdiff
path: root/test/wasm2js
diff options
context:
space:
mode:
authormagic-akari <akari.ccino@gmail.com>2022-03-18 01:27:28 +0800
committerGitHub <noreply@github.com>2022-03-17 17:27:28 +0000
commitb7e1989553a645968399ad379a86b809e04c0ae2 (patch)
tree714472a3d156ad55f1a8ba1618426426b7295433 /test/wasm2js
parent86acb00c7095017f8bded15def3c928909099731 (diff)
downloadbinaryen-b7e1989553a645968399ad379a86b809e04c0ae2.tar.gz
binaryen-b7e1989553a645968399ad379a86b809e04c0ae2.tar.bz2
binaryen-b7e1989553a645968399ad379a86b809e04c0ae2.zip
[wasm2js] Support exports of Globals (#4523)
Export an object with a `.value` property like the wasm JS API does in browsers, and implement them with a getter and setter. Fixes #4522
Diffstat (limited to 'test/wasm2js')
-rw-r--r--test/wasm2js/export_global.2asm.js37
-rw-r--r--test/wasm2js/export_global.2asm.js.opt37
-rw-r--r--test/wasm2js/export_global.wast6
3 files changed, 80 insertions, 0 deletions
diff --git a/test/wasm2js/export_global.2asm.js b/test/wasm2js/export_global.2asm.js
new file mode 100644
index 000000000..7db0d3a20
--- /dev/null
+++ b/test/wasm2js/export_global.2asm.js
@@ -0,0 +1,37 @@
+
+function asmFunc(env) {
+ var Math_imul = Math.imul;
+ var Math_fround = Math.fround;
+ var Math_abs = Math.abs;
+ var Math_clz32 = Math.clz32;
+ var Math_min = Math.min;
+ var Math_max = Math.max;
+ var Math_floor = Math.floor;
+ var Math_ceil = Math.ceil;
+ var Math_trunc = Math.trunc;
+ var Math_sqrt = Math.sqrt;
+ var abort = env.abort;
+ var nan = NaN;
+ var infinity = Infinity;
+ var global0 = 655360;
+ function $0() {
+ return 42 | 0;
+ }
+
+ return {
+ "HELLO": {
+ get value() {
+ return global0;
+ },
+ set value(_global0) {
+ global0 = _global0;
+ }
+ },
+ "helloWorld": $0
+ };
+}
+
+var retasmFunc = asmFunc( { abort: function() { throw new Error('abort'); }
+ });
+export var HELLO = retasmFunc.HELLO;
+export var helloWorld = retasmFunc.helloWorld;
diff --git a/test/wasm2js/export_global.2asm.js.opt b/test/wasm2js/export_global.2asm.js.opt
new file mode 100644
index 000000000..eb4e88090
--- /dev/null
+++ b/test/wasm2js/export_global.2asm.js.opt
@@ -0,0 +1,37 @@
+
+function asmFunc(env) {
+ var Math_imul = Math.imul;
+ var Math_fround = Math.fround;
+ var Math_abs = Math.abs;
+ var Math_clz32 = Math.clz32;
+ var Math_min = Math.min;
+ var Math_max = Math.max;
+ var Math_floor = Math.floor;
+ var Math_ceil = Math.ceil;
+ var Math_trunc = Math.trunc;
+ var Math_sqrt = Math.sqrt;
+ var abort = env.abort;
+ var nan = NaN;
+ var infinity = Infinity;
+ var global0 = 655360;
+ function $0() {
+ return 42;
+ }
+
+ return {
+ "HELLO": {
+ get value() {
+ return global0;
+ },
+ set value(_global0) {
+ global0 = _global0;
+ }
+ },
+ "helloWorld": $0
+ };
+}
+
+var retasmFunc = asmFunc( { abort: function() { throw new Error('abort'); }
+ });
+export var HELLO = retasmFunc.HELLO;
+export var helloWorld = retasmFunc.helloWorld;
diff --git a/test/wasm2js/export_global.wast b/test/wasm2js/export_global.wast
new file mode 100644
index 000000000..9b990be8d
--- /dev/null
+++ b/test/wasm2js/export_global.wast
@@ -0,0 +1,6 @@
+(module
+ (global $global0 i32 (i32.const 655360))
+ (export "HELLO" (global $global0))
+ (func (result i32) (i32.const 42))
+ (export "helloWorld" (func 0))
+) \ No newline at end of file