1 #ifndef SRC_JS_NATIVE_API_V8_INTERNALS_H_
2 #define SRC_JS_NATIVE_API_V8_INTERNALS_H_
3
4 // The V8 implementation of N-API, including `js_native_api_v8.h` uses certain
5 // idioms which require definition here. For example, it uses a variant of
6 // persistent references which need not be reset in the constructor. It is the
7 // responsibility of this file to define these idioms. Optionally, this file
8 // may also define `NAPI_VERSION` and set it to the version of N-API to be
9 // exposed.
10
11 // In the case of the Node.js implementation of N-API some of the idioms are
12 // imported directly from Node.js by including `node_internals.h` below. Others
13 // are bridged to remove references to the `node` namespace. `node_version.h`,
14 // included below, defines `NAPI_VERSION`.
15
16 #include "node_version.h"
17
18 #include "env.h"
19 #include "gtest/gtest_prod.h"
20 #include "node_errors.h"
21 #include "node_internals.h"
22
23 #define JSVM_ARRAYSIZE(array) node::arraysize((array))
24
25 #define JSVM_FIXED_ONE_BYTE_STRING(isolate, string) \
26 node::FIXED_ONE_BYTE_STRING((isolate), (string))
27
28 #define JSVM_PRIVATE_KEY(isolate, suffix) \
29 (v8impl::GetIsolateData(isolate)->jsvm_##suffix##_key.Get(isolate))
30
31 namespace v8impl {
32
33 template <typename T>
34 using Persistent = v8::Global<T>;
35
36 using PersistentToLocal = node::PersistentToLocal;
37
OnFatalError(const char * location,const char * message)38 [[noreturn]] inline void OnFatalError(const char* location,
39 const char* message) {
40 node::OnFatalError(location, message);
41 }
42
43 } // end of namespace v8impl
44
45 #endif // SRC_JS_NATIVE_API_V8_INTERNALS_H_
46