Skip to content

Commit 25aa541

Browse files
committed
feat: add HermesRuntime::createNapiEnv method
1 parent dceba8c commit 25aa541

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

API/hermes/hermes.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
*/
77

88
#include "hermes.h"
9+
#include "hermes_win.h"
10+
#include "ScriptStore.h"
911

1012
#include "llvh/Support/Compiler.h"
1113

@@ -78,6 +80,13 @@ namespace vm = hermes::vm;
7880
namespace hbc = hermes::hbc;
7981
using ::hermes::hermesLog;
8082

83+
napi_status hermes_create_napi_env(
84+
::hermes::vm::Runtime &runtime,
85+
bool isInspectable,
86+
std::shared_ptr<facebook::jsi::PreparedScriptStore> preparedScript,
87+
const ::hermes::vm::RuntimeConfig &runtimeConfig,
88+
napi_env *env);
89+
8190
namespace facebook {
8291
namespace hermes {
8392
namespace detail {
@@ -1068,6 +1077,11 @@ inline const HermesRuntimeImpl *impl(const HermesRuntime *rt) {
10681077

10691078
} // namespace
10701079

1080+
napi_status HermesRuntime::createNapiEnv(napi_env *env) {
1081+
auto imp = impl(this);
1082+
return hermes_create_napi_env(imp->runtime_, true, nullptr, {}, env);
1083+
}
1084+
10711085
bool HermesRuntime::isHermesBytecode(const uint8_t *data, size_t len) {
10721086
return hbc::BCProviderFromBuffer::isBytecodeStream(
10731087
llvh::ArrayRef<uint8_t>(data, len));

API/hermes/hermes.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include <jsi/jsi.h>
2121
#include <unordered_map>
2222

23+
#include "js_native_api.h"
24+
2325
struct HermesTestHelper;
2426

2527
namespace hermes {
@@ -82,6 +84,8 @@ class HERMES_EXPORT HermesRuntime : public jsi::Runtime {
8284
/// Dump sampled stack trace to the given stream.
8385
static void dumpSampledTraceToStream(std::ostream &stream);
8486

87+
napi_status createNapiEnv(napi_env *env);
88+
8589
/// Serialize the sampled stack to the format expected by DevTools'
8690
/// Profiler.stop return type.
8791
void sampledTraceToStreamInDevToolsFormat(std::ostream &stream);

0 commit comments

Comments
 (0)