Skip to content

Commit 22e55d4

Browse files
dcaspiFacebook Github Bot 9
authored andcommitted
Adding Pre-PArsing cache & StringRef to iOS 8's JSC
Reviewed By: michalgr Differential Revision: D3066370 fb-gh-sync-id: 2dabffbd41d4f4f9f2a9ddaca3224ba00498821e shipit-source-id: 2dabffbd41d4f4f9f2a9ddaca3224ba00498821e
1 parent 60b2398 commit 22e55d4

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

ReactAndroid/src/main/jni/react/JSCExecutor.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,19 +205,37 @@ void JSCExecutor::terminateOnJSVMThread() {
205205
m_context = nullptr;
206206
}
207207

208+
// Checks if the user is in the pre-parsing cache & StringRef QE.
209+
// Should be removed when these features are no longer gated.
210+
bool JSCExecutor::usePreparsingAndStringRef(){
211+
return m_jscConfig.getDefault("PreparsingStringRef", true).getBool();
212+
}
213+
208214
void JSCExecutor::loadApplicationScript(
209215
const std::string& script,
210216
const std::string& sourceURL) {
211217
ReactMarker::logMarker("loadApplicationScript_startStringConvert");
218+
#if WITH_FBJSCEXTENSIONS
219+
JSStringRef jsScriptRef;
220+
if (usePreparsingAndStringRef()){
221+
jsScriptRef = JSStringCreateWithUTF8CStringExpectAscii(script.c_str(), script.size());
222+
} else {
223+
jsScriptRef = JSStringCreateWithUTF8CString(script.c_str());
224+
}
225+
226+
String jsScript = String::adopt(jsScriptRef);
227+
#else
212228
String jsScript = String::createExpectingAscii(script);
229+
#endif
230+
213231
ReactMarker::logMarker("loadApplicationScript_endStringConvert");
214232

215233
String jsSourceURL(sourceURL.c_str());
216234
#ifdef WITH_FBSYSTRACE
217235
FbSystraceSection s(TRACE_TAG_REACT_CXX_BRIDGE, "JSCExecutor::loadApplicationScript",
218236
"sourceURL", sourceURL);
219237
#endif
220-
if (!jsSourceURL) {
238+
if (!jsSourceURL || !usePreparsingAndStringRef()) {
221239
evaluateScript(m_context, jsScript, jsSourceURL);
222240
} else {
223241
// If we're evaluating a script, get the device's cache dir

ReactAndroid/src/main/jni/react/JSCExecutor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ class JSCExecutor : public JSExecutor {
113113
void receiveMessageFromOwner(const std::string &msgString);
114114
void terminateOwnedWebWorker(int worker);
115115
Object createMessageObject(const std::string& msgData);
116+
bool usePreparsingAndStringRef();
116117

117118
static JSValueRef nativeStartWorker(
118119
JSContextRef ctx,

ReactAndroid/src/main/jni/react/JSCHelpers.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ JSValueRef makeJSCException(
3838
JSValueRef evaluateScript(JSContextRef context, JSStringRef script, JSStringRef source, const char *cachePath) {
3939
JSValueRef exn, result;
4040
#if WITH_FBJSCEXTENSIONS
41-
if (source){
41+
// Only evaluate the script using pre-parsing cache if the script comes from
42+
// a bundle file and a cache path is given.
43+
if (source && cachePath){
4244
// If evaluating an application script, send it through `JSEvaluateScriptWithCache()`
4345
// to add cache support.
4446
result = JSEvaluateScriptWithCache(context, script, NULL, source, 0, &exn, cachePath);

0 commit comments

Comments
 (0)