jsNewString function
Implementation
Pointer<JSValue> jsNewString(Pointer<JSContext> ctx, String str) {
// Pass the byte length explicitly: the string may contain U+0000.
final bytes = utf8.encode(str);
final utf8str = malloc<Uint8>(bytes.length + 1);
utf8str.asTypedList(bytes.length).setAll(0, bytes);
final jsStr = _jsNewString(ctx, utf8str, bytes.length);
malloc.free(utf8str);
return jsStr;
}