From 60867fb030bae582082340ead7dbc7efdc2f5398 Mon Sep 17 00:00:00 2001 From: 8cy <50817549+8cy@users.noreply.github.com> Date: Fri, 3 Apr 2020 02:37:42 -0700 Subject: 2020/04/03, 02:34, v1.2.0 --- node_modules/node-addon-api/src/node_internals.h | 157 +++++++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 node_modules/node-addon-api/src/node_internals.h (limited to 'node_modules/node-addon-api/src/node_internals.h') diff --git a/node_modules/node-addon-api/src/node_internals.h b/node_modules/node-addon-api/src/node_internals.h new file mode 100644 index 0000000..bacccff --- /dev/null +++ b/node_modules/node-addon-api/src/node_internals.h @@ -0,0 +1,157 @@ +#ifndef SRC_NODE_INTERNALS_H_ +#define SRC_NODE_INTERNALS_H_ + +// +// This is a stripped down shim to allow node_api.cc to build outside of the node source tree. +// + +#include "node_version.h" +#include "util-inl.h" +#include +#include +#include "uv.h" +#include "node.h" +#include + +// Windows 8+ does not like abort() in Release mode +#ifdef _WIN32 +#define ABORT_NO_BACKTRACE() raise(SIGABRT) +#else +#define ABORT_NO_BACKTRACE() abort() +#endif + +#define ABORT() node::Abort() + +#ifdef __GNUC__ +#define LIKELY(expr) __builtin_expect(!!(expr), 1) +#define UNLIKELY(expr) __builtin_expect(!!(expr), 0) +#define PRETTY_FUNCTION_NAME __PRETTY_FUNCTION__ +#else +#define LIKELY(expr) expr +#define UNLIKELY(expr) expr +#define PRETTY_FUNCTION_NAME "" +#endif + +#define STRINGIFY_(x) #x +#define STRINGIFY(x) STRINGIFY_(x) + +#define CHECK(expr) \ + do { \ + if (UNLIKELY(!(expr))) { \ + static const char* const args[] = { __FILE__, STRINGIFY(__LINE__), \ + #expr, PRETTY_FUNCTION_NAME }; \ + node::Assert(&args); \ + } \ + } while (0) + +#define CHECK_EQ(a, b) CHECK((a) == (b)) +#define CHECK_GE(a, b) CHECK((a) >= (b)) +#define CHECK_GT(a, b) CHECK((a) > (b)) +#define CHECK_LE(a, b) CHECK((a) <= (b)) +#define CHECK_LT(a, b) CHECK((a) < (b)) +#define CHECK_NE(a, b) CHECK((a) != (b)) + +#ifdef __GNUC__ +#define NO_RETURN __attribute__((noreturn)) +#else +#define NO_RETURN +#endif + +#ifndef NODE_RELEASE +#define NODE_RELEASE "node" +#endif + +#if NODE_MAJOR_VERSION < 8 || NODE_MAJOR_VERSION == 8 && NODE_MINOR_VERSION < 6 +class CallbackScope { + public: + CallbackScope(void *work); +}; +#endif // NODE_MAJOR_VERSION < 8 + +namespace node { + +// Copied from Node.js' src/node_persistent.h +template +struct ResetInDestructorPersistentTraits { + static const bool kResetInDestructor = true; + template + // Disallow copy semantics by leaving this unimplemented. + inline static void Copy( + const v8::Persistent&, + v8::Persistent>*); +}; + +// v8::Persistent does not reset the object slot in its destructor. That is +// acknowledged as a flaw in the V8 API and expected to change in the future +// but for now node::Persistent is the easier and safer alternative. +template +using Persistent = v8::Persistent>; + +#if NODE_MAJOR_VERSION < 8 || NODE_MAJOR_VERSION == 8 && NODE_MINOR_VERSION < 2 +typedef int async_id; + +typedef struct async_context { + node::async_id async_id; + node::async_id trigger_async_id; +} async_context; +#endif // NODE_MAJOR_VERSION < 8.2 + +#if NODE_MAJOR_VERSION < 8 || NODE_MAJOR_VERSION == 8 && NODE_MINOR_VERSION < 6 +NODE_EXTERN async_context EmitAsyncInit(v8::Isolate* isolate, + v8::Local resource, + v8::Local name, + async_id trigger_async_id = -1); + +NODE_EXTERN void EmitAsyncDestroy(v8::Isolate* isolate, + async_context asyncContext); + +v8::MaybeLocal MakeCallback(v8::Isolate* isolate, + v8::Local recv, + v8::Local callback, + int argc, + v8::Local* argv, + async_context asyncContext); + +#if NODE_MAJOR_VERSION < 8 +class AsyncResource { + public: + AsyncResource(v8::Isolate* isolate, + v8::Local object, + const char *name); +}; +#endif // node version below 8 + +#endif // node version below 8.6 + +// The slightly odd function signature for Assert() is to ease +// instruction cache pressure in calls from ASSERT and CHECK. +NO_RETURN void Abort(); +NO_RETURN void Assert(const char* const (*args)[4]); +void DumpBacktrace(FILE* fp); + +template +constexpr size_t arraysize(const T(&)[N]) { return N; } + +NO_RETURN void FatalError(const char* location, const char* message); + +} // namespace node + +#if NODE_MAJOR_VERSION < 8 +#define NewTarget This +#endif // NODE_MAJOR_VERSION < 8 + +#if NODE_MAJOR_VERSION < 6 +namespace v8 { + namespace Private { + v8::Local ForApi(v8::Isolate* isolate, v8::Local key); + } +} +#define GetPrivate(context, key) Get((context), (key)) +#define SetPrivate(context, key, value) \ + DefineOwnProperty((context), (key), (value), \ + static_cast(v8::DontEnum | \ + v8::DontDelete | \ + v8::ReadOnly)) +#endif // NODE_MAJOR_VERSION < 6 + +#endif // SRC_NODE_INTERNALS_H_ -- cgit v1.2.3