Skip to content

Commit 880b164

Browse files
rFlexfacebook-github-bot
authored andcommitted
Expose a way to retrieve the underlying VM Runtime instance from JSI HermesRuntime (#1430)
Summary: I understand this change might be a bit contentious, but please hear me out. Our Hermes integration does not use the JSI API, we integrate with the Hermes Runtime C++ API directly. There are a few reasons for this: - We already have an API that is similar to JSI for which we have 4 different JS engines integrated with it. If we were integrating Hermes through JSI we would be implementing an abstraction on top of an abstraction, which adds performance and memory overhead. We want our Hermes integration to be as fast as it can be, and for that we need our bridge layer to have minimal overhead so that it can compete on a performance level against our other JS engine integrations that are also based on lower level JS engine primitives. - There are APIs we need to integrate that can't be implemented with JSI. - We don't have C++ exceptions enabled, and the JSI Hermes integration makes heavy use of them and forces its consumers to handle errors through exceptions. The Hermes Debugger implementation is however based on the JSI API, so in order for us to leverage the Hermes Debugger, this change exposes a new method that returns the underlying VM Runtime instance from the JSI API. This makes it possible for us to keep our integration which is based on the VM Runtime API directly instead of JSI, and use the debugger API. Pull Request resolved: #1430 Test Plan: <!-- Demonstrate the code is solid. Example: The exact commands you ran and their output, screenshots / videos if the pull request changes the user interface. --> Reviewed By: avp Differential Revision: D61212063 Pulled By: neildhar fbshipit-source-id: dea983dab57c0e8eaa35d0d8a3bb776c6ce55b22
1 parent 05ee71f commit 880b164

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

API/hermes/hermes.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -1382,6 +1382,10 @@ jsi::Value HermesRuntime::evaluateJavaScriptWithSourceMap(
13821382
buffer, sourceMapBuf, sourceURL));
13831383
}
13841384

1385+
::hermes::vm::Runtime *HermesRuntime::getVMRuntimeUnsafe() const {
1386+
return impl(this)->rt_.get();
1387+
}
1388+
13851389
size_t HermesRuntime::rootsListLengthForTests() const {
13861390
return impl(this)->hermesValues_.sizeForTests();
13871391
}

API/hermes/hermes.h

+7
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ struct HermesTestHelper;
2525
namespace hermes {
2626
namespace vm {
2727
class GCExecTrace;
28+
class Runtime;
2829
} // namespace vm
2930
} // namespace hermes
3031

@@ -214,6 +215,12 @@ class HERMES_EXPORT HermesRuntime : public jsi::Runtime {
214215
const std::shared_ptr<const jsi::Buffer> &sourceMapBuf,
215216
const std::string &sourceURL);
216217

218+
/// Returns the underlying low level Hermes VM runtime instance.
219+
/// This function is considered unsafe and unstable.
220+
/// Direct use of a vm::Runtime should be avoided as the lower level APIs are
221+
/// unsafe and they can change without notice.
222+
::hermes::vm::Runtime *getVMRuntimeUnsafe() const;
223+
217224
private:
218225
// Only HermesRuntimeImpl can subclass this.
219226
HermesRuntime() = default;

0 commit comments

Comments
 (0)