cheerp-meta icon indicating copy to clipboard operation
cheerp-meta copied to clipboard

In genericjs functions: comparing std::string_view with string litteral causes exception

Open niansa opened this issue 4 years ago • 4 comments

Take this code for example:

[[cheerp::genericjs]]
inline void setElemAttr(std::string_view id, std::string_view key, std::string_view value) {
    // Find element
    auto elem = client::document.getElementById(toJsStr(id));
    if (elem) {
        log("Elem EXISTS: "+std::string(id)+" ("+toStdStr(elem->get_innerHTML())+')');
    }
    // Set attribute
    if (key == "innerHtml") {
        elem->set_innerHTML(toJsStr(value));
    } else if (key == "text") {
        elem->set_textContent(toJsStr(value));
    } else if (key == "value") {
        static_cast<client::HTMLInputElement*>(elem)->set_value((toJsStr(value)));
    } else {
        elem->set_(toJsStr(key), toJsStr(value));
    }
}

It's called from WASM code and crashes as std::string_view is compared with "innerHtml".

niansa avatar Jul 13 '21 14:07 niansa

Hi @niansa, can you provide a minimal reproducible testcase (eg. something like a main calling setElemAttr and causing the error). I don't see anything obviously wrong, and would like to know we are seeing the same issue.

Bests, Carlo

carlopi avatar Jul 13 '21 15:07 carlopi

Sure thing, will do asap.

niansa avatar Jul 14 '21 08:07 niansa

[[cheerp::genericjs]]
bool test(std::string_view str) {
    return str == "Hello world";
}

niansa avatar Nov 26 '21 04:11 niansa

Thanks @niasa, I am looking into the issue

carlopi avatar Dec 01 '21 08:12 carlopi

There isn't a full test case, so I just tested string_view comparison with char* in genericjs, and I can't reproduce this issue with Cheerp 3.0, so I am closing.

Feel free to reopen if it's still happening with the latest version on your actual use case.

yuri91 avatar Mar 14 '23 11:03 yuri91