Skip to content

Commit

Permalink
src: reduce includes of node_internals.h
Browse files Browse the repository at this point in the history
PR-URL: #25507
Reviewed-By: Daniel Bevenius <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
joyeecheung authored and addaleax committed Jan 23, 2019
1 parent efe089e commit 291cedf
Show file tree
Hide file tree
Showing 54 changed files with 153 additions and 158 deletions.
1 change: 0 additions & 1 deletion src/async_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
1 change: 0 additions & 1 deletion src/cares_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion src/connection_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion src/debug_utils.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "debug_utils.h"
#include "node_internals.h"

#ifdef __POSIX__
#if defined(__linux__)
Expand Down
5 changes: 3 additions & 2 deletions src/debug_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/fs_event_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
3 changes: 1 addition & 2 deletions src/heap_utils.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "node_internals.h"
#include "env.h"
#include "env-inl.h"

using v8::Array;
using v8::Boolean;
Expand Down
1 change: 0 additions & 1 deletion src/inspector_js_api.cc
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
1 change: 0 additions & 1 deletion src/js_stream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
1 change: 0 additions & 1 deletion src/module_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
3 changes: 2 additions & 1 deletion src/node_binding.cc
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/node_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion src/node_contextify.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/node_domain.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "env-inl.h"
#include "v8.h"
#include "node_internals.h"

namespace node {
namespace domain {
Expand Down
1 change: 0 additions & 1 deletion src/node_dtrace.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
#endif

#include "node_errors.h"
#include "node_internals.h"

#include <string.h>

Expand Down
3 changes: 2 additions & 1 deletion src/node_dtrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@

#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

#include "node_internals.h"
#include "env.h"
#include "v8.h"

extern "C" {
/*
Expand Down
2 changes: 1 addition & 1 deletion src/node_env_var.cc
Original file line number Diff line number Diff line change
@@ -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>
Expand Down
2 changes: 1 addition & 1 deletion src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion src/node_http2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
3 changes: 3 additions & 0 deletions src/node_http2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/node_http_parser_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 3 additions & 2 deletions src/node_i18n.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
3 changes: 2 additions & 1 deletion src/node_i18n.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
100 changes: 0 additions & 100 deletions src/node_internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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_; }
Expand Down
1 change: 0 additions & 1 deletion src/node_messaging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion src/node_native_module.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "node_native_module.h"
#include "node_errors.h"
#include "node_internals.h"

namespace node {

Expand Down
3 changes: 2 additions & 1 deletion src/node_options.cc
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/node_os.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
1 change: 0 additions & 1 deletion src/node_perf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions src/node_perf_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

#include "node.h"
#include "uv.h"
#include "v8.h"

#include <algorithm>
Expand Down
Loading

0 comments on commit 291cedf

Please sign in to comment.