11cb0ef41Sopenharmony_ci#ifndef SRC_NODE_EXTERNAL_REFERENCE_H_
21cb0ef41Sopenharmony_ci#define SRC_NODE_EXTERNAL_REFERENCE_H_
31cb0ef41Sopenharmony_ci
41cb0ef41Sopenharmony_ci#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ci#include <cinttypes>
71cb0ef41Sopenharmony_ci#include <vector>
81cb0ef41Sopenharmony_ci#include "v8-fast-api-calls.h"
91cb0ef41Sopenharmony_ci#include "v8.h"
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_cinamespace node {
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ciusing CFunctionCallback = void (*)(v8::Local<v8::Value> receiver);
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ci// This class manages the external references from the V8 heap
161cb0ef41Sopenharmony_ci// to the C++ addresses in Node.js.
171cb0ef41Sopenharmony_ciclass ExternalReferenceRegistry {
181cb0ef41Sopenharmony_ci public:
191cb0ef41Sopenharmony_ci  ExternalReferenceRegistry();
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ci#define ALLOWED_EXTERNAL_REFERENCE_TYPES(V)                                    \
221cb0ef41Sopenharmony_ci  V(CFunctionCallback)                                                         \
231cb0ef41Sopenharmony_ci  V(const v8::CFunctionInfo*)                                                  \
241cb0ef41Sopenharmony_ci  V(v8::FunctionCallback)                                                      \
251cb0ef41Sopenharmony_ci  V(v8::AccessorGetterCallback)                                                \
261cb0ef41Sopenharmony_ci  V(v8::AccessorSetterCallback)                                                \
271cb0ef41Sopenharmony_ci  V(v8::AccessorNameGetterCallback)                                            \
281cb0ef41Sopenharmony_ci  V(v8::AccessorNameSetterCallback)                                            \
291cb0ef41Sopenharmony_ci  V(v8::GenericNamedPropertyDefinerCallback)                                   \
301cb0ef41Sopenharmony_ci  V(v8::GenericNamedPropertyDeleterCallback)                                   \
311cb0ef41Sopenharmony_ci  V(v8::GenericNamedPropertyEnumeratorCallback)                                \
321cb0ef41Sopenharmony_ci  V(v8::GenericNamedPropertyQueryCallback)                                     \
331cb0ef41Sopenharmony_ci  V(v8::GenericNamedPropertySetterCallback)                                    \
341cb0ef41Sopenharmony_ci  V(v8::IndexedPropertySetterCallback)                                         \
351cb0ef41Sopenharmony_ci  V(v8::IndexedPropertyDefinerCallback)                                        \
361cb0ef41Sopenharmony_ci  V(v8::IndexedPropertyDeleterCallback)                                        \
371cb0ef41Sopenharmony_ci  V(v8::IndexedPropertyQueryCallback)                                          \
381cb0ef41Sopenharmony_ci  V(v8::IndexedPropertyDescriptorCallback)
391cb0ef41Sopenharmony_ci
401cb0ef41Sopenharmony_ci#define V(ExternalReferenceType)                                               \
411cb0ef41Sopenharmony_ci  void Register(ExternalReferenceType addr) { RegisterT(addr); }
421cb0ef41Sopenharmony_ci  ALLOWED_EXTERNAL_REFERENCE_TYPES(V)
431cb0ef41Sopenharmony_ci#undef V
441cb0ef41Sopenharmony_ci
451cb0ef41Sopenharmony_ci  // This can be called only once.
461cb0ef41Sopenharmony_ci  const std::vector<intptr_t>& external_references();
471cb0ef41Sopenharmony_ci
481cb0ef41Sopenharmony_ci  bool is_empty() { return external_references_.empty(); }
491cb0ef41Sopenharmony_ci
501cb0ef41Sopenharmony_ci private:
511cb0ef41Sopenharmony_ci  template <typename T>
521cb0ef41Sopenharmony_ci  void RegisterT(T* address) {
531cb0ef41Sopenharmony_ci    external_references_.push_back(reinterpret_cast<intptr_t>(address));
541cb0ef41Sopenharmony_ci  }
551cb0ef41Sopenharmony_ci  bool is_finalized_ = false;
561cb0ef41Sopenharmony_ci  std::vector<intptr_t> external_references_;
571cb0ef41Sopenharmony_ci};
581cb0ef41Sopenharmony_ci
591cb0ef41Sopenharmony_ci#define EXTERNAL_REFERENCE_BINDING_LIST_BASE(V)                                \
601cb0ef41Sopenharmony_ci  V(async_wrap)                                                                \
611cb0ef41Sopenharmony_ci  V(binding)                                                                   \
621cb0ef41Sopenharmony_ci  V(blob)                                                                      \
631cb0ef41Sopenharmony_ci  V(buffer)                                                                    \
641cb0ef41Sopenharmony_ci  V(builtins)                                                                  \
651cb0ef41Sopenharmony_ci  V(cares_wrap)                                                                \
661cb0ef41Sopenharmony_ci  V(contextify)                                                                \
671cb0ef41Sopenharmony_ci  V(credentials)                                                               \
681cb0ef41Sopenharmony_ci  V(env_var)                                                                   \
691cb0ef41Sopenharmony_ci  V(errors)                                                                    \
701cb0ef41Sopenharmony_ci  V(fs)                                                                        \
711cb0ef41Sopenharmony_ci  V(fs_dir)                                                                    \
721cb0ef41Sopenharmony_ci  V(fs_event_wrap)                                                             \
731cb0ef41Sopenharmony_ci  V(handle_wrap)                                                               \
741cb0ef41Sopenharmony_ci  V(heap_utils)                                                                \
751cb0ef41Sopenharmony_ci  V(messaging)                                                                 \
761cb0ef41Sopenharmony_ci  V(mksnapshot)                                                                \
771cb0ef41Sopenharmony_ci  V(module_wrap)                                                               \
781cb0ef41Sopenharmony_ci  V(options)                                                                   \
791cb0ef41Sopenharmony_ci  V(os)                                                                        \
801cb0ef41Sopenharmony_ci  V(performance)                                                               \
811cb0ef41Sopenharmony_ci  V(process_methods)                                                           \
821cb0ef41Sopenharmony_ci  V(process_object)                                                            \
831cb0ef41Sopenharmony_ci  V(report)                                                                    \
841cb0ef41Sopenharmony_ci  V(task_queue)                                                                \
851cb0ef41Sopenharmony_ci  V(tcp_wrap)                                                                  \
861cb0ef41Sopenharmony_ci  V(tty_wrap)                                                                  \
871cb0ef41Sopenharmony_ci  V(url)                                                                       \
881cb0ef41Sopenharmony_ci  V(util)                                                                      \
891cb0ef41Sopenharmony_ci  V(pipe_wrap)                                                                 \
901cb0ef41Sopenharmony_ci  V(sea)                                                                       \
911cb0ef41Sopenharmony_ci  V(serdes)                                                                    \
921cb0ef41Sopenharmony_ci  V(string_decoder)                                                            \
931cb0ef41Sopenharmony_ci  V(stream_wrap)                                                               \
941cb0ef41Sopenharmony_ci  V(signal_wrap)                                                               \
951cb0ef41Sopenharmony_ci  V(trace_events)                                                              \
961cb0ef41Sopenharmony_ci  V(timers)                                                                    \
971cb0ef41Sopenharmony_ci  V(types)                                                                     \
981cb0ef41Sopenharmony_ci  V(uv)                                                                        \
991cb0ef41Sopenharmony_ci  V(v8)                                                                        \
1001cb0ef41Sopenharmony_ci  V(zlib)                                                                      \
1011cb0ef41Sopenharmony_ci  V(wasm_web_api)                                                              \
1021cb0ef41Sopenharmony_ci  V(worker)
1031cb0ef41Sopenharmony_ci
1041cb0ef41Sopenharmony_ci#if NODE_HAVE_I18N_SUPPORT
1051cb0ef41Sopenharmony_ci#define EXTERNAL_REFERENCE_BINDING_LIST_I18N(V) V(icu)
1061cb0ef41Sopenharmony_ci#else
1071cb0ef41Sopenharmony_ci#define EXTERNAL_REFERENCE_BINDING_LIST_I18N(V)
1081cb0ef41Sopenharmony_ci#endif  // NODE_HAVE_I18N_SUPPORT
1091cb0ef41Sopenharmony_ci
1101cb0ef41Sopenharmony_ci#if HAVE_INSPECTOR
1111cb0ef41Sopenharmony_ci#define EXTERNAL_REFERENCE_BINDING_LIST_INSPECTOR(V)                           \
1121cb0ef41Sopenharmony_ci  V(inspector)                                                                 \
1131cb0ef41Sopenharmony_ci  V(profiler)
1141cb0ef41Sopenharmony_ci#else
1151cb0ef41Sopenharmony_ci#define EXTERNAL_REFERENCE_BINDING_LIST_INSPECTOR(V)
1161cb0ef41Sopenharmony_ci#endif  // HAVE_INSPECTOR
1171cb0ef41Sopenharmony_ci
1181cb0ef41Sopenharmony_ci#if HAVE_DTRACE || HAVE_ETW
1191cb0ef41Sopenharmony_ci#define EXTERNAL_REFERENCE_BINDING_LIST_DTRACE(V) V(dtrace)
1201cb0ef41Sopenharmony_ci#else
1211cb0ef41Sopenharmony_ci#define EXTERNAL_REFERENCE_BINDING_LIST_DTRACE(V)
1221cb0ef41Sopenharmony_ci#endif
1231cb0ef41Sopenharmony_ci
1241cb0ef41Sopenharmony_ci#if HAVE_OPENSSL
1251cb0ef41Sopenharmony_ci#define EXTERNAL_REFERENCE_BINDING_LIST_CRYPTO(V) V(crypto) V(tls_wrap)
1261cb0ef41Sopenharmony_ci#else
1271cb0ef41Sopenharmony_ci#define EXTERNAL_REFERENCE_BINDING_LIST_CRYPTO(V)
1281cb0ef41Sopenharmony_ci#endif  // HAVE_OPENSSL
1291cb0ef41Sopenharmony_ci
1301cb0ef41Sopenharmony_ci#define EXTERNAL_REFERENCE_BINDING_LIST(V)                                     \
1311cb0ef41Sopenharmony_ci  EXTERNAL_REFERENCE_BINDING_LIST_BASE(V)                                      \
1321cb0ef41Sopenharmony_ci  EXTERNAL_REFERENCE_BINDING_LIST_INSPECTOR(V)                                 \
1331cb0ef41Sopenharmony_ci  EXTERNAL_REFERENCE_BINDING_LIST_I18N(V)                                      \
1341cb0ef41Sopenharmony_ci  EXTERNAL_REFERENCE_BINDING_LIST_DTRACE(V)                                    \
1351cb0ef41Sopenharmony_ci  EXTERNAL_REFERENCE_BINDING_LIST_CRYPTO(V)
1361cb0ef41Sopenharmony_ci
1371cb0ef41Sopenharmony_ci}  // namespace node
1381cb0ef41Sopenharmony_ci
1391cb0ef41Sopenharmony_ci// Declare all the external reference registration functions here,
1401cb0ef41Sopenharmony_ci// and define them later with #NODE_BINDING_EXTERNAL_REFERENCE(modname, func);
1411cb0ef41Sopenharmony_ci#define V(modname)                                                             \
1421cb0ef41Sopenharmony_ci  void _register_external_reference_##modname(                                 \
1431cb0ef41Sopenharmony_ci      node::ExternalReferenceRegistry* registry);
1441cb0ef41Sopenharmony_ciEXTERNAL_REFERENCE_BINDING_LIST(V)
1451cb0ef41Sopenharmony_ci#undef V
1461cb0ef41Sopenharmony_ci
1471cb0ef41Sopenharmony_ci#define NODE_BINDING_EXTERNAL_REFERENCE(modname, func)                         \
1481cb0ef41Sopenharmony_ci  void _register_external_reference_##modname(                                 \
1491cb0ef41Sopenharmony_ci      node::ExternalReferenceRegistry* registry) {                             \
1501cb0ef41Sopenharmony_ci    func(registry);                                                            \
1511cb0ef41Sopenharmony_ci  }
1521cb0ef41Sopenharmony_ci#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
1531cb0ef41Sopenharmony_ci#endif  // SRC_NODE_EXTERNAL_REFERENCE_H_
154