Skip to content

Commit 0b1ba20

Browse files
addaleaxMylesBorins
authored andcommitted
src: re-integrate headers into node.h
Alternative to #20938 (clean revert) and #20925 (adding the headers to the release tarball). The changes to `src/node.h` are a clean revert in the same ways as #20938 does it, the difference being that the new `.cc` files are kept here. This has the advantage of not being another large diff that other PRs will have to rebase against, especially since the split into `callback_scope.cc` and `exceptions.cc` is something that we want to keep in the long run. This essentialy implements bnoordhuis’s suggestion from #20925. PR-URL: #20939 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Refael Ackermann <refack@gmail.com>
1 parent 52f21fb commit 0b1ba20

File tree

7 files changed

+137
-174
lines changed

7 files changed

+137
-174
lines changed

node.gyp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,12 +365,10 @@
365365
'src/async_wrap-inl.h',
366366
'src/base_object.h',
367367
'src/base_object-inl.h',
368-
'src/callback_scope.h',
369368
'src/connection_wrap.h',
370369
'src/connect_wrap.h',
371370
'src/env.h',
372371
'src/env-inl.h',
373-
'src/exceptions.h',
374372
'src/handle_wrap.h',
375373
'src/js_stream.h',
376374
'src/module_wrap.h',

src/callback_scope.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include "node.h"
2-
#include "callback_scope.h"
32
#include "async_wrap.h"
43
#include "async_wrap-inl.h"
54
#include "env.h"

src/callback_scope.h

Lines changed: 0 additions & 47 deletions
This file was deleted.

src/core.h

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/exceptions.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#include "node_internals.h"
33
#include "env.h"
44
#include "env-inl.h"
5-
#include "exceptions.h"
65
#include "util.h"
76
#include "util-inl.h"
87
#include "v8.h"

src/exceptions.h

Lines changed: 0 additions & 76 deletions
This file was deleted.

src/node.h

Lines changed: 137 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@
2222
#ifndef SRC_NODE_H_
2323
#define SRC_NODE_H_
2424

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+
2535
#ifdef BUILDING_NODE_EXTENSION
2636
# undef BUILDING_V8_SHARED
2737
# undef BUILDING_UV_SHARED
@@ -50,12 +60,39 @@
5060
# define SIGKILL 9
5161
#endif
5262

53-
#include "core.h" // NOLINT(build/include_order)
5463
#include "v8.h" // NOLINT(build/include_order)
5564
#include "v8-platform.h" // NOLINT(build/include_order)
5665
#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
5996

6097
// Forward-declare libuv loop
6198
struct uv_loop_s;
@@ -69,6 +106,47 @@ class TracingController;
69106
// terminally confused when it's done in node_internals.h
70107
namespace node {
71108

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+
72150
/*
73151
* These methods need to be called in a HandleScope.
74152
*
@@ -373,6 +451,26 @@ NODE_DEPRECATED("Use DecodeWrite(isolate, ...)",
373451
return DecodeWrite(v8::Isolate::GetCurrent(), buf, buflen, val, encoding);
374452
})
375453

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+
376474
const char *signo_string(int errorno);
377475

378476

@@ -495,6 +593,12 @@ typedef void (*promise_hook_func) (v8::PromiseHookType type,
495593
v8::Local<v8::Value> parent,
496594
void* arg);
497595

596+
typedef double async_id;
597+
struct async_context {
598+
::node::async_id async_id;
599+
::node::async_id trigger_async_id;
600+
};
601+
498602
/* Registers an additional v8::PromiseHook wrapper. This API exists because V8
499603
* itself supports only a single PromiseHook. */
500604
NODE_EXTERN void AddPromiseHook(v8::Isolate* isolate,
@@ -543,6 +647,36 @@ NODE_EXTERN async_context EmitAsyncInit(v8::Isolate* isolate,
543647
NODE_EXTERN void EmitAsyncDestroy(v8::Isolate* isolate,
544648
async_context asyncContext);
545649

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+
546680
/* An API specific to emit before/after callbacks is unnecessary because
547681
* MakeCallback will automatically call them for you.
548682
*

0 commit comments

Comments
 (0)