src: reduce includes of node_internals.h

PR-URL: https://github.com/nodejs/node/pull/25507
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Joyee Cheung 2019-01-13 17:17:26 +08:00 committed by Daniel Bevenius
parent 8b2e861da1
commit 1838d00eba
54 changed files with 153 additions and 158 deletions

View File

@ -22,7 +22,6 @@
#include "async_wrap-inl.h"
#include "env-inl.h"
#include "node_errors.h"
#include "node_internals.h"
#include "tracing/traced_value.h"
#include "util-inl.h"

View File

@ -24,7 +24,6 @@
#include "async_wrap-inl.h"
#include "env-inl.h"
#include "node.h"
#include "node_internals.h"
#include "req_wrap-inl.h"
#include "util-inl.h"
#include "uv.h"

View File

@ -3,7 +3,6 @@
#include "connect_wrap.h"
#include "env-inl.h"
#include "pipe_wrap.h"
#include "node_internals.h"
#include "stream_base-inl.h"
#include "stream_wrap.h"
#include "tcp_wrap.h"

View File

@ -1,5 +1,4 @@
#include "debug_utils.h"
#include "node_internals.h"
#ifdef __POSIX__
#if defined(__linux__)

View File

@ -4,9 +4,10 @@
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
#include "async_wrap.h"
#include "env.h"
#include <string>
#include "env-inl.h"
#include <sstream>
#include <string>
// Use FORCE_INLINE on functions that have a debug-category-enabled check first
// and then ideally only a single function call following it, to maintain

View File

@ -23,7 +23,6 @@
#include "env-inl.h"
#include "util-inl.h"
#include "node.h"
#include "node_internals.h"
#include "handle_wrap.h"
#include "string_bytes.h"

View File

@ -1,5 +1,4 @@
#include "node_internals.h"
#include "env.h"
#include "env-inl.h"
using v8::Array;
using v8::Boolean;

View File

@ -1,7 +1,6 @@
#include "base_object-inl.h"
#include "inspector_agent.h"
#include "inspector_io.h"
#include "node_internals.h"
#include "v8.h"
#include "v8-inspector.h"

View File

@ -4,7 +4,6 @@
#include "env-inl.h"
#include "node_buffer.h"
#include "node_errors.h"
#include "node_internals.h"
#include "stream_base-inl.h"
#include "v8.h"

View File

@ -7,7 +7,6 @@
#include "node_errors.h"
#include "node_url.h"
#include "util-inl.h"
#include "node_internals.h"
#include "node_contextify.h"
#include "node_watchdog.h"

View File

@ -1,6 +1,7 @@
#include "node_binding.h"
#include "node_internals.h"
#include "env-inl.h"
#include "node_native_module.h"
#include "util.h"
#if HAVE_OPENSSL
#define NODE_BUILTIN_OPENSSL_MODULES(V) V(crypto) V(tls_wrap)

View File

@ -19,9 +19,10 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "node.h"
#include "node_buffer.h"
#include "node.h"
#include "node_errors.h"
#include "node_internals.h"
#include "env-inl.h"
#include "string_bytes.h"

View File

@ -6,7 +6,6 @@
#include "base_object-inl.h"
#include "node_context_data.h"
#include "node_errors.h"
#include "node_internals.h"
namespace node {
namespace contextify {

View File

@ -27,7 +27,6 @@
#include "node_crypto_clienthello-inl.h"
#include "node_crypto_groups.h"
#include "node_errors.h"
#include "node_internals.h"
#include "node_mutex.h"
#include "node_process.h"
#include "tls_wrap.h" // TLSWrap

View File

@ -1,5 +1,5 @@
#include "env-inl.h"
#include "v8.h"
#include "node_internals.h"
namespace node {
namespace domain {

View File

@ -43,7 +43,6 @@
#endif
#include "node_errors.h"
#include "node_internals.h"
#include <string.h>

View File

@ -24,7 +24,8 @@
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
#include "node_internals.h"
#include "env.h"
#include "v8.h"
extern "C" {
/*

View File

@ -1,6 +1,6 @@
#include "node_errors.h"
#include "node_internals.h"
#include "node_process.h"
#include "util.h"
#ifdef __APPLE__
#include <crt_externs.h>

View File

@ -22,9 +22,9 @@
#include "node_file.h"
#include "aliased_buffer.h"
#include "node_buffer.h"
#include "node_internals.h"
#include "node_process.h"
#include "node_stat_watcher.h"
#include "util.h"
#include "tracing/trace_event.h"

View File

@ -4,8 +4,8 @@
#include "node_buffer.h"
#include "node_http2.h"
#include "node_http2_state.h"
#include "node_internals.h"
#include "node_perf.h"
#include "util.h"
#include <algorithm>

View File

@ -3,7 +3,10 @@
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
// FIXME(joyeecheung): nghttp2.h needs stdint.h to compile on Windows
#include <stdint.h>
#include "nghttp2/nghttp2.h"
#include "node_http2_state.h"
#include "node_perf.h"
#include "stream_base-inl.h"

View File

@ -27,7 +27,7 @@
#include "node.h"
#include "node_buffer.h"
#include "node_internals.h"
#include "util.h"
#include "async_wrap-inl.h"
#include "env-inl.h"

View File

@ -44,12 +44,13 @@
#if defined(NODE_HAVE_I18N_SUPPORT)
#include "base_object-inl.h"
#include "env-inl.h"
#include "node.h"
#include "node_buffer.h"
#include "node_errors.h"
#include "env-inl.h"
#include "node_internals.h"
#include "util-inl.h"
#include "base_object-inl.h"
#include "v8.h"
#include <unicode/utypes.h>

View File

@ -24,7 +24,8 @@
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
#include "node_internals.h"
#include "util.h"
#include <string>
#if defined(NODE_HAVE_I18N_SUPPORT)

View File

@ -44,39 +44,9 @@
#define Z_MIN_WINDOWBITS 8
#define Z_MAX_WINDOWBITS 15
#define Z_DEFAULT_WINDOWBITS 15
// Fewer than 64 bytes per chunk is not recommended.
// Technically it could work with as few as 8, but even 64 bytes
// is low. Usually a MB or more is best.
#define Z_MIN_CHUNK 64
#define Z_MAX_CHUNK std::numeric_limits<double>::infinity()
#define Z_DEFAULT_CHUNK (16 * 1024)
#define Z_MIN_MEMLEVEL 1
#define Z_MAX_MEMLEVEL 9
#define Z_DEFAULT_MEMLEVEL 8
#define Z_MIN_LEVEL -1
#define Z_MAX_LEVEL 9
#define Z_DEFAULT_LEVEL Z_DEFAULT_COMPRESSION
struct sockaddr;
// Variation on NODE_DEFINE_CONSTANT that sets a String value.
#define NODE_DEFINE_STRING_CONSTANT(target, name, constant) \
do { \
v8::Isolate* isolate = target->GetIsolate(); \
v8::Local<v8::String> constant_name = \
v8::String::NewFromUtf8(isolate, name, v8::NewStringType::kNormal) \
.ToLocalChecked(); \
v8::Local<v8::String> constant_value = \
v8::String::NewFromUtf8(isolate, constant, v8::NewStringType::kNormal)\
.ToLocalChecked(); \
v8::PropertyAttribute constant_attributes = \
static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete); \
target->DefineOwnProperty(isolate->GetCurrentContext(), \
constant_name, \
constant_value, \
constant_attributes).FromJust(); \
} while (0)
namespace node {
namespace native_module {
@ -126,80 +96,10 @@ void RegisterSignalHandler(int signal,
std::string GetHumanReadableProcessName();
void GetHumanReadableProcessName(char (*name)[1024]);
template <typename T, size_t N>
constexpr size_t arraysize(const T(&)[N]) { return N; }
#ifndef ROUND_UP
# define ROUND_UP(a, b) ((a) % (b) ? ((a) + (b)) - ((a) % (b)) : (a))
#endif
#ifdef __GNUC__
# define MUST_USE_RESULT __attribute__((warn_unused_result))
#else
# define MUST_USE_RESULT
#endif
class SlicedArguments {
public:
inline explicit SlicedArguments(
const v8::FunctionCallbackInfo<v8::Value>& args,
size_t start = 0);
inline size_t size() const { return size_; }
inline v8::Local<v8::Value>* data() { return data_; }
private:
size_t size_;
v8::Local<v8::Value>* data_;
v8::Local<v8::Value> fixed_[64];
std::vector<v8::Local<v8::Value>> dynamic_;
};
SlicedArguments::SlicedArguments(
const v8::FunctionCallbackInfo<v8::Value>& args,
size_t start) : size_(0), data_(fixed_) {
const size_t length = static_cast<size_t>(args.Length());
if (start >= length) return;
const size_t size = length - start;
if (size > arraysize(fixed_)) {
dynamic_.resize(size);
data_ = dynamic_.data();
}
for (size_t i = 0; i < size; ++i)
data_[i] = args[i + start];
size_ = size;
}
namespace task_queue {
void PromiseRejectCallback(v8::PromiseRejectMessage message);
} // namespace task_queue
enum Endianness {
kLittleEndian, // _Not_ LITTLE_ENDIAN, clashes with endian.h.
kBigEndian
};
inline enum Endianness GetEndianness() {
// Constant-folded by the compiler.
const union {
uint8_t u8[2];
uint16_t u16;
} u = {
{ 1, 0 }
};
return u.u16 == 1 ? kLittleEndian : kBigEndian;
}
inline bool IsLittleEndian() {
return GetEndianness() == kLittleEndian;
}
inline bool IsBigEndian() {
return GetEndianness() == kBigEndian;
}
class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
public:
inline uint32_t* zero_fill_field() { return &zero_fill_field_; }

View File

@ -4,7 +4,6 @@
#include "debug_utils.h"
#include "node_buffer.h"
#include "node_errors.h"
#include "node_internals.h"
#include "node_process.h"
#include "util-inl.h"
#include "util.h"

View File

@ -1,6 +1,5 @@
#include "node_native_module.h"
#include "node_errors.h"
#include "node_internals.h"
namespace node {

View File

@ -1,5 +1,6 @@
#include <errno.h>
#include "node_internals.h"
#include "env-inl.h"
#include "node_binding.h"
#include "node_options-inl.h"
using v8::Boolean;

View File

@ -19,8 +19,9 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "node_internals.h"
#include "env-inl.h"
#include "string_bytes.h"
#include "util.h"
#include <array>
#include <errno.h>

View File

@ -4,7 +4,6 @@
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
#include "node.h"
#include "node_internals.h"
#include "node_perf_common.h"
#include "env.h"
#include "base_object-inl.h"

View File

@ -4,6 +4,7 @@
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
#include "node.h"
#include "uv.h"
#include "v8.h"
#include <algorithm>

View File

@ -1,8 +1,8 @@
#include <stdarg.h>
#include "env.h"
#include "node_internals.h"
#include "env-inl.h"
#include "node_process.h"
#include "util.h"
namespace node {
using v8::Context;

View File

@ -20,10 +20,10 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "node_stat_watcher.h"
#include "node_internals.h"
#include "async_wrap-inl.h"
#include "env.h"
#include "node_file.h"
#include "util.h"
#include <string.h>
#include <stdlib.h>

View File

@ -1,4 +1,5 @@
#include "node_internals.h"
#include "env-inl.h"
#include "node.h"
using v8::Context;
using v8::FunctionCallbackInfo;

View File

@ -2,7 +2,7 @@
#include "base_object-inl.h"
#include "node_errors.h"
#include "node_i18n.h"
#include "node_internals.h"
#include "util.h"
#include <string>
#include <vector>

View File

@ -1,6 +1,6 @@
#include "node_internals.h"
#include "node_errors.h"
#include "node_watchdog.h"
#include "util.h"
namespace node {
namespace util {

View File

@ -20,7 +20,6 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "node.h"
#include "node_internals.h"
#include "env-inl.h"
#include "util-inl.h"
#include "v8.h"

View File

@ -1,7 +1,6 @@
#include "node_worker.h"
#include "debug_utils.h"
#include "node_errors.h"
#include "node_internals.h"
#include "node_buffer.h"
#include "node_perf.h"
#include "util.h"

View File

@ -21,7 +21,6 @@
#include "node.h"
#include "node_buffer.h"
#include "node_internals.h"
#include "async_wrap-inl.h"
#include "env-inl.h"
@ -59,6 +58,19 @@ using v8::Value;
namespace {
// Fewer than 64 bytes per chunk is not recommended.
// Technically it could work with as few as 8, but even 64 bytes
// is low. Usually a MB or more is best.
#define Z_MIN_CHUNK 64
#define Z_MAX_CHUNK std::numeric_limits<double>::infinity()
#define Z_DEFAULT_CHUNK (16 * 1024)
#define Z_MIN_MEMLEVEL 1
#define Z_MAX_MEMLEVEL 9
#define Z_DEFAULT_MEMLEVEL 8
#define Z_MIN_LEVEL -1
#define Z_MAX_LEVEL 9
#define Z_DEFAULT_LEVEL Z_DEFAULT_COMPRESSION
#define ZLIB_ERROR_CODES(V) \
V(Z_OK) \
V(Z_STREAM_END) \

View File

@ -27,7 +27,6 @@
#include "handle_wrap.h"
#include "node.h"
#include "node_buffer.h"
#include "node_internals.h"
#include "connect_wrap.h"
#include "stream_base-inl.h"
#include "stream_wrap.h"

View File

@ -20,7 +20,6 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "env-inl.h"
#include "node_internals.h"
#include "stream_base-inl.h"
#include "stream_wrap.h"
#include "util-inl.h"

View File

@ -22,8 +22,8 @@
#include "spawn_sync.h"
#include "debug_utils.h"
#include "env-inl.h"
#include "node_internals.h"
#include "string_bytes.h"
#include "util.h"
#include <string.h>

View File

@ -24,8 +24,9 @@
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
#include "node_internals.h"
#include "node_buffer.h"
#include "uv.h"
#include "v8.h"
namespace node {

View File

@ -4,11 +4,9 @@
#include "node.h"
#include "node_buffer.h"
#include "node_errors.h"
#include "node_internals.h"
#include "env-inl.h"
#include "js_stream.h"
#include "string_bytes.h"
#include "util.h"
#include "util-inl.h"
#include "v8.h"

View File

@ -1,7 +1,6 @@
#include "stream_pipe.h"
#include "stream_base-inl.h"
#include "node_buffer.h"
#include "node_internals.h"
using v8::Context;
using v8::External;

View File

@ -22,9 +22,10 @@
#include "string_bytes.h"
#include "base64.h"
#include "node_internals.h"
#include "node_errors.h"
#include "env-inl.h"
#include "node_buffer.h"
#include "node_errors.h"
#include "util.h"
#include <limits.h>
#include <string.h> // memcpy

View File

@ -1,7 +1,7 @@
#include "string_decoder-inl.h"
#include "string_bytes.h"
#include "node_internals.h"
#include "env-inl.h"
#include "node_buffer.h"
#include "string_bytes.h"
#include "string_decoder-inl.h"
using v8::Array;
using v8::Context;

View File

@ -7,7 +7,8 @@
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
#include "node_internals.h"
#include "util.h"
#include <string.h>
#include <algorithm>

View File

@ -1,4 +1,6 @@
#include "node_internals.h"
#include "env-inl.h"
#include "util.h"
#include "v8.h"
#include <stdint.h>

View File

@ -26,7 +26,6 @@
#include "node_crypto_bio.h" // NodeBIO
// ClientHelloParser
#include "node_crypto_clienthello-inl.h"
#include "node_internals.h"
#include "stream_base-inl.h"
#include "util-inl.h"

View File

@ -5,7 +5,8 @@
#ifndef SRC_TRACING_TRACED_VALUE_H_
#define SRC_TRACING_TRACED_VALUE_H_
#include "node_internals.h"
#include "node.h"
#include "util.h"
#include "v8.h"
#include <stddef.h>

View File

@ -22,7 +22,6 @@
#include "udp_wrap.h"
#include "env-inl.h"
#include "node_buffer.h"
#include "node_internals.h"
#include "handle_wrap.h"
#include "req_wrap-inl.h"
#include "util-inl.h"

View File

@ -570,6 +570,94 @@ inline v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context,
#define READONLY_STRING_PROPERTY(obj, name, str) \
READONLY_PROPERTY(obj, name, ToV8Value(context, str).ToLocalChecked())
// Variation on NODE_DEFINE_CONSTANT that sets a String value.
#define NODE_DEFINE_STRING_CONSTANT(target, name, constant) \
do { \
v8::Isolate* isolate = target->GetIsolate(); \
v8::Local<v8::String> constant_name = \
v8::String::NewFromUtf8(isolate, name, v8::NewStringType::kNormal) \
.ToLocalChecked(); \
v8::Local<v8::String> constant_value = \
v8::String::NewFromUtf8(isolate, constant, v8::NewStringType::kNormal) \
.ToLocalChecked(); \
v8::PropertyAttribute constant_attributes = \
static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete); \
target \
->DefineOwnProperty(isolate->GetCurrentContext(), \
constant_name, \
constant_value, \
constant_attributes) \
.FromJust(); \
} while (0)
enum Endianness {
kLittleEndian, // _Not_ LITTLE_ENDIAN, clashes with endian.h.
kBigEndian
};
inline enum Endianness GetEndianness() {
// Constant-folded by the compiler.
const union {
uint8_t u8[2];
uint16_t u16;
} u = {{1, 0}};
return u.u16 == 1 ? kLittleEndian : kBigEndian;
}
inline bool IsLittleEndian() {
return GetEndianness() == kLittleEndian;
}
inline bool IsBigEndian() {
return GetEndianness() == kBigEndian;
}
template <typename T, size_t N>
constexpr size_t arraysize(const T (&)[N]) {
return N;
}
#ifndef ROUND_UP
#define ROUND_UP(a, b) ((a) % (b) ? ((a) + (b)) - ((a) % (b)) : (a))
#endif
#ifdef __GNUC__
#define MUST_USE_RESULT __attribute__((warn_unused_result))
#else
#define MUST_USE_RESULT
#endif
class SlicedArguments {
public:
inline explicit SlicedArguments(
const v8::FunctionCallbackInfo<v8::Value>& args, size_t start = 0);
inline size_t size() const { return size_; }
inline v8::Local<v8::Value>* data() { return data_; }
private:
size_t size_;
v8::Local<v8::Value>* data_;
v8::Local<v8::Value> fixed_[64];
std::vector<v8::Local<v8::Value>> dynamic_;
};
SlicedArguments::SlicedArguments(
const v8::FunctionCallbackInfo<v8::Value>& args, size_t start)
: size_(0), data_(fixed_) {
const size_t length = static_cast<size_t>(args.Length());
if (start >= length) return;
const size_t size = length - start;
if (size > arraysize(fixed_)) {
dynamic_.resize(size);
data_ = dynamic_.data();
}
for (size_t i = 0; i < size; ++i) data_[i] = args[i + start];
size_ = size;
}
} // namespace node
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

View File

@ -22,8 +22,8 @@
#include "uv.h"
#include "env-inl.h"
#include "node.h"
#include "node_internals.h"
#include "node_process.h"
#include "util.h"
namespace node {