ReactNative 源码分析4——ReactActivity之加载JSBundle

接着ReactInstanceManager.createReactContext方法继续讲

scss 复制代码
////ReactInstanceManager.createReactContext
private ReactApplicationContext createReactContext(
    JavaScriptExecutor jsExecutor, JSBundleLoader jsBundleLoader) {
    ...
    catalystInstance.runJSBundle();
    ...
}

最终会调用到如下 2 个方法进入C++层

arduino 复制代码
private native void jniLoadScriptFromAssets(
    AssetManager assetManager, String assetURL, boolean loadSynchronously);

private native void jniLoadScriptFromFile(
    String fileName, String sourceURL, boolean loadSynchronously);

jniLoadScriptFromFile是调用到instance_->loadScriptFromString,然后调用loadBundle

c 复制代码
void Instance::loadBundle(
    std::unique_ptr<RAMBundleRegistry> bundleRegistry,
    std::unique_ptr<const JSBigString> string,
    std::string sourceURL) {
  callback_->incrementPendingJSCalls();
  SystraceSection s( "Instance::loadBundle" , "sourceURL" , sourceURL);
  nativeToJsBridge_->loadBundle(
      std::move(bundleRegistry), std::move(string), std::move(sourceURL));
}
  • callback_是Java层的InstanceCallback实例,这里是通知Java层
  • nativeToJsBridge_是NativeToJsBridge对象
arduino 复制代码
void NativeToJsBridge::loadBundle(
    std::unique_ptr<RAMBundleRegistry> bundleRegistry,
    std::unique_ptr<const JSBigString> startupScript,
    std::string startupScriptSourceURL) {
  runOnExecutorQueue(
      [this,
       bundleRegistryWrap = makeMoveWrapper(std::move(bundleRegistry)),
       startupScript = makeMoveWrapper(std::move(startupScript)),
       startupScriptSourceURL =
           std::move(startupScriptSourceURL)](JSExecutor* executor) mutable {
        auto bundleRegistry = bundleRegistryWrap.move();
        if (bundleRegistry) {
          executor->setBundleRegistry(std::move(bundleRegistry));
        }
        try {
          executor->loadBundle(
              std::move(*startupScript), std::move(startupScriptSourceURL));
        } catch (...) {
          m_applicationScriptHasFailure = true;
          throw;
        }
      });
}
  • runOnExecutorQueue在JS线程中执行
  • executor是HermesExecutor对象
c 复制代码
void JSIExecutor::loadBundle(
    std::unique_ptr<const JSBigString> script,
    std::string sourceURL) {
  ...
  runtime_->evaluateJavaScript(
      std::make_unique<BigStringBuffer>(std::move(script)), sourceURL);
  ...
}
  • runtime_:DecoratedRuntime对象,它里面包装了HermesRuntime运行时

到这里其实就明确了,调用Hermes引擎去加载JSBundle

相关推荐
weixin_394758033 小时前
CRMEB Pro 优惠券:下单怎么核销,取消/退款怎么返券
android
alexhilton4 小时前
Android 17 内存预算成为必修课
android·kotlin·android jetpack
AI2中文网7 小时前
App Inventor 对接 OneNet:手机收数据
android·鸿蒙·app inventor
好的佩奇7 小时前
Dart 之文件读写
android·flutter·dart
砚底藏山河9 小时前
量化行情横截面中性化闭式与回归实现
android·java·python·金融·kotlin
明君6899 小时前
APK 签名绕过方案(Android 10~17)
android
芝麻别开门9 小时前
Android libmpv 源码下载与编译
android·mpv·libmpv
FLJwu9 小时前
运动相机代工模具风控③:试模样品、结构公差、装配干涉,提前规避大货装配不良
android·开发语言·数码相机·运动相机·oem 量产
应用市场10 小时前
安卓底层拆解(四)· 属性要成套:abilist 与 zygote 的连锁反应
android·zygote
齊家治國平天下11 小时前
Android Automotive(AAOS)系统入门:从五层架构到车载机制
android·架构·车载系统·aaos·智能座舱