Skip to content

Commit

Permalink
fix(wasm): preserve global ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
xtuc committed May 29, 2018
1 parent bfdb769 commit 23795ba
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/wasm/WebAssemblyGenerator.js
Expand Up @@ -207,6 +207,13 @@ const rewriteImportedGlobals = state => bin => {

path.remove();
}
},

// in order to preserve non-imported global's order we need to re-inject
// those as well
Global(path) {
newGlobals.push(path.node);
path.remove();
}
});

Expand Down
2 changes: 2 additions & 0 deletions test/cases/wasm/imported-global-preserve-ordering/env.js
@@ -0,0 +1,2 @@
export const a = 1;
export const b = 2;
6 changes: 6 additions & 0 deletions test/cases/wasm/imported-global-preserve-ordering/index.js
@@ -0,0 +1,6 @@
it("should preserve the ordering of globals", function() {
return import("./module.wat").then(function(e) {
expect(e.c).toBe(3);
expect(e.d).toBe(4);
});
});
10 changes: 10 additions & 0 deletions test/cases/wasm/imported-global-preserve-ordering/module.wat
@@ -0,0 +1,10 @@
(module
(import "./env.js" "a" (global i32))
(import "./env.js" "b" (global i32))

(global $c i32 (i32.const 3))
(global $d i32 (i32.const 4))

(export "c" (global $c))
(export "d" (global $d))
)
@@ -0,0 +1,5 @@
var supportsWebAssembly = require("../../../helpers/supportsWebAssembly");

module.exports = function(config) {
return supportsWebAssembly();
};

0 comments on commit 23795ba

Please sign in to comment.