Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions src/passes/RemoveNonJSOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,11 +337,6 @@ struct RemoveNonJSOpsPass : public WalkerPass<PostWalker<RemoveNonJSOpsPass>> {

struct StubUnsupportedJSOpsPass
: public WalkerPass<PostWalker<StubUnsupportedJSOpsPass>> {
bool isFunctionParallel() override { return true; }

std::unique_ptr<Pass> create() override {
return std::make_unique<StubUnsupportedJSOpsPass>();
}

void visitUnary(Unary* curr) {
switch (curr->op) {
Expand Down Expand Up @@ -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<Name> 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(); }
Expand Down
30 changes: 30 additions & 0 deletions test/lit/passes/stub-unsupported-js-globals.wast
Original file line number Diff line number Diff line change
@@ -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
)
)

Loading