[webkit-help] Pushing binary data into a string (JSStringCreateWithCharacters, JSStringCreateWithUTF8CString)
Eric Wing
ewmailing at gmail.com
Fri Jun 5 05:39:46 PDT 2015
I am using JavaScriptCore in an embedded application situation. I am
writing a binding between libcurl and JavaScriptCore.
Curl callbacks for data give back a char* buffer, which may be a
string or binary data. I want to push this data directly into
JavaScript as a string because I thought it would be easiest for
handling and the usually the typical usage is a non-binary string. And
my understanding is Javascript strings themselves can hold any kind of
data and don't suffer from the C terminator problem.
Since I have a char* buffer, JSStringCreateWithUTF8CString() has the
right type signature, but it assumes null termination and there isn't
a variation with an explicit size parameter. This is problematic if
either there is no NULL terminator or there are 0's in the data
stream.
JSStringCreateWithCharacters has a parameter for the number of
characters, but it uses a JSChar* instead of char*. I don't know how
to convert.
Is there a way I can get this through the bridge correctly?
Thanks,
Eric
P.S. For my callback bindings, I found the API
JSContextGetGlobalContext() invaluable. I found an old archived thread
suggesting it might be officially moved to public API. If it has not
already been moved, I would really like encourage this.
More information about the webkit-help
mailing list