Search code examples
javascriptwebassemblyspidermonkeyanyref

How can I enable references in WebAssembly with SpiderMonkey?


I try to use the experimental AnyRef in WebAssembly with the JavaScript engine SpiderMonkey. I receive the follow error:

CompileError: wasm validation error: at offset 40: reference types not enabled

I try to enable it with the command line parameter --wasm-gc but without luck. Any idea how I can do it?

I call it like:

js --wasm-gc test.js

Solution

  • Using anyref is a little tricky at the moment because the feature is in an inbetween state; it'll "just work" once we land some of the missing pieces.

    Currently you need not only the command line switch but also an explicit opt-in in the module itself.

    In the text mode (if you're using the built-in wasmTextToBinary function in the SpiderMonkey shell) you must have a custom section at the beginning of the module that looks like this:

    (gc_feature_opt_in 1)

    If you're generating binary code, the encoding is documented here: https://github.com/lars-t-hansen/moz-gc-experiments/blob/master/version1.md