Island WebAssembly SignatureMismatch exception dependent on variable presence in code

webassembly
island

(Marko Zubin) #1

IDE: Water
Version: 10.0.0.2351
Target (If relevant): Island (WebAssembly)
Description:
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.

Steps:
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:

@Export
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() {
        writeLn("HelloWorld")
    }
}

the code in my index.html file:

<html>
    <head>
        <title>WebAsmSilverError Test Page</title>
        <script lang="javascript" src="wasm/RemObjectsElements.js"></script>
        <script lang="javascript" src="wasm/WebAsmSilverError.js"></script>
    </head>
    <body>
    <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.HelloWorld();
            //program.ButtonCall(); //uncommenting this also deactivates the bug
        });
    </script>
    
    <button onclick="program.ButtonCall()">click me</button>
    </body>
</html>

(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!