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
This commit is contained in:
Dan Caspi 2016-03-18 12:20:13 -07:00 committed by Facebook Github Bot 9
parent 60b2398cc5
commit 22e55d4396
3 changed files with 23 additions and 2 deletions

View File

@ -205,11 +205,29 @@ void JSCExecutor::terminateOnJSVMThread() {
m_context = nullptr; 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( void JSCExecutor::loadApplicationScript(
const std::string& script, const std::string& script,
const std::string& sourceURL) { const std::string& sourceURL) {
ReactMarker::logMarker("loadApplicationScript_startStringConvert"); 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); String jsScript = String::createExpectingAscii(script);
#endif
ReactMarker::logMarker("loadApplicationScript_endStringConvert"); ReactMarker::logMarker("loadApplicationScript_endStringConvert");
String jsSourceURL(sourceURL.c_str()); String jsSourceURL(sourceURL.c_str());
@ -217,7 +235,7 @@ void JSCExecutor::loadApplicationScript(
FbSystraceSection s(TRACE_TAG_REACT_CXX_BRIDGE, "JSCExecutor::loadApplicationScript", FbSystraceSection s(TRACE_TAG_REACT_CXX_BRIDGE, "JSCExecutor::loadApplicationScript",
"sourceURL", sourceURL); "sourceURL", sourceURL);
#endif #endif
if (!jsSourceURL) { if (!jsSourceURL || !usePreparsingAndStringRef()) {
evaluateScript(m_context, jsScript, jsSourceURL); evaluateScript(m_context, jsScript, jsSourceURL);
} else { } else {
// If we're evaluating a script, get the device's cache dir // If we're evaluating a script, get the device's cache dir

View File

@ -113,6 +113,7 @@ private:
void receiveMessageFromOwner(const std::string &msgString); void receiveMessageFromOwner(const std::string &msgString);
void terminateOwnedWebWorker(int worker); void terminateOwnedWebWorker(int worker);
Object createMessageObject(const std::string& msgData); Object createMessageObject(const std::string& msgData);
bool usePreparsingAndStringRef();
static JSValueRef nativeStartWorker( static JSValueRef nativeStartWorker(
JSContextRef ctx, JSContextRef ctx,

View File

@ -38,7 +38,9 @@ JSValueRef makeJSCException(
JSValueRef evaluateScript(JSContextRef context, JSStringRef script, JSStringRef source, const char *cachePath) { JSValueRef evaluateScript(JSContextRef context, JSStringRef script, JSStringRef source, const char *cachePath) {
JSValueRef exn, result; JSValueRef exn, result;
#if WITH_FBJSCEXTENSIONS #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()` // If evaluating an application script, send it through `JSEvaluateScriptWithCache()`
// to add cache support. // to add cache support.
result = JSEvaluateScriptWithCache(context, script, NULL, source, 0, &exn, cachePath); result = JSEvaluateScriptWithCache(context, script, NULL, source, 0, &exn, cachePath);