26 # ifndef BUILDING_NODE_EXTENSION 27 # define NODE_EXTERN __declspec(dllexport) 29 # define NODE_EXTERN __declspec(dllimport) 35 #ifdef BUILDING_NODE_EXTENSION 36 # undef BUILDING_V8_SHARED 37 # undef BUILDING_UV_SHARED 38 # define USING_V8_SHARED 1 39 # define USING_UV_SHARED 1 44 #if defined(__MINGW32__) || defined(_MSC_VER) 46 # define _WIN32_WINNT 0x0501 56 #define PATH_MAX MAX_PATH 66 #define NODE_MAKE_VERSION(major, minor, patch) \ 67 ((major) * 0x1000 + (minor) * 0x100 + (patch)) 70 # define NODE_CLANG_AT_LEAST(major, minor, patch) \ 71 (NODE_MAKE_VERSION(major, minor, patch) <= \ 72 NODE_MAKE_VERSION(__clang_major__, __clang_minor__, __clang_patchlevel__)) 74 # define NODE_CLANG_AT_LEAST(major, minor, patch) (0) 78 # define NODE_GNUC_AT_LEAST(major, minor, patch) \ 79 (NODE_MAKE_VERSION(major, minor, patch) <= \ 80 NODE_MAKE_VERSION(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__)) 82 # define NODE_GNUC_AT_LEAST(major, minor, patch) (0) 85 #if NODE_CLANG_AT_LEAST(2, 9, 0) || NODE_GNUC_AT_LEAST(4, 5, 0) 86 # define NODE_DEPRECATED(message, declarator) \ 87 __attribute__((deprecated(message))) declarator 88 #elif defined(_MSC_VER) 89 # define NODE_DEPRECATED(message, declarator) \ 90 __declspec(deprecated) declarator 92 # define NODE_DEPRECATED(message, declarator) \ 105 const char* syscall = NULL,
106 const char* message = NULL,
107 const char* path = NULL);
110 const char* syscall = NULL,
111 const char* message = NULL,
112 const char* path = NULL);
123 const char* syscall = NULL,
124 const char* message = NULL,
125 const char* path = NULL) {
133 inline v8::Local<v8::Value>
UVException(
int errorno,
134 const char* syscall = NULL,
135 const char* message = NULL,
136 const char* path = NULL) {
152 v8::Isolate* isolate,
153 v8::Local<v8::Object> recv,
156 v8::Local<v8::Value>* argv);
158 v8::Isolate* isolate,
159 v8::Local<v8::Object> recv,
160 v8::Local<v8::String> symbol,
162 v8::Local<v8::Value>* argv);
164 v8::Isolate* isolate,
165 v8::Local<v8::Object> recv,
166 v8::Local<v8::Function> callback,
168 v8::Local<v8::Value>* argv);
172 #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS 179 #ifndef NODE_STRINGIFY 180 #define NODE_STRINGIFY(n) NODE_STRINGIFY_HELPER(n) 181 #define NODE_STRINGIFY_HELPER(n) #n 186 #if !defined(_SSIZE_T_) && !defined(_SSIZE_T_DEFINED) 187 typedef intptr_t ssize_t;
189 # define _SSIZE_T_DEFINED 192 # include <sys/types.h> 211 const char*** exec_argv);
217 struct uv_loop_s* loop);
221 v8::Local<v8::Context> context,
223 const char*
const* argv,
225 const char*
const* exec_argv);
235 #define NODE_UNIXTIME_V8(t) v8::Date::New(v8::Isolate::GetCurrent(), \ 236 1000 * static_cast<double>(t)) 237 #define NODE_V8_UNIXTIME(v) (static_cast<double>((v)->NumberValue())/1000.0); 239 #define NODE_DEFINE_CONSTANT(target, constant) \ 241 v8::Isolate* isolate = target->GetIsolate(); \ 242 v8::Local<v8::Context> context = isolate->GetCurrentContext(); \ 243 v8::Local<v8::String> constant_name = \ 244 v8::String::NewFromUtf8(isolate, #constant); \ 245 v8::Local<v8::Number> constant_value = \ 246 v8::Number::New(isolate, static_cast<double>(constant)); \ 247 v8::PropertyAttribute constant_attributes = \ 248 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete); \ 249 (target)->DefineOwnProperty(context, \ 252 constant_attributes).FromJust(); \ 256 #define NODE_DEFINE_HIDDEN_CONSTANT(target, constant) \ 258 v8::Isolate* isolate = target->GetIsolate(); \ 259 v8::Local<v8::Context> context = isolate->GetCurrentContext(); \ 260 v8::Local<v8::String> constant_name = \ 261 v8::String::NewFromUtf8(isolate, #constant, \ 262 v8::NewStringType::kInternalized) \ 264 v8::Local<v8::Number> constant_value = \ 265 v8::Number::New(isolate, static_cast<double>(constant)); \ 266 v8::PropertyAttribute constant_attributes = \ 267 static_cast<v8::PropertyAttribute>(v8::ReadOnly | \ 270 (target)->DefineOwnProperty(context, \ 273 constant_attributes).FromJust(); \ 280 v8::FunctionCallback callback) {
281 v8::Isolate* isolate = v8::Isolate::GetCurrent();
282 v8::HandleScope handle_scope(isolate);
285 v8::Local<v8::String> fn_name = v8::String::NewFromUtf8(isolate, name);
286 t->SetClassName(fn_name);
287 recv->Set(fn_name, t);
293 v8::FunctionCallback callback) {
294 v8::Isolate* isolate = v8::Isolate::GetCurrent();
295 v8::HandleScope handle_scope(isolate);
298 v8::Local<v8::Function> fn = t->GetFunction();
299 v8::Local<v8::String> fn_name = v8::String::NewFromUtf8(isolate, name);
300 fn->SetName(fn_name);
301 recv->Set(fn_name, fn);
303 #define NODE_SET_METHOD node::NODE_SET_METHOD 309 v8::FunctionCallback callback) {
310 v8::Isolate* isolate = v8::Isolate::GetCurrent();
311 v8::HandleScope handle_scope(isolate);
313 v8::Local<v8::FunctionTemplate>
t =
315 v8::Local<v8::String> fn_name = v8::String::NewFromUtf8(isolate, name);
316 t->SetClassName(fn_name);
317 recv->PrototypeTemplate()->Set(fn_name, t);
319 #define NODE_SET_PROTOTYPE_METHOD node::NODE_SET_PROTOTYPE_METHOD 325 v8::Isolate* isolate,
326 v8::Local<v8::Value> encoding_v,
330 v8::Local<v8::Value> encoding_v,
332 return ParseEncoding(v8::Isolate::GetCurrent(), encoding_v, default_encoding);
336 const v8::TryCatch& try_catch);
355 inline v8::Local<v8::Value>
Encode(
359 v8::Isolate* isolate = v8::Isolate::GetCurrent();
361 assert(reinterpret_cast<uintptr_t>(buf) %
sizeof(uint16_t) == 0 &&
362 "UCS2 buffer must be aligned on two-byte boundary.");
363 const uint16_t* that =
static_cast<const uint16_t*
>(
buf);
364 return Encode(isolate, that, len /
sizeof(*that));
366 return Encode(isolate, static_cast<const char*>(buf), len,
encoding);
371 v8::Local<v8::Value>,
375 v8::Local<v8::Value> val,
384 v8::Local<v8::Value>,
389 v8::Local<v8::Value> val,
395 NODE_EXTERN v8::Local<v8::Value> WinapiErrnoException(
396 v8::Isolate* isolate,
398 const char *syscall = NULL,
399 const char *msg =
"",
400 const char *path = NULL);
403 inline v8::Local<v8::Value> WinapiErrnoException(
int errorno,
404 const char *syscall = NULL,
const char *msg =
"",
405 const char *path = NULL) {
406 return WinapiErrnoException(v8::Isolate::GetCurrent(),
418 v8::Local<v8::Object> exports,
419 v8::Local<v8::Value> module,
423 v8::Local<v8::Object> exports,
424 v8::Local<v8::Value> module,
425 v8::Local<v8::Context> context,
428 #define NM_F_BUILTIN 0x01 429 #define NM_F_LINKED 0x02 449 # define NODE_MODULE_EXPORT __declspec(dllexport) 451 # define NODE_MODULE_EXPORT __attribute__((visibility("default"))) 454 #ifdef NODE_SHARED_MODE 455 # define NODE_CTOR_PREFIX 457 # define NODE_CTOR_PREFIX static 460 #if defined(_MSC_VER) 461 #pragma section(".CRT$XCU", read) 462 #define NODE_C_CTOR(fn) \ 463 NODE_CTOR_PREFIX void __cdecl fn(void); \ 464 __declspec(dllexport, allocate(".CRT$XCU")) \ 465 void (__cdecl*fn ## _)(void) = fn; \ 466 NODE_CTOR_PREFIX void __cdecl fn(void) 468 #define NODE_C_CTOR(fn) \ 469 NODE_CTOR_PREFIX void fn(void) __attribute__((constructor)); \ 470 NODE_CTOR_PREFIX void fn(void) 473 #define NODE_MODULE_X(modname, regfunc, priv, flags) \ 475 static node::node_module _module = \ 477 NODE_MODULE_VERSION, \ 481 (node::addon_register_func) (regfunc), \ 483 NODE_STRINGIFY(modname), \ 487 NODE_C_CTOR(_register_ ## modname) { \ 488 node_module_register(&_module); \ 492 #define NODE_MODULE_CONTEXT_AWARE_X(modname, regfunc, priv, flags) \ 494 static node::node_module _module = \ 496 NODE_MODULE_VERSION, \ 501 (node::addon_context_register_func) (regfunc), \ 502 NODE_STRINGIFY(modname), \ 506 NODE_C_CTOR(_register_ ## modname) { \ 507 node_module_register(&_module); \ 511 #define NODE_MODULE(modname, regfunc) \ 512 NODE_MODULE_X(modname, regfunc, NULL, 0) 514 #define NODE_MODULE_CONTEXT_AWARE(modname, regfunc) \ 515 NODE_MODULE_CONTEXT_AWARE_X(modname, regfunc, NULL, 0) 517 #define NODE_MODULE_CONTEXT_AWARE_BUILTIN(modname, regfunc) \ 518 NODE_MODULE_CONTEXT_AWARE_X(modname, regfunc, NULL, NM_F_BUILTIN) \ 523 #define NODE_MODULE_DECL 537 v8::Local<v8::Promise> promise,
538 v8::Local<v8::Value> parent,
547 NODE_DEPRECATED(
"Use async_context directly as returned by EmitAsyncInit()",
579 v8::Local<v8::Object> resource,
581 async_id trigger_async_id);
584 #define EmitAsyncInit EmitAsyncInit__New 594 v8::Local<v8::Object> resource,
596 async_id trigger_async_id = -1);
600 async_context asyncContext);
613 v8::MaybeLocal<v8::Value>
MakeCallback(v8::Isolate* isolate,
614 v8::Local<v8::Object> recv,
615 v8::Local<v8::Function> callback,
617 v8::Local<v8::Value>* argv,
618 async_context asyncContext);
620 v8::MaybeLocal<v8::Value>
MakeCallback(v8::Isolate* isolate,
621 v8::Local<v8::Object> recv,
624 v8::Local<v8::Value>* argv,
625 async_context asyncContext);
627 v8::MaybeLocal<v8::Value>
MakeCallback(v8::Isolate* isolate,
628 v8::Local<v8::Object> recv,
629 v8::Local<v8::String> symbol,
631 v8::Local<v8::Value>* argv,
632 async_context asyncContext);
637 NODE_DEPRECATED(
"Use MakeCallback(..., async_context asyncContext) instead",
638 v8::MaybeLocal<v8::Value>
MakeCallback(v8::Isolate* isolate,
639 v8::Local<v8::Object> recv,
640 v8::Local<v8::Function> callback,
642 v8::Local<v8::Value>* argv,
644 async_id triggerAsyncId));
646 NODE_DEPRECATED(
"Use MakeCallback(..., async_context asyncContext) instead",
647 v8::MaybeLocal<v8::Value>
MakeCallback(v8::Isolate* isolate,
648 v8::Local<v8::Object> recv,
651 v8::Local<v8::Value>* argv,
653 async_id triggerAsyncId));
655 NODE_DEPRECATED(
"Use MakeCallback(..., async_context asyncContext) instead",
656 v8::MaybeLocal<v8::Value>
MakeCallback(v8::Isolate* isolate,
657 v8::Local<v8::Object> recv,
658 v8::Local<v8::String> symbol,
660 v8::Local<v8::Value>* argv,
662 async_id triggerAsyncId));
670 v8::Local<v8::Object> resource,
672 async_id trigger_async_id = -1)
674 resource_(isolate, resource) {
684 v8::Local<v8::Function> callback,
686 v8::Local<v8::Value>* argv) {
688 callback, argc, argv,
695 v8::Local<v8::Value>* argv) {
702 v8::Local<v8::String> symbol,
704 v8::Local<v8::Value>* argv) {
711 return resource_.Get(isolate_);
715 async_id get_uid()
const {
716 return get_async_id();
720 async_id get_async_id()
const {
721 return async_context_.async_id;
725 return async_context_.trigger_async_id;
728 v8::Isolate* isolate_;
729 v8::Persistent<v8::Object> resource_;
735 #endif // SRC_NODE_H_
void FreeEnvironment(Environment *env)
void EmitBeforeExit(Environment *env)
void NODE_SET_METHOD(v8::Local< v8::Template > recv, const char *name, v8::FunctionCallback callback)
v8::MaybeLocal< v8::Value > MakeCallback(v8::Local< v8::Function > callback, int argc, v8::Local< v8::Value > *argv)
ssize_t DecodeWrite(Isolate *isolate, char *buf, size_t buflen, Local< Value > val, enum encoding encoding)
async_id AsyncHooksGetTriggerId(Isolate *isolate)
struct node_module * nm_link
v8::Local< v8::Object > get_resource()
int EmitExit(Environment *env)
ssize_t DecodeBytes(Isolate *isolate, Local< Value > val, enum encoding encoding)
void FatalException(Isolate *isolate, Local< Value > error, Local< Message > message)
IsolateData * CreateIsolateData(Isolate *isolate, uv_loop_t *loop)
async_context EmitAsyncInit(Isolate *isolate, Local< Object > resource, const char *name, async_id trigger_async_id)
void node_module_register(void *m)
void AtExit(void(*cb)(void *arg), void *arg)
async_id get_trigger_async_id() const
NODE_DEPRECATED("Use Encode(isolate, ...)", inline v8::Local< v8::Value > Encode(const void *buf, size_t len, enum encoding encoding=LATIN1) { v8::Isolate *isolate=v8::Isolate::GetCurrent();if(encoding==UCS2) { assert(reinterpret_cast< uintptr_t >(buf) % sizeof(uint16_t)==0 &&"UCS2 buffer must be aligned on two-byte boundary.");const uint16_t *that=static_cast< const uint16_t * >(buf);return Encode(isolate, that, len/sizeof(*that));} return Encode(isolate, static_cast< const char * >(buf), len, encoding);}) NODE_EXTERN ssize_t DecodeBytes(v8 NODE_DEPRECATED("Use DecodeBytes(isolate, ...)", inline ssize_t DecodeBytes(v8::Local< v8::Value > val, enum encoding encoding=LATIN1) { return DecodeBytes(v8::Isolate::GetCurrent(), val, encoding);}) NODE_EXTERN ssize_t DecodeWrite(v8 NODE_DEPRECATED("Use DecodeWrite(isolate, ...)", inline ssize_t DecodeWrite(char *buf, size_t buflen, v8::Local< v8::Value > val, enum encoding encoding=LATIN1) { return DecodeWrite(v8::Isolate::GetCurrent(), buf, buflen, val, encoding);}) const char *signo_string(int errorno)
void AddPromiseHook(v8::Isolate *isolate, promise_hook_func fn, void *arg)
void FreeIsolateData(IsolateData *isolate_data)
async_id AsyncHooksGetExecutionAsyncId(Isolate *isolate)
Local< Value > ErrnoException(Isolate *isolate, int errorno, const char *syscall, const char *msg, const char *path)
Environment * CreateEnvironment(IsolateData *isolate_data, Local< Context > context, int argc, const char *const *argv, int exec_argc, const char *const *exec_argv)
const char * signo_string(int signo)
node::addon_context_register_func nm_context_register_func
void(* addon_register_func)(v8::Local< v8::Object > exports, v8::Local< v8::Value > module, void *priv)
struct node_module * get_linked_module(const char *name)
v8::MaybeLocal< v8::Value > MakeCallback(v8::Local< v8::String > symbol, int argc, v8::Local< v8::Value > *argv)
void(* addon_context_register_func)(v8::Local< v8::Object > exports, v8::Local< v8::Value > module, v8::Local< v8::Context > context, void *priv)
enum encoding ParseEncoding(const char *encoding, enum encoding default_encoding)
void EmitAsyncDestroy(Isolate *isolate, async_context asyncContext)
::node::async_id trigger_async_id
::node::async_id async_id
node::addon_register_func nm_register_func
async_id AsyncHooksGetCurrentId(Isolate *isolate)
MaybeLocal< Object > New(Isolate *isolate, Local< String > string, enum encoding enc)
void(* promise_hook_func)(v8::PromiseHookType type, v8::Local< v8::Promise > promise, v8::Local< v8::Value > parent, void *arg)
MaybeLocal< Value > MakeCallback(Isolate *isolate, Local< Object > recv, Local< Function > callback, int argc, Local< Value > *argv, async_id asyncId, async_id triggerAsyncId)
NODE_DEPRECATED("Use AsyncResource::get_async_id()", async_id get_uid() const { return get_async_id();}) async_id get_async_id() const
struct node_module * get_builtin_module(const char *name)
int Start(Isolate *isolate, IsolateData *isolate_data, int argc, const char *const *argv, int exec_argc, const char *const *exec_argv)
v8::MaybeLocal< v8::Value > MakeCallback(const char *method, int argc, v8::Local< v8::Value > *argv)
void Init(int *argc, const char **argv, int *exec_argc, const char ***exec_argv)
void NODE_SET_PROTOTYPE_METHOD(v8::Local< v8::FunctionTemplate > recv, const char *name, v8::FunctionCallback callback)
async_id AsyncHooksGetTriggerAsyncId(Isolate *isolate)
NODE_DEPRECATED("Use ParseEncoding(isolate, ...)", inline enum encoding ParseEncoding(v8::Local< v8::Value > encoding_v, enum encoding default_encoding=LATIN1) { return ParseEncoding(v8::Isolate::GetCurrent(), encoding_v, default_encoding);}) NODE_EXTERN void FatalException(v8 NODE_DEPRECATED("Use FatalException(isolate, ...)", inline void FatalException(const v8::TryCatch &try_catch) { return FatalException(v8::Isolate::GetCurrent(), try_catch);}) NODE_EXTERN v8 NODE_EXTERN v8::Local< v8::Value > Encode(v8::Isolate *isolate, const uint16_t *buf, size_t len)
AsyncResource(v8::Isolate *isolate, v8::Local< v8::Object > resource, const char *name, async_id trigger_async_id=-1)
Local< Value > UVException(Isolate *isolate, int errorno, const char *syscall, const char *msg, const char *path)
void RunAtExit(Environment *env)
void LoadEnvironment(Environment *env)