Closed Aincvy closed 2 years ago
Hi,
to_v8()
works as expected:
std::string
and std::string_view
have a known length and are converted to JavaScript Stringconst char*
is treated as a null terminated string literal and converted via std::string_view
to JS Stringchar array[N]
is a fixed size array and treated as as a string literal of fixed wellknown length N and converted to JS StringYou can use the 2nd argument of to_v8(str, len)
to specify the desired string length for such a fixed size arrays.
Here is some code.
The stmt
v8pp::to_v8(isolate, item.value.string))
will call this function.Then my string has a lot of
0
, and those 0 will be a part of a string. Here is some log.The (last line of log)'s code is:
When I change the code to
functionObject->Set(context, v8pp::to_v8(isolate, "value"), v8pp::to_v8(isolate, (const char*) item.value.string));
. It works fine, those0
are gone.I use
char[]
as a string buffer.I don't know this is a design or not.