10 Jul 2020
??? J2V8 Supports 16bit Characters
Comments
When J2V8 was first released, all Java characters passed between Java and V8 were converted to 8bit C-Style strings. For many applications this was just fine, but if your JavaScript contained 16 bit Unicode characters, then you were hosed.
When you use the word "hosed" to mean broken, you're probably Canadian.
— Wayne Beaton (@waynebeaton) July 25, 2016
With J2V8 4 this has been fixed. All strings are now referencedย asย uint16_t in C++. Using the JNI API we were able to get the 2 byte string using:
const uint16_t* unicodeString = env->GetStringChars(string, NULL);
and create the V8 String object using String::NewFromTwoByte().Now you can execute JavaScript, or access JS properties, that contain 16 bit characters such as:
For more J2V8 Tips and Tricks, follow me on Twitter.