Skip to content

Commit 23795ba

Browse files
committed
fix(wasm): preserve global ordering
1 parent bfdb769 commit 23795ba

File tree

5 files changed

+30
-0
lines changed

5 files changed

+30
-0
lines changed

lib/wasm/WebAssemblyGenerator.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,13 @@ const rewriteImportedGlobals = state => bin => {
207207

208208
path.remove();
209209
}
210+
},
211+
212+
// in order to preserve non-imported global's order we need to re-inject
213+
// those as well
214+
Global(path) {
215+
newGlobals.push(path.node);
216+
path.remove();
210217
}
211218
});
212219

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const a = 1;
2+
export const b = 2;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
it("should preserve the ordering of globals", function() {
2+
return import("./module.wat").then(function(e) {
3+
expect(e.c).toBe(3);
4+
expect(e.d).toBe(4);
5+
});
6+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
(module
2+
(import "./env.js" "a" (global i32))
3+
(import "./env.js" "b" (global i32))
4+
5+
(global $c i32 (i32.const 3))
6+
(global $d i32 (i32.const 4))
7+
8+
(export "c" (global $c))
9+
(export "d" (global $d))
10+
)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
var supportsWebAssembly = require("../../../helpers/supportsWebAssembly");
2+
3+
module.exports = function(config) {
4+
return supportsWebAssembly();
5+
};

0 commit comments

Comments
 (0)