22
22
#ifndef SRC_NODE_H_
23
23
#define SRC_NODE_H_
24
24
25
+ #ifdef _WIN32
26
+ # ifndef BUILDING_NODE_EXTENSION
27
+ # define NODE_EXTERN __declspec (dllexport)
28
+ # else
29
+ # define NODE_EXTERN __declspec (dllimport)
30
+ # endif
31
+ #else
32
+ # define NODE_EXTERN /* nothing */
33
+ #endif
34
+
25
35
#ifdef BUILDING_NODE_EXTENSION
26
36
# undef BUILDING_V8_SHARED
27
37
# undef BUILDING_UV_SHARED
50
60
# define SIGKILL 9
51
61
#endif
52
62
53
- #include " core.h" // NOLINT(build/include_order)
54
63
#include " v8.h" // NOLINT(build/include_order)
55
64
#include " v8-platform.h" // NOLINT(build/include_order)
56
65
#include " node_version.h" // NODE_MODULE_VERSION
57
- #include " callback_scope.h"
58
- #include " exceptions.h"
66
+
67
+ #define NODE_MAKE_VERSION (major, minor, patch ) \
68
+ ((major) * 0x1000 + (minor) * 0x100 + (patch))
69
+
70
+ #ifdef __clang__
71
+ # define NODE_CLANG_AT_LEAST (major, minor, patch ) \
72
+ (NODE_MAKE_VERSION(major, minor, patch) <= \
73
+ NODE_MAKE_VERSION (__clang_major__, __clang_minor__, __clang_patchlevel__))
74
+ #else
75
+ # define NODE_CLANG_AT_LEAST (major, minor, patch ) (0 )
76
+ #endif
77
+
78
+ #ifdef __GNUC__
79
+ # define NODE_GNUC_AT_LEAST (major, minor, patch ) \
80
+ (NODE_MAKE_VERSION(major, minor, patch) <= \
81
+ NODE_MAKE_VERSION (__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__))
82
+ #else
83
+ # define NODE_GNUC_AT_LEAST (major, minor, patch ) (0 )
84
+ #endif
85
+
86
+ #if NODE_CLANG_AT_LEAST(2, 9, 0) || NODE_GNUC_AT_LEAST(4, 5, 0)
87
+ # define NODE_DEPRECATED (message, declarator ) \
88
+ __attribute__ ((deprecated(message))) declarator
89
+ #elif defined(_MSC_VER)
90
+ # define NODE_DEPRECATED (message, declarator ) \
91
+ __declspec (deprecated) declarator
92
+ #else
93
+ # define NODE_DEPRECATED (message, declarator ) \
94
+ declarator
95
+ #endif
59
96
60
97
// Forward-declare libuv loop
61
98
struct uv_loop_s ;
@@ -69,6 +106,47 @@ class TracingController;
69
106
// terminally confused when it's done in node_internals.h
70
107
namespace node {
71
108
109
+ NODE_EXTERN v8::Local<v8::Value> ErrnoException (v8::Isolate* isolate,
110
+ int errorno,
111
+ const char * syscall = nullptr ,
112
+ const char * message = nullptr ,
113
+ const char * path = nullptr );
114
+ NODE_EXTERN v8::Local<v8::Value> UVException (v8::Isolate* isolate,
115
+ int errorno,
116
+ const char * syscall = nullptr ,
117
+ const char * message = nullptr ,
118
+ const char * path = nullptr );
119
+ NODE_EXTERN v8::Local<v8::Value> UVException (v8::Isolate* isolate,
120
+ int errorno,
121
+ const char * syscall,
122
+ const char * message,
123
+ const char * path,
124
+ const char * dest);
125
+
126
+ NODE_DEPRECATED (" Use ErrnoException(isolate, ...)" ,
127
+ inline v8::Local<v8::Value> ErrnoException (
128
+ int errorno,
129
+ const char * syscall = nullptr ,
130
+ const char * message = nullptr ,
131
+ const char * path = nullptr ) {
132
+ return ErrnoException (v8::Isolate::GetCurrent (),
133
+ errorno,
134
+ syscall,
135
+ message,
136
+ path);
137
+ })
138
+
139
+ inline v8::Local<v8::Value> UVException (int errorno,
140
+ const char * syscall = nullptr ,
141
+ const char * message = nullptr ,
142
+ const char * path = nullptr ) {
143
+ return UVException (v8::Isolate::GetCurrent (),
144
+ errorno,
145
+ syscall,
146
+ message,
147
+ path);
148
+ }
149
+
72
150
/*
73
151
* These methods need to be called in a HandleScope.
74
152
*
@@ -373,6 +451,26 @@ NODE_DEPRECATED("Use DecodeWrite(isolate, ...)",
373
451
return DecodeWrite (v8::Isolate::GetCurrent (), buf, buflen, val, encoding);
374
452
})
375
453
454
+ #ifdef _WIN32
455
+ NODE_EXTERN v8::Local<v8::Value> WinapiErrnoException (
456
+ v8::Isolate* isolate,
457
+ int errorno,
458
+ const char *syscall = nullptr ,
459
+ const char *msg = " " ,
460
+ const char *path = nullptr );
461
+
462
+ NODE_DEPRECATED (" Use WinapiErrnoException(isolate, ...)" ,
463
+ inline v8::Local<v8::Value> WinapiErrnoException (int errorno,
464
+ const char *syscall = nullptr , const char *msg = " " ,
465
+ const char *path = nullptr ) {
466
+ return WinapiErrnoException (v8::Isolate::GetCurrent (),
467
+ errorno,
468
+ syscall,
469
+ msg,
470
+ path);
471
+ })
472
+ #endif
473
+
376
474
const char *signo_string (int errorno);
377
475
378
476
@@ -495,6 +593,12 @@ typedef void (*promise_hook_func) (v8::PromiseHookType type,
495
593
v8::Local<v8::Value> parent,
496
594
void * arg);
497
595
596
+ typedef double async_id;
597
+ struct async_context {
598
+ ::node::async_id async_id;
599
+ ::node::async_id trigger_async_id;
600
+ };
601
+
498
602
/* Registers an additional v8::PromiseHook wrapper. This API exists because V8
499
603
* itself supports only a single PromiseHook. */
500
604
NODE_EXTERN void AddPromiseHook (v8::Isolate* isolate,
@@ -543,6 +647,36 @@ NODE_EXTERN async_context EmitAsyncInit(v8::Isolate* isolate,
543
647
NODE_EXTERN void EmitAsyncDestroy (v8::Isolate* isolate,
544
648
async_context asyncContext);
545
649
650
+ class InternalCallbackScope ;
651
+
652
+ /* This class works like `MakeCallback()` in that it sets up a specific
653
+ * asyncContext as the current one and informs the async_hooks and domains
654
+ * modules that this context is currently active.
655
+ *
656
+ * `MakeCallback()` is a wrapper around this class as well as
657
+ * `Function::Call()`. Either one of these mechanisms needs to be used for
658
+ * top-level calls into JavaScript (i.e. without any existing JS stack).
659
+ *
660
+ * This object should be stack-allocated to ensure that it is contained in a
661
+ * valid HandleScope.
662
+ */
663
+ class NODE_EXTERN CallbackScope {
664
+ public:
665
+ CallbackScope (v8::Isolate* isolate,
666
+ v8::Local<v8::Object> resource,
667
+ async_context asyncContext);
668
+ ~CallbackScope ();
669
+
670
+ private:
671
+ InternalCallbackScope* private_;
672
+ v8::TryCatch try_catch_;
673
+
674
+ void operator =(const CallbackScope&) = delete ;
675
+ void operator =(CallbackScope&&) = delete ;
676
+ CallbackScope (const CallbackScope&) = delete ;
677
+ CallbackScope (CallbackScope&&) = delete ;
678
+ };
679
+
546
680
/* An API specific to emit before/after callbacks is unnecessary because
547
681
* MakeCallback will automatically call them for you.
548
682
*
0 commit comments