From 22e55d4396499a5fe960f9d59210fc3fece3e55f Mon Sep 17 00:00:00 2001 From: Dan Caspi Date: Fri, 18 Mar 2016 12:20:13 -0700 Subject: [PATCH] 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 --- .../src/main/jni/react/JSCExecutor.cpp | 20 ++++++++++++++++++- ReactAndroid/src/main/jni/react/JSCExecutor.h | 1 + .../src/main/jni/react/JSCHelpers.cpp | 4 +++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/ReactAndroid/src/main/jni/react/JSCExecutor.cpp b/ReactAndroid/src/main/jni/react/JSCExecutor.cpp index a97a9ae6f82530..a4067aaef5a839 100644 --- a/ReactAndroid/src/main/jni/react/JSCExecutor.cpp +++ b/ReactAndroid/src/main/jni/react/JSCExecutor.cpp @@ -205,11 +205,29 @@ void JSCExecutor::terminateOnJSVMThread() { m_context = nullptr; } +// Checks if the user is in the pre-parsing cache & StringRef QE. +// Should be removed when these features are no longer gated. +bool JSCExecutor::usePreparsingAndStringRef(){ + return m_jscConfig.getDefault("PreparsingStringRef", true).getBool(); +} + void JSCExecutor::loadApplicationScript( const std::string& script, const std::string& sourceURL) { ReactMarker::logMarker("loadApplicationScript_startStringConvert"); +#if WITH_FBJSCEXTENSIONS + JSStringRef jsScriptRef; + if (usePreparsingAndStringRef()){ + jsScriptRef = JSStringCreateWithUTF8CStringExpectAscii(script.c_str(), script.size()); + } else { + jsScriptRef = JSStringCreateWithUTF8CString(script.c_str()); + } + + String jsScript = String::adopt(jsScriptRef); +#else String jsScript = String::createExpectingAscii(script); +#endif + ReactMarker::logMarker("loadApplicationScript_endStringConvert"); String jsSourceURL(sourceURL.c_str()); @@ -217,7 +235,7 @@ void JSCExecutor::loadApplicationScript( FbSystraceSection s(TRACE_TAG_REACT_CXX_BRIDGE, "JSCExecutor::loadApplicationScript", "sourceURL", sourceURL); #endif - if (!jsSourceURL) { + if (!jsSourceURL || !usePreparsingAndStringRef()) { evaluateScript(m_context, jsScript, jsSourceURL); } else { // If we're evaluating a script, get the device's cache dir diff --git a/ReactAndroid/src/main/jni/react/JSCExecutor.h b/ReactAndroid/src/main/jni/react/JSCExecutor.h index 7c704d0779798f..d810296f24b18d 100644 --- a/ReactAndroid/src/main/jni/react/JSCExecutor.h +++ b/ReactAndroid/src/main/jni/react/JSCExecutor.h @@ -113,6 +113,7 @@ class JSCExecutor : public JSExecutor { void receiveMessageFromOwner(const std::string &msgString); void terminateOwnedWebWorker(int worker); Object createMessageObject(const std::string& msgData); + bool usePreparsingAndStringRef(); static JSValueRef nativeStartWorker( JSContextRef ctx, diff --git a/ReactAndroid/src/main/jni/react/JSCHelpers.cpp b/ReactAndroid/src/main/jni/react/JSCHelpers.cpp index e961a4051c4b77..27dca94f12ccc6 100644 --- a/ReactAndroid/src/main/jni/react/JSCHelpers.cpp +++ b/ReactAndroid/src/main/jni/react/JSCHelpers.cpp @@ -38,7 +38,9 @@ JSValueRef makeJSCException( JSValueRef evaluateScript(JSContextRef context, JSStringRef script, JSStringRef source, const char *cachePath) { JSValueRef exn, result; #if WITH_FBJSCEXTENSIONS - if (source){ + // Only evaluate the script using pre-parsing cache if the script comes from + // a bundle file and a cache path is given. + if (source && cachePath){ // If evaluating an application script, send it through `JSEvaluateScriptWithCache()` // to add cache support. result = JSEvaluateScriptWithCache(context, script, NULL, source, 0, &exn, cachePath);