Files
react-native/ReactCommon/hermes/inspector/RuntimeAdapter.h
T
cpojer d7f5153cd8 Add Hermes support to React Native on Android (#25613)
Summary:
Yesterday we shipped hermesengine.dev as part of the current 0.60 release. This PR brings those changes to master.

## Changelog

[General] [Added] - Added support for Hermes
Pull Request resolved: https://github.com/facebook/react-native/pull/25613

Test Plan:
* CI is green both on GitHub and at FB
* Creating a new app from source can use Hermes on Android

Reviewed By: cpojer

Differential Revision: D16221777

Pulled By: willholen

fbshipit-source-id: aa6be10537863039cb666292465ba2e1d44b64ef
2019-07-25 23:05:53 -07:00

60 lines
1.8 KiB
C++

// Copyright 2004-present Facebook. All Rights Reserved.
#pragma once
#include <memory>
#include <hermes/hermes.h>
namespace facebook {
namespace hermes {
namespace inspector {
/**
* RuntimeAdapter encapsulates a HermesRuntime object. The underlying Hermes
* runtime object should stay alive for at least as long as the RuntimeAdapter
* is alive.
*/
class RuntimeAdapter {
public:
virtual ~RuntimeAdapter() = 0;
/// getRuntime should return the Hermes runtime encapsulated by this adapter.
virtual HermesRuntime &getRuntime() = 0;
/// tickleJs is a method that subclasses can choose to override to make the
/// inspector more responsive. If overridden, it should call the "__tickleJs"
/// function. The call should occur with appropriate locking (e.g. via a
/// thread-safe runtime instance, or by enqueuing the call on to a dedicated
/// JS thread).
///
/// This makes the inspector more responsive because it gives the inspector
/// the ability to force the process to enter the Hermes interpreter loop
/// soon. This is important because the inspector can only do a number of
/// important operations (like manipulating breakpoints) within the context of
/// a Hermes interperter loop.
///
/// The default implementation does nothing.
virtual void tickleJs();
};
/**
* SharedRuntimeAdapter is a simple implementation of RuntimeAdapter that
* uses shared_ptr to hold on to the runtime. It's generally only used in tests,
* since it does not implement tickleJs.
*/
class SharedRuntimeAdapter : public RuntimeAdapter {
public:
SharedRuntimeAdapter(std::shared_ptr<HermesRuntime> runtime);
virtual ~SharedRuntimeAdapter();
HermesRuntime &getRuntime() override;
private:
std::shared_ptr<HermesRuntime> runtime_;
};
} // namespace inspector
} // namespace hermes
} // namespace facebook