Skip to content

Commit

Permalink
Expose a way to retrieve the underlying VM Runtime instance from JSI …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
rFlex authored and facebook-github-bot committed Aug 13, 2024
1 parent 05ee71f commit 880b164
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions API/hermes/hermes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1382,6 +1382,10 @@ jsi::Value HermesRuntime::evaluateJavaScriptWithSourceMap(
buffer, sourceMapBuf, sourceURL));
}

::hermes::vm::Runtime *HermesRuntime::getVMRuntimeUnsafe() const {
return impl(this)->rt_.get();
}

size_t HermesRuntime::rootsListLengthForTests() const {
return impl(this)->hermesValues_.sizeForTests();
}
Expand Down
7 changes: 7 additions & 0 deletions API/hermes/hermes.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ struct HermesTestHelper;
namespace hermes {
namespace vm {
class GCExecTrace;
class Runtime;
} // namespace vm
} // namespace hermes

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

/// Returns the underlying low level Hermes VM runtime instance.
/// This function is considered unsafe and unstable.
/// Direct use of a vm::Runtime should be avoided as the lower level APIs are
/// unsafe and they can change without notice.
::hermes::vm::Runtime *getVMRuntimeUnsafe() const;

private:
// Only HermesRuntimeImpl can subclass this.
HermesRuntime() = default;
Expand Down

0 comments on commit 880b164

Please sign in to comment.