2
2
#include " js_runtime.h"
3
3
4
4
using namespace facebook ::jsi;
5
- std::unordered_map<napi_env, JSR*> JSR::env_to_jsr_cache;
5
+ std::unordered_map<napi_env, JSR *> JSR::env_to_jsr_cache;
6
6
7
7
typedef struct napi_runtime__ {
8
- JSR* hermes;
8
+ JSR * hermes;
9
9
} napi_runtime__;
10
10
11
11
JSR::JSR () {
12
12
hermes::vm::RuntimeConfig config =
13
- hermes::vm::RuntimeConfig::Builder ().withMicrotaskQueue (true ).withES6Class (true ).withES6Promise (true ).withArrayBuffer (true ).withEnableEval (true ).build ();
13
+ hermes::vm::RuntimeConfig::Builder ().withMicrotaskQueue (true ).withES6Class (
14
+ true ).withES6Promise (true ).withArrayBuffer (true ).withEnableEval (true ).build ();
14
15
threadSafeRuntime = facebook::hermes::makeThreadSafeHermesRuntime (config);
15
16
16
- facebook::jsi::Function abc = facebook::jsi::Function::createFromHostFunction (threadSafeRuntime->getUnsafeRuntime (), facebook::jsi::PropNameID::forAscii (threadSafeRuntime->getUnsafeRuntime (), " directFunction" ), 0 , [](Runtime& rt, const Value& thisVal, const Value* args, size_t count) -> Value {
17
- return Value::undefined ();
18
- });
17
+ facebook::jsi::Function abc = facebook::jsi::Function::createFromHostFunction (
18
+ threadSafeRuntime->getUnsafeRuntime (),
19
+ facebook::jsi::PropNameID::forAscii (threadSafeRuntime->getUnsafeRuntime (),
20
+ " directFunction" ), 0 ,
21
+ [](Runtime &rt, const Value &thisVal, const Value *args, size_t count) -> Value {
22
+ return Value::undefined ();
23
+ });
19
24
20
- threadSafeRuntime->getUnsafeRuntime ().global ().setProperty (threadSafeRuntime->getUnsafeRuntime (), " directFunction" , abc);
25
+ threadSafeRuntime->getUnsafeRuntime ().global ().setProperty (
26
+ threadSafeRuntime->getUnsafeRuntime (), " directFunction" , abc);
21
27
22
- rt = (facebook::hermes::HermesRuntime *)&threadSafeRuntime->getUnsafeRuntime ();
28
+ rt = (facebook::hermes::HermesRuntime *) &threadSafeRuntime->getUnsafeRuntime ();
23
29
}
24
30
25
- napi_status js_create_runtime (napi_runtime* runtime) {
31
+ napi_status js_create_runtime (napi_runtime * runtime) {
26
32
if (runtime == nullptr ) return napi_invalid_arg;
27
33
*runtime = new napi_runtime__ ();
28
34
(*runtime)->hermes = new JSR ();
@@ -49,19 +55,21 @@ napi_status js_unlock_env(napi_env env) {
49
55
50
56
return napi_ok;
51
57
}
52
- napi_status js_create_napi_env (napi_env* env, napi_runtime runtime) {
58
+
59
+ napi_status js_create_napi_env (napi_env *env, napi_runtime runtime) {
53
60
if (env == nullptr ) return napi_invalid_arg;
54
- runtime->hermes ->rt ->createNapiEnv ( env);
61
+ runtime->hermes ->rt ->createNapiEnv (env);
55
62
JSR::env_to_jsr_cache.insert (std::make_pair (*env, runtime->hermes ));
56
63
return napi_ok;
57
64
}
58
65
59
- napi_status js_set_runtime_flags (const char * flags) {
66
+ napi_status js_set_runtime_flags (const char * flags) {
60
67
return napi_ok;
61
68
}
62
69
63
70
napi_status js_free_napi_env (napi_env env) {
64
- return napi_ok;
71
+ JSR::env_to_jsr_cache.erase (env);
72
+ return napi_ok;
65
73
}
66
74
67
75
napi_status js_free_runtime (napi_runtime runtime) {
@@ -90,20 +98,23 @@ napi_status js_get_engine_ptr(napi_env env, int64_t *engine_ptr) {
90
98
return napi_ok;
91
99
}
92
100
93
- napi_status js_adjust_external_memory (napi_env env, int64_t changeInBytes, int64_t * externalMemory) {
101
+ napi_status
102
+ js_adjust_external_memory (napi_env env, int64_t changeInBytes, int64_t *externalMemory) {
103
+ napi_adjust_external_memory (env, changeInBytes, externalMemory);
94
104
return napi_ok;
95
105
}
96
106
97
107
napi_status js_cache_script (napi_env env, const char *source, const char *file) {
98
108
return napi_ok;
99
109
}
100
- napi_status js_run_cached_script (napi_env env, const char * file, napi_value script, void * cache, napi_value *result) {
110
+
111
+ napi_status js_run_cached_script (napi_env env, const char *file, napi_value script, void *cache,
112
+ napi_value *result) {
101
113
return napi_ok;
102
114
}
103
115
104
- napi_status js_get_runtime_version (napi_env env, napi_value* version) {
116
+ napi_status js_get_runtime_version (napi_env env, napi_value * version) {
105
117
napi_create_string_utf8 (env, " Hermes" , NAPI_AUTO_LENGTH, version);
106
-
107
118
return napi_ok;
108
119
}
109
120
0 commit comments