On Sep 3, 10:31 am, Bret Taylor <
btay...@gmail.com> wrote:
> I am exploring the V8 code base for the first time and making a few
> embedding demos to become more familiar. I was in the process of
> wrapping some system calls and calling them from JavaScript, and I was
> curious what the best way to pass binary strings to and from
> JavaScript is (and if it is possible).
Right now there's no simple way to do that for 8 bit data.
The String::New(const char* data, int length) method will 'mangle'
bytes over 127 (ie interpret them as UTF-8 if possible).
The String::New(const uint16_t* data, int length) method doesn't
mangle anything, but it only takes an even number of bytes and if the
binary input data contains any 8 bit characters then the characters in
the string will bear little relation to those in the original data.
If your data is binary and not really a string then perhaps you should
be storing it in an array instead of in a string. If you do that then
note that integers that can be represented in 31 bits or fewer (8, 16
or 24 for example) are more efficient in V8 than full blown signed 32
bit integers, which require a separate Number object to represent the
numbers in half the range.