Skip to content

Commit d731556

Browse files
lavenzgfacebook-github-bot
authored andcommitted
Allow ReactInstance to evaluate SH unit when possible (#53471)
Summary: Pull Request resolved: #53471 When IHermes::getSHUnitCreator() returns non-null pointer, call `evaluateSHUnit()` on that instead of `evaluateJavaScript()`. Changelog: [Internal] Reviewed By: dannysu Differential Revision: D80916868 fbshipit-source-id: 9c1e2327b720cab4b374d4752a9c64f87c592ad6
1 parent 1f57ae5 commit d731556

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

packages/react-native/ReactCommon/react/runtime/ReactInstance.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <cxxreact/TraceSection.h>
1616
#include <glog/logging.h>
1717
#include <jsi/JSIDynamic.h>
18+
#include <jsi/hermes.h>
1819
#include <jsi/instrumentation.h>
1920
#include <jsinspector-modern/HostTarget.h>
2021
#include <jsireact/JSIExecutor.h>
@@ -242,7 +243,17 @@ void ReactInstance::loadScript(
242243
ReactMarker::RUN_JS_BUNDLE_START, scriptName.c_str());
243244
}
244245

245-
runtime.evaluateJavaScript(buffer, sourceURL);
246+
// Check if the shermes unit is avaliable.
247+
auto* shUnitAPI = jsi::castInterface<hermes::IHermesSHUnit>(&runtime);
248+
auto* shUnitCreator = shUnitAPI ? shUnitAPI->getSHUnitCreator() : nullptr;
249+
if (shUnitCreator) {
250+
LOG(WARNING) << "ReactInstance: evaluateSHUnit";
251+
auto* hermesAPI = jsi::castInterface<hermes::IHermes>(&runtime);
252+
hermesAPI->evaluateSHUnit(shUnitCreator);
253+
} else {
254+
LOG(WARNING) << "ReactInstance: evaluateJavaScript() with JS bundle";
255+
runtime.evaluateJavaScript(buffer, sourceURL);
256+
}
246257

247258
/**
248259
* TODO(T183610671): We need a safe/reliable way to enable the js

0 commit comments

Comments
 (0)