Island WebAssembly SignatureMismatch exception dependent on variable presence in code


(Marko Zubin) #1

IDE: Water
Target (If relevant): Island (WebAssembly)
An exception is thrown when calling a function from javascript to webassembly, but only under certain conditions.

Expected Behavior:
When I call the function it should work.

Actual Behavior:
When I call the function both firefox and chrome show an exception.

Create a new Island (webassembly) project. I’m using silver if it’s important.
I’ll include the code below but first I’ll explain how to reproduce the error. (there are two ways)

So the code (as it is written in the example) will work as expected. When it loads it prints “HelloWorld” and then when the user presses the button it prints “Button pressed”. No bugs so far.

Now to recreate the bug just uncomment the let a = “something” line. Rebuild. It will print the “HelloWorld” line but when you press the button it will raise an exception.

This appears to be happening if a function is at the top of the class and there is a variable underneath it. This can be further shown by uncommenting the let b = “12345” line. Rebuild. And everything will work normally.

Another way to “avoid” the bug is to uncomment the “program.ButtonCall();” line in the html. So that it gets called immediately after program.HelloWorld();
If this is done the button can later be pressed and will work normally. (but of course it will also get called buring initialization)

the code in my Program.swift file:

public class Program {
    //let b = "12345" //uncommenting this deactivates the bug

    public func ButtonCall() {
        writeLn("Button pressed")
    //let a = "something" //uncommenting this activates the bug
    public func HelloWorld() {

the code in my index.html file:

        <title>WebAsmSilverError Test Page</title>
        <script lang="javascript" src="wasm/RemObjectsElements.js"></script>
        <script lang="javascript" src="wasm/WebAsmSilverError.js"></script>
    <h1>WebAsmSilverError Test Page</h1>
    <div id="helloWorld"/>
    <script lang="javascript">
        var program;
        WebAsmSilverError.instantiate("wasm/WebAsmSilverError.wasm").then(function (result) {
            console.log("WebAssembly file WebAsmSilverError.wasm has been loaded.");
            program = result.Program();
            //program.ButtonCall(); //uncommenting this also deactivates the bug
    <button onclick="program.ButtonCall()">click me</button>

(RemObjects) #2

Thanks, logged as bugs://81794

(RemObjects) #3

bugs://81794 got closed with status fixed.

(Carlo Kok) #4

Wow this was a nasty one. If you need a fix for this right away, you can apply this change:

to your local changes. Else fridays build will also have it.

Thanks for the report!