From dcebe8cd374d149dd9d870f77967554b0d1f3802 Mon Sep 17 00:00:00 2001 From: Mike Armstrong Date: Tue, 8 Dec 2015 01:35:57 -0800 Subject: [PATCH] Use ascii characters to construct JSStringRef Reviewed By: astreet Differential Revision: D2700781 fb-gh-sync-id: be790600ea3d4c0238553efe69a0979c177ddb2d --- ReactAndroid/src/main/jni/react/JSCExecutor.cpp | 3 +-- ReactAndroid/src/main/jni/react/Value.h | 11 +++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/ReactAndroid/src/main/jni/react/JSCExecutor.cpp b/ReactAndroid/src/main/jni/react/JSCExecutor.cpp index 93bb17fba..5f23c2b88 100644 --- a/ReactAndroid/src/main/jni/react/JSCExecutor.cpp +++ b/ReactAndroid/src/main/jni/react/JSCExecutor.cpp @@ -117,9 +117,8 @@ void JSCExecutor::executeApplicationScript( jstring endStringMarker = env->NewStringUTF("executeApplicationScript_endStringConvert"); env->CallStaticVoidMethod(markerClass, logMarkerMethod, startStringMarker); - String jsScript(script.c_str()); + String jsScript = String::createExpectingAscii(script); env->CallStaticVoidMethod(markerClass, logMarkerMethod, endStringMarker); - env->DeleteLocalRef(startStringMarker); env->DeleteLocalRef(endStringMarker); diff --git a/ReactAndroid/src/main/jni/react/Value.h b/ReactAndroid/src/main/jni/react/Value.h index bb10f9a85..b39bdef30 100644 --- a/ReactAndroid/src/main/jni/react/Value.h +++ b/ReactAndroid/src/main/jni/react/Value.h @@ -8,6 +8,9 @@ #include #include #include +#if WITH_FBJSCEXTENSIONS +#include +#endif namespace facebook { namespace react { @@ -53,6 +56,14 @@ public: return JSStringIsEqualToUTF8CString(m_string.get(), utf8); } + static String createExpectingAscii(std::string const &utf8) { + #if WITH_FBJSCEXTENSIONS + return String(Adopt, JSStringCreateWithUTF8CStringExpectAscii(utf8.c_str(), utf8.size())); + #else + return String(Adopt, JSStringCreateWithUTF8CString(utf8.c_str())); + #endif + } + static String ref(JSStringRef string) { return String(string); }