Skip to content

Commit

Permalink
Adding Pre-PArsing cache & StringRef to iOS 8's JSC
Browse files Browse the repository at this point in the history
Reviewed By: michalgr

Differential Revision: D3066370

fb-gh-sync-id: 2dabffbd41d4f4f9f2a9ddaca3224ba00498821e
shipit-source-id: 2dabffbd41d4f4f9f2a9ddaca3224ba00498821e
  • Loading branch information
dcaspi authored and Facebook Github Bot 9 committed Mar 18, 2016
1 parent 60b2398 commit 22e55d4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
20 changes: 19 additions & 1 deletion ReactAndroid/src/main/jni/react/JSCExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,19 +205,37 @@ 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());
#ifdef WITH_FBSYSTRACE
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
Expand Down
1 change: 1 addition & 0 deletions ReactAndroid/src/main/jni/react/JSCExecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion ReactAndroid/src/main/jni/react/JSCHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 22e55d4

Please sign in to comment.