JSC Pre-Parsing cache
Reviewed By: mikearmstrong001 Differential Revision: D2840411 fb-gh-sync-id: d238e10b9a859185e6011c4685229cedbcc57a3e
This commit is contained in:
parent
191b692e05
commit
ea1aec3c23
|
@ -138,6 +138,29 @@ JSCExecutor::~JSCExecutor() {
|
|||
JSGlobalContextRelease(m_context);
|
||||
}
|
||||
|
||||
std::string JSCExecutor::getDeviceCacheDir(){
|
||||
// Get the Application Context object
|
||||
auto getApplicationClass = findClassLocal(
|
||||
"com/facebook/react/common/ApplicationHolder");
|
||||
auto getApplicationMethod = getApplicationClass->getStaticMethod<jobject()>(
|
||||
"getApplication",
|
||||
"()Landroid/app/Application;"
|
||||
);
|
||||
auto application = getApplicationMethod(getApplicationClass);
|
||||
|
||||
// Get getCacheDir() from the context
|
||||
auto getCacheDirMethod = findClassLocal("android/app/Application")
|
||||
->getMethod<jobject()>("getCacheDir",
|
||||
"()Ljava/io/File;"
|
||||
);
|
||||
auto cacheDirObj = getCacheDirMethod(application);
|
||||
|
||||
// Call getAbsolutePath() on the returned File object
|
||||
auto getAbsolutePathMethod = findClassLocal("java/io/File")
|
||||
->getMethod<jstring()>("getAbsolutePath");
|
||||
return getAbsolutePathMethod(cacheDirObj)->toStdString();
|
||||
}
|
||||
|
||||
void JSCExecutor::executeApplicationScript(
|
||||
const std::string& script,
|
||||
const std::string& sourceURL) {
|
||||
|
@ -153,11 +176,18 @@ void JSCExecutor::executeApplicationScript(
|
|||
env->DeleteLocalRef(startStringMarker);
|
||||
env->DeleteLocalRef(endStringMarker);
|
||||
|
||||
String jsSourceURL(sourceURL.c_str());
|
||||
#ifdef WITH_FBSYSTRACE
|
||||
FbSystraceSection s(TRACE_TAG_REACT_CXX_BRIDGE, "JSCExecutor::executeApplicationScript",
|
||||
"sourceURL", sourceURL);
|
||||
#endif
|
||||
evaluateScript(m_context, jsScript, String(sourceURL.c_str()));
|
||||
if (!jsSourceURL) {
|
||||
evaluateScript(m_context, jsScript, jsSourceURL);
|
||||
} else {
|
||||
// If we're evaluating a script, get the device's cache dir
|
||||
// in which a cache file for that script will be stored.
|
||||
evaluateScript(m_context, jsScript, jsSourceURL, getDeviceCacheDir().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void JSCExecutor::loadApplicationUnbundle(
|
||||
|
|
|
@ -71,6 +71,7 @@ private:
|
|||
void postMessageToWebWorker(int worker, JSValueRef message, JSValueRef *exn);
|
||||
void terminateWebWorker(int worker);
|
||||
void loadModule(uint32_t moduleId);
|
||||
std::string getDeviceCacheDir();
|
||||
|
||||
static JSValueRef nativeStartWorker(
|
||||
JSContextRef ctx,
|
||||
|
|
|
@ -8,6 +8,10 @@
|
|||
|
||||
#include "Value.h"
|
||||
|
||||
#if WITH_FBJSCEXTENSIONS
|
||||
#include <jsc_function_info_cache.h>
|
||||
#endif
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
|
@ -32,9 +36,19 @@ JSValueRef makeJSCException(
|
|||
return JSValueToObject(ctx, exceptionString, NULL);
|
||||
}
|
||||
|
||||
JSValueRef evaluateScript(JSContextRef context, JSStringRef script, JSStringRef source) {
|
||||
JSValueRef exn;
|
||||
auto result = JSEvaluateScript(context, script, NULL, source, 0, &exn);
|
||||
JSValueRef evaluateScript(JSContextRef context, JSStringRef script, JSStringRef source, const char *cachePath) {
|
||||
JSValueRef exn, result;
|
||||
#if WITH_FBJSCEXTENSIONS
|
||||
if (source){
|
||||
// If evaluating an application script, send it through `JSEvaluateScriptWithCache()`
|
||||
// to add cache support.
|
||||
result = JSEvaluateScriptWithCache(context, script, NULL, source, 0, &exn, cachePath);
|
||||
} else {
|
||||
result = JSEvaluateScript(context, script, NULL, source, 0, &exn);
|
||||
}
|
||||
#else
|
||||
result = JSEvaluateScript(context, script, NULL, source, 0, &exn);
|
||||
#endif
|
||||
if (result == nullptr) {
|
||||
Value exception = Value(context, exn);
|
||||
std::string exceptionText = exception.toString().str();
|
||||
|
|
|
@ -20,6 +20,6 @@ JSValueRef makeJSCException(
|
|||
JSContextRef ctx,
|
||||
const char* exception_text);
|
||||
|
||||
JSValueRef evaluateScript(JSContextRef context, JSStringRef script, JSStringRef source);
|
||||
JSValueRef evaluateScript(JSContextRef context, JSStringRef script, JSStringRef source, const char *cachePath = nullptr);
|
||||
|
||||
} }
|
||||
|
|
Loading…
Reference in New Issue