Skip to content

Commit a9dd976

Browse files
dannysufacebook-github-bot
authored andcommitted
Expose a way to retrieve the underlying VM Runtime instance from JSI HermesRuntime (#1430) (#1430)
Summary: Original Author: [email protected] Original Git: 880b164 Original Reviewed By: avp Original Revision: D61212063 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 Pulled By: neildhar Reviewed By: neildhar Differential Revision: D61574245 fbshipit-source-id: 3ce10e622233d2f75d788d9bb0d6b4b2cbdeed52
1 parent b5e9c09 commit a9dd976

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
@@ -1426,6 +1426,10 @@ SHRuntime *HermesRuntime::getSHRuntime() noexcept {
14261426
return vm::getSHRuntime(impl(this)->runtime_);
14271427
}
14281428

1429+
::hermes::vm::Runtime *HermesRuntime::getVMRuntimeUnsafe() const {
1430+
return impl(this)->rt_.get();
1431+
}
1432+
14291433
size_t HermesRuntime::rootsListLengthForTests() const {
14301434
return impl(this)->hermesValues_.sizeForTests();
14311435
}

API/hermes/hermes.h

+7
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ struct SHRuntime;
2727
namespace hermes {
2828
namespace vm {
2929
class GCExecTrace;
30+
class Runtime;
3031
} // namespace vm
3132
} // namespace hermes
3233

@@ -224,6 +225,12 @@ class HERMES_EXPORT HermesRuntime : public jsi::Runtime {
224225
/// Retrieve the underlying SHRuntime.
225226
SHRuntime *getSHRuntime() noexcept;
226227

228+
/// Returns the underlying low level Hermes VM runtime instance.
229+
/// This function is considered unsafe and unstable.
230+
/// Direct use of a vm::Runtime should be avoided as the lower level APIs are
231+
/// unsafe and they can change without notice.
232+
::hermes::vm::Runtime *getVMRuntimeUnsafe() const;
233+
227234
private:
228235
// Only HermesRuntimeImpl can subclass this.
229236
HermesRuntime() = default;

0 commit comments

Comments
 (0)