In genericjs functions: comparing std::string_view with string litteral causes exception
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".
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
Sure thing, will do asap.
[[cheerp::genericjs]]
bool test(std::string_view str) {
return str == "Hello world";
}
Thanks @niasa, I am looking into the issue
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.