skoppe / spasm

Write single page applications in D that compile to webassembly
MIT License
218 stars 17 forks source link

strings broken in v0.2.0-beta.7 #53

Closed WebFreak001 closed 4 years ago

WebFreak001 commented 4 years ago

I'm trying this simple example code:

import spasm.bindings;
import spasm.dom;
import spasm.types;

extern (C) export void _start()
{
    console.log("hello");
    auto elem = document.createElement("div").as!HTMLElement;
    elem.style.backgroundColor = "green";
    elem.innerHTML = "BLA BLA!";
    elem.addEventListener("mouseover",(event){
        console.log("onmouseover");
        console.log(event);
        console.log(event.as!MouseEvent.clientX);
        });

    import std.algorithm : move;
    auto root = document.querySelector("body").front.move;
    root.appendChild(elem);
}

but in the browser it first prints <empty string> and then crashes with InvalidCharacterError: String contains an invalid character (in the createElement I guess)

Tried LDC 1.20.1 and LDC 1.22.0

I also tried 0.1.13 but there I got the issue LinkError: import object field 'AbortController_signal_Get' is not a Function (or others)

skoppe commented 4 years ago

If this is from an existing project that got upgraded to the latest beta you may need to re-run dub run spasm:bootstrap-webpack. Recently memory handling has been upgraded and It seems the JS glue code is out-of-sync.

If this is a fresh project, or you did run the bootstrap again, there might be something bigger going on.

skoppe commented 4 years ago

Another possibility is that due to a dub run issue it might run an older bootstrap version, thus generating wrong files. When you run the command please make sure dub mentions the correct version of spasm.

WebFreak001 commented 4 years ago

this is a fresh project. Because I followed the instructions in the readme it first fetched the non-beta version of spasm and then because it didn't work out of the box (probably forgot the webidl thing) I tried the beta and at that point everything got mixed up, throwing all kinds of errors.

I have now deleted all spasm versions except 0.2.0-beta.7 from my dub folder. Now I did:

dub build --build=release --build-mode=allAtOnce
dub run spasm:webidl -- --bindgen
dub run spasm:bootstrap-webpack
dub run spasm:webidl -- --bindgen
npm install
npm run start

and now it seems to work

skoppe commented 4 years ago

Nice.

I wonder if I can get a version identifier in the glue code and check that on build or during run. Multiple people have hit their heads against this and it is far from robust.