void NativeToJsBridge::setGlobalVariable(std::string propName, std::unique_ptr<const JSBigString> jsonValue) { runOnExecutorQueue([propName=std::move(propName), jsonValue=folly::makeMoveWrapper(std::move(jsonValue))] (JSExecutor* executor) mutable { executor->setGlobalVariable(propName, jsonValue.move()); }); }
void NativeToJsBridge::callFunction( std::string&& module, std::string&& method, folly::dynamic&& arguments) { int systraceCookie = -1; #ifdef WITH_FBSYSTRACE systraceCookie = m_systraceCookie++; FbSystraceAsyncFlow::begin( TRACE_TAG_REACT_CXX_BRIDGE, "JSCall", systraceCookie); #endif runOnExecutorQueue([module = std::move(module), method = std::move(method), arguments = std::move(arguments), systraceCookie] (JSExecutor* executor) { #ifdef WITH_FBSYSTRACE FbSystraceAsyncFlow::end( TRACE_TAG_REACT_CXX_BRIDGE, "JSCall", systraceCookie); SystraceSection s("NativeToJsBridge::callFunction", "module", module, "method", method); #endif // This is safe because we are running on the executor's thread: it won't // destruct until after it's been unregistered (which we check above) and // that will happen on this thread executor->callFunction(module, method, arguments); }); }
void NativeToJsBridge::callFunction( ExecutorToken executorToken, std::string&& module, std::string&& method, folly::dynamic&& arguments) { int systraceCookie = -1; #ifdef WITH_FBSYSTRACE systraceCookie = m_systraceCookie++; std::string tracingName = fbsystrace_is_tracing(TRACE_TAG_REACT_CXX_BRIDGE) ? folly::to<std::string>("JSCall__", module, '_', method) : std::string(); SystraceSection s(tracingName.c_str()); FbSystraceAsyncFlow::begin( TRACE_TAG_REACT_CXX_BRIDGE, tracingName.c_str(), systraceCookie); #else std::string tracingName; #endif runOnExecutorQueue(executorToken, [module = std::move(module), method = std::move(method), arguments = std::move(arguments), tracingName = std::move(tracingName), systraceCookie] (JSExecutor* executor) { #ifdef WITH_FBSYSTRACE FbSystraceAsyncFlow::end( TRACE_TAG_REACT_CXX_BRIDGE, tracingName.c_str(), systraceCookie); SystraceSection s(tracingName.c_str()); #endif // This is safe because we are running on the executor's thread: it won't // destruct until after it's been unregistered (which we check above) and // that will happen on this thread executor->callFunction(module, method, arguments); }); }
void NativeToJsBridge::callFunction( ExecutorToken executorToken, const std::string& moduleId, const std::string& methodId, const folly::dynamic& arguments, const std::string& tracingName) { int systraceCookie = -1; #ifdef WITH_FBSYSTRACE systraceCookie = m_systraceCookie++; FbSystraceAsyncFlow::begin( TRACE_TAG_REACT_CXX_BRIDGE, tracingName.c_str(), systraceCookie); #endif runOnExecutorQueue(executorToken, [moduleId, methodId, arguments, tracingName, systraceCookie] (JSExecutor* executor) { #ifdef WITH_FBSYSTRACE FbSystraceAsyncFlow::end( TRACE_TAG_REACT_CXX_BRIDGE, tracingName.c_str(), systraceCookie); SystraceSection s(tracingName.c_str()); #endif // This is safe because we are running on the executor's thread: it won't // destruct until after it's been unregistered (which we check above) and // that will happen on this thread executor->callFunction(moduleId, methodId, arguments); }); }
void NativeToJsBridge::loadApplicationUnbundle( std::unique_ptr<JSModulesUnbundle> unbundle, std::unique_ptr<const JSBigString> startupScript, std::string startupScriptSourceURL) { runOnExecutorQueue( m_mainExecutorToken, [unbundle=folly::makeMoveWrapper(std::move(unbundle)), startupScript=folly::makeMoveWrapper(std::move(startupScript)), startupScriptSourceURL=std::move(startupScriptSourceURL)] (JSExecutor* executor) mutable { executor->setJSModulesUnbundle(unbundle.move()); executor->loadApplicationScript(std::move(*startupScript), std::move(startupScriptSourceURL)); }); }
void NativeToJsBridge::loadApplication( std::unique_ptr<RAMBundleRegistry> bundleRegistry, std::unique_ptr<const JSBigString> startupScript, std::string startupScriptSourceURL) { runOnExecutorQueue( [bundleRegistryWrap=folly::makeMoveWrapper(std::move(bundleRegistry)), startupScript=folly::makeMoveWrapper(std::move(startupScript)), startupScriptSourceURL=std::move(startupScriptSourceURL)] (JSExecutor* executor) mutable { auto bundleRegistry = bundleRegistryWrap.move(); if (bundleRegistry) { executor->setBundleRegistry(std::move(bundleRegistry)); } executor->loadApplicationScript(std::move(*startupScript), std::move(startupScriptSourceURL)); }); }
void NativeToJsBridge::invokeCallback(double callbackId, folly::dynamic&& arguments) { int systraceCookie = -1; #ifdef WITH_FBSYSTRACE systraceCookie = m_systraceCookie++; FbSystraceAsyncFlow::begin( TRACE_TAG_REACT_CXX_BRIDGE, "<callback>", systraceCookie); #endif runOnExecutorQueue([callbackId, arguments = std::move(arguments), systraceCookie] (JSExecutor* executor) { #ifdef WITH_FBSYSTRACE FbSystraceAsyncFlow::end( TRACE_TAG_REACT_CXX_BRIDGE, "<callback>", systraceCookie); SystraceSection s("NativeToJsBridge::invokeCallback"); #endif executor->invokeCallback(callbackId, arguments); }); }
void NativeToJsBridge::handleMemoryPressure(int pressureLevel) { runOnExecutorQueue([=] (JSExecutor* executor) { executor->handleMemoryPressure(pressureLevel); }); }
void NativeToJsBridge::stopProfiler(const std::string& title, const std::string& filename) { runOnExecutorQueue([=] (JSExecutor* executor) { executor->stopProfiler(title, filename); }); }
void NativeToJsBridge::handleMemoryPressureCritical() { runOnExecutorQueue(m_mainExecutorToken, [=] (JSExecutor* executor) { executor->handleMemoryPressureCritical(); }); }
void NativeToJsBridge::startProfiler(const std::string& title) { runOnExecutorQueue(m_mainExecutorToken, [=] (JSExecutor* executor) { executor->startProfiler(title); }); }
void NativeToJsBridge::registerBundle(uint32_t bundleId, const std::string& bundlePath) { runOnExecutorQueue([bundleId, bundlePath] (JSExecutor* executor) { executor->registerBundle(bundleId, bundlePath); }); }