diff --git a/src/passes/RemoveNonJSOps.cpp b/src/passes/RemoveNonJSOps.cpp index 90116f8f3c3..8af0d1070ee 100644 --- a/src/passes/RemoveNonJSOps.cpp +++ b/src/passes/RemoveNonJSOps.cpp @@ -337,11 +337,6 @@ struct RemoveNonJSOpsPass : public WalkerPass> { struct StubUnsupportedJSOpsPass : public WalkerPass> { - bool isFunctionParallel() override { return true; } - - std::unique_ptr create() override { - return std::make_unique(); - } void visitUnary(Unary* curr) { switch (curr->op) { @@ -386,6 +381,21 @@ struct StubUnsupportedJSOpsPass } replaceCurrent(replacement); } + + void visitModule(Module* module) { + // We remove global exports, as wasm2js doesn't emit them in a fully + // compatible form yet (they aren't instances of WebAssembly.Global). + // Globals. + std::vector badExports; + for (auto& exp : module->exports) { + if (exp->kind == ExternalKind::Global) { + badExports.push_back(exp->name); + } + } + for (auto name : badExports) { + module->removeExport(name); + } + } }; Pass* createRemoveNonJSOpsPass() { return new RemoveNonJSOpsPass(); } diff --git a/test/lit/passes/stub-unsupported-js-globals.wast b/test/lit/passes/stub-unsupported-js-globals.wast new file mode 100644 index 00000000000..a2ac2b8e578 --- /dev/null +++ b/test/lit/passes/stub-unsupported-js-globals.wast @@ -0,0 +1,30 @@ +;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited. + +;; RUN: foreach %s %t wasm-opt -all --stub-unsupported-js -S -o - | filecheck %s + +;; We should remove global exports, as wasm2js doesn't emit them in a fully +;; compatible form yet (they aren't instances of WebAssembly.Global). All the +;; global exports below should vanish, but not the function export. + +(module + ;; CHECK: (type $0 (func)) + + ;; CHECK: (global $i32 i32 (i32.const 42)) + (global $i32 i32 (i32.const 42)) + + ;; CHECK: (global $v128 v128 (v128.const i32x4 0x00000000 0x00000000 0x00000000 0x00000000)) + (global $v128 v128 (v128.const i32x4 0x00000000 0x00000000 0x00000000 0x00000000)) + + (export "bad1" (global $v128)) + + (export "bad2" (global $i32)) + + ;; CHECK: (export "good" (func $func)) + (export "good" (func $func)) + + ;; CHECK: (func $func (type $0) + ;; CHECK-NEXT: ) + (func $func + ) +) +