summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2019-01-13 17:17:26 +0800
committerDaniel Bevenius <daniel.bevenius@gmail.com>2019-01-21 07:54:42 +0100
commit1838d00eba30708dd8468a5707489d1ff6bb8a9d (patch)
treeb757b6c004602f22bab5063a38a9e2cdde1f7fa1
parent8b2e861da1da827cf8c581efbfd126907df9b593 (diff)
downloadandroid-node-v8-1838d00eba30708dd8468a5707489d1ff6bb8a9d.tar.gz
android-node-v8-1838d00eba30708dd8468a5707489d1ff6bb8a9d.tar.bz2
android-node-v8-1838d00eba30708dd8468a5707489d1ff6bb8a9d.zip
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>
-rw-r--r--src/async_wrap.cc1
-rw-r--r--src/cares_wrap.cc1
-rw-r--r--src/connection_wrap.cc1
-rw-r--r--src/debug_utils.cc1
-rw-r--r--src/debug_utils.h5
-rw-r--r--src/fs_event_wrap.cc1
-rw-r--r--src/heap_utils.cc3
-rw-r--r--src/inspector_js_api.cc1
-rw-r--r--src/js_stream.cc1
-rw-r--r--src/module_wrap.cc1
-rw-r--r--src/node_binding.cc3
-rw-r--r--src/node_buffer.cc3
-rw-r--r--src/node_contextify.h1
-rw-r--r--src/node_crypto.cc1
-rw-r--r--src/node_domain.cc2
-rw-r--r--src/node_dtrace.cc1
-rw-r--r--src/node_dtrace.h3
-rw-r--r--src/node_env_var.cc2
-rw-r--r--src/node_file.cc2
-rw-r--r--src/node_http2.cc2
-rw-r--r--src/node_http2.h3
-rw-r--r--src/node_http_parser_impl.h2
-rw-r--r--src/node_i18n.cc5
-rw-r--r--src/node_i18n.h3
-rw-r--r--src/node_internals.h100
-rw-r--r--src/node_messaging.cc1
-rw-r--r--src/node_native_module.cc1
-rw-r--r--src/node_options.cc3
-rw-r--r--src/node_os.cc3
-rw-r--r--src/node_perf.h1
-rw-r--r--src/node_perf_common.h1
-rw-r--r--src/node_process_events.cc4
-rw-r--r--src/node_stat_watcher.cc2
-rw-r--r--src/node_types.cc3
-rw-r--r--src/node_url.cc2
-rw-r--r--src/node_util.cc2
-rw-r--r--src/node_v8.cc1
-rw-r--r--src/node_worker.cc1
-rw-r--r--src/node_zlib.cc14
-rw-r--r--src/pipe_wrap.cc1
-rw-r--r--src/process_wrap.cc1
-rw-r--r--src/spawn_sync.cc2
-rw-r--r--src/spawn_sync.h3
-rw-r--r--src/stream_base.cc2
-rw-r--r--src/stream_pipe.cc1
-rw-r--r--src/string_bytes.cc5
-rw-r--r--src/string_decoder.cc6
-rw-r--r--src/string_search.h3
-rw-r--r--src/timers.cc4
-rw-r--r--src/tls_wrap.cc1
-rw-r--r--src/tracing/traced_value.h3
-rw-r--r--src/udp_wrap.cc1
-rw-r--r--src/util.h88
-rw-r--r--src/uv.cc2
54 files changed, 153 insertions, 158 deletions
diff --git a/src/async_wrap.cc b/src/async_wrap.cc
index 47a9955127..70fc86702f 100644
--- a/src/async_wrap.cc
+++ b/src/async_wrap.cc
@@ -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"
diff --git a/src/cares_wrap.cc b/src/cares_wrap.cc
index 09cf809dec..57c02fb326 100644
--- a/src/cares_wrap.cc
+++ b/src/cares_wrap.cc
@@ -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"
diff --git a/src/connection_wrap.cc b/src/connection_wrap.cc
index db239f9bec..67308bdb9c 100644
--- a/src/connection_wrap.cc
+++ b/src/connection_wrap.cc
@@ -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"
diff --git a/src/debug_utils.cc b/src/debug_utils.cc
index d9db2d52e0..6dac86f002 100644
--- a/src/debug_utils.cc
+++ b/src/debug_utils.cc
@@ -1,5 +1,4 @@
#include "debug_utils.h"
-#include "node_internals.h"
#ifdef __POSIX__
#if defined(__linux__)
diff --git a/src/debug_utils.h b/src/debug_utils.h
index ed5e42fcbe..7e8a23d3ae 100644
--- a/src/debug_utils.h
+++ b/src/debug_utils.h
@@ -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
diff --git a/src/fs_event_wrap.cc b/src/fs_event_wrap.cc
index 249a4bb973..acc83d017e 100644
--- a/src/fs_event_wrap.cc
+++ b/src/fs_event_wrap.cc
@@ -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"
diff --git a/src/heap_utils.cc b/src/heap_utils.cc
index 84cbf07c1e..a1ca118e6c 100644
--- a/src/heap_utils.cc
+++ b/src/heap_utils.cc
@@ -1,5 +1,4 @@
-#include "node_internals.h"
-#include "env.h"
+#include "env-inl.h"
using v8::Array;
using v8::Boolean;
diff --git a/src/inspector_js_api.cc b/src/inspector_js_api.cc
index 0bf43c6fbb..d94cf4173d 100644
--- a/src/inspector_js_api.cc
+++ b/src/inspector_js_api.cc
@@ -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"
diff --git a/src/js_stream.cc b/src/js_stream.cc
index e4137079fa..32dea04db5 100644
--- a/src/js_stream.cc
+++ b/src/js_stream.cc
@@ -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"
diff --git a/src/module_wrap.cc b/src/module_wrap.cc
index 243352fe64..8599029fea 100644
--- a/src/module_wrap.cc
+++ b/src/module_wrap.cc
@@ -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"
diff --git a/src/node_binding.cc b/src/node_binding.cc
index 5ea8f01b41..85f3c19e69 100644
--- a/src/node_binding.cc
+++ b/src/node_binding.cc
@@ -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)
diff --git a/src/node_buffer.cc b/src/node_buffer.cc
index 2f4a4c6661..ccc338f941 100644
--- a/src/node_buffer.cc
+++ b/src/node_buffer.cc
@@ -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"
diff --git a/src/node_contextify.h b/src/node_contextify.h
index fedec0cd34..5f4f20554a 100644
--- a/src/node_contextify.h
+++ b/src/node_contextify.h
@@ -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 {
diff --git a/src/node_crypto.cc b/src/node_crypto.cc
index bda172e281..920869a2f2 100644
--- a/src/node_crypto.cc
+++ b/src/node_crypto.cc
@@ -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
diff --git a/src/node_domain.cc b/src/node_domain.cc
index b29ca1db05..9075845442 100644
--- a/src/node_domain.cc
+++ b/src/node_domain.cc
@@ -1,5 +1,5 @@
+#include "env-inl.h"
#include "v8.h"
-#include "node_internals.h"
namespace node {
namespace domain {
diff --git a/src/node_dtrace.cc b/src/node_dtrace.cc
index cd3986cef5..dfabde0747 100644
--- a/src/node_dtrace.cc
+++ b/src/node_dtrace.cc
@@ -43,7 +43,6 @@
#endif
#include "node_errors.h"
-#include "node_internals.h"
#include <string.h>
diff --git a/src/node_dtrace.h b/src/node_dtrace.h
index d16e23ddb3..ee11cd68aa 100644
--- a/src/node_dtrace.h
+++ b/src/node_dtrace.h
@@ -24,7 +24,8 @@
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
-#include "node_internals.h"
+#include "env.h"
+#include "v8.h"
extern "C" {
/*
diff --git a/src/node_env_var.cc b/src/node_env_var.cc
index d1ebb064e2..63cba55ab5 100644
--- a/src/node_env_var.cc
+++ b/src/node_env_var.cc
@@ -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>
diff --git a/src/node_file.cc b/src/node_file.cc
index 8757f6bf0d..35c8e01a28 100644
--- a/src/node_file.cc
+++ b/src/node_file.cc
@@ -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"
diff --git a/src/node_http2.cc b/src/node_http2.cc
index 1489d8b6f8..a3ce022835 100644
--- a/src/node_http2.cc
+++ b/src/node_http2.cc
@@ -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>
diff --git a/src/node_http2.h b/src/node_http2.h
index 4dc33d84c2..8347510c9d 100644
--- a/src/node_http2.h
+++ b/src/node_http2.h
@@ -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"
diff --git a/src/node_http_parser_impl.h b/src/node_http_parser_impl.h
index 48d669a759..7a955cc1e9 100644
--- a/src/node_http_parser_impl.h
+++ b/src/node_http_parser_impl.h
@@ -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"
diff --git a/src/node_i18n.cc b/src/node_i18n.cc
index c081bde93b..edc7f56093 100644
--- a/src/node_i18n.cc
+++ b/src/node_i18n.cc
@@ -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>
diff --git a/src/node_i18n.h b/src/node_i18n.h
index 7faa5e57ef..a0a398ac81 100644
--- a/src/node_i18n.h
+++ b/src/node_i18n.h
@@ -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)
diff --git a/src/node_internals.h b/src/node_internals.h
index 70c82dd2fc..0d4fe74ebf 100644
--- a/src/node_internals.h
+++ b/src/node_internals.h
@@ -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_; }
diff --git a/src/node_messaging.cc b/src/node_messaging.cc
index a538839bcc..aa4b92bf74 100644
--- a/src/node_messaging.cc
+++ b/src/node_messaging.cc
@@ -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"
diff --git a/src/node_native_module.cc b/src/node_native_module.cc
index 012e50b9e8..f272dd46be 100644
--- a/src/node_native_module.cc
+++ b/src/node_native_module.cc
@@ -1,6 +1,5 @@
#include "node_native_module.h"
#include "node_errors.h"
-#include "node_internals.h"
namespace node {
diff --git a/src/node_options.cc b/src/node_options.cc
index 667d7b6b9d..a3a5e0233a 100644
--- a/src/node_options.cc
+++ b/src/node_options.cc
@@ -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;
diff --git a/src/node_os.cc b/src/node_os.cc
index 505f42daf6..4a372f4e42 100644
--- a/src/node_os.cc
+++ b/src/node_os.cc
@@ -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>
diff --git a/src/node_perf.h b/src/node_perf.h
index 703ef81ce4..fe418ad441 100644
--- a/src/node_perf.h
+++ b/src/node_perf.h
@@ -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"
diff --git a/src/node_perf_common.h b/src/node_perf_common.h
index 0053ebf611..1c4cf01c87 100644
--- a/src/node_perf_common.h
+++ b/src/node_perf_common.h
@@ -4,6 +4,7 @@
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
#include "node.h"
+#include "uv.h"
#include "v8.h"
#include <algorithm>
diff --git a/src/node_process_events.cc b/src/node_process_events.cc
index d9c87173ab..ccc40b6575 100644
--- a/src/node_process_events.cc
+++ b/src/node_process_events.cc
@@ -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;
diff --git a/src/node_stat_watcher.cc b/src/node_stat_watcher.cc
index 7cf06393bb..9564a0a2b3 100644
--- a/src/node_stat_watcher.cc
+++ b/src/node_stat_watcher.cc
@@ -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>
diff --git a/src/node_types.cc b/src/node_types.cc
index 048c47493d..a53bcba555 100644
--- a/src/node_types.cc
+++ b/src/node_types.cc
@@ -1,4 +1,5 @@
-#include "node_internals.h"
+#include "env-inl.h"
+#include "node.h"
using v8::Context;
using v8::FunctionCallbackInfo;
diff --git a/src/node_url.cc b/src/node_url.cc
index 1841f32aad..d7402c4d04 100644
--- a/src/node_url.cc
+++ b/src/node_url.cc
@@ -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>
diff --git a/src/node_util.cc b/src/node_util.cc
index ba81d9d6e7..2a7d90cfe2 100644
--- a/src/node_util.cc
+++ b/src/node_util.cc
@@ -1,6 +1,6 @@
-#include "node_internals.h"
#include "node_errors.h"
#include "node_watchdog.h"
+#include "util.h"
namespace node {
namespace util {
diff --git a/src/node_v8.cc b/src/node_v8.cc
index c61f1e6600..8ed0e41670 100644
--- a/src/node_v8.cc
+++ b/src/node_v8.cc
@@ -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"
diff --git a/src/node_worker.cc b/src/node_worker.cc
index 30004957a4..cb49600584 100644
--- a/src/node_worker.cc
+++ b/src/node_worker.cc
@@ -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"
diff --git a/src/node_zlib.cc b/src/node_zlib.cc
index 4c65ede612..639d7f87c5 100644
--- a/src/node_zlib.cc
+++ b/src/node_zlib.cc
@@ -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) \
diff --git a/src/pipe_wrap.cc b/src/pipe_wrap.cc
index 6259cbdd19..8ad1e0f594 100644
--- a/src/pipe_wrap.cc
+++ b/src/pipe_wrap.cc
@@ -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"
diff --git a/src/process_wrap.cc b/src/process_wrap.cc
index d0514d64e0..37afaf8ff9 100644
--- a/src/process_wrap.cc
+++ b/src/process_wrap.cc
@@ -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"
diff --git a/src/spawn_sync.cc b/src/spawn_sync.cc
index eb16719b05..5a600d2e21 100644
--- a/src/spawn_sync.cc
+++ b/src/spawn_sync.cc
@@ -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>
diff --git a/src/spawn_sync.h b/src/spawn_sync.h
index 53fdee11d5..0ed6b9dff3 100644
--- a/src/spawn_sync.h
+++ b/src/spawn_sync.h
@@ -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 {
diff --git a/src/stream_base.cc b/src/stream_base.cc
index 739964eb85..a55cb60cfc 100644
--- a/src/stream_base.cc
+++ b/src/stream_base.cc
@@ -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"
diff --git a/src/stream_pipe.cc b/src/stream_pipe.cc
index 931972a48c..e58aa929e4 100644
--- a/src/stream_pipe.cc
+++ b/src/stream_pipe.cc
@@ -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;
diff --git a/src/string_bytes.cc b/src/string_bytes.cc
index e4c4c0a7db..53bb95d80d 100644
--- a/src/string_bytes.cc
+++ b/src/string_bytes.cc
@@ -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
diff --git a/src/string_decoder.cc b/src/string_decoder.cc
index ceee1c9d76..9cf1bd671b 100644
--- a/src/string_decoder.cc
+++ b/src/string_decoder.cc
@@ -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;
diff --git a/src/string_search.h b/src/string_search.h
index c924908b8b..95c746ea89 100644
--- a/src/string_search.h
+++ b/src/string_search.h
@@ -7,7 +7,8 @@
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
-#include "node_internals.h"
+#include "util.h"
+
#include <string.h>
#include <algorithm>
diff --git a/src/timers.cc b/src/timers.cc
index f0ee1db415..f80e9e6be4 100644
--- a/src/timers.cc
+++ b/src/timers.cc
@@ -1,4 +1,6 @@
-#include "node_internals.h"
+#include "env-inl.h"
+#include "util.h"
+#include "v8.h"
#include <stdint.h>
diff --git a/src/tls_wrap.cc b/src/tls_wrap.cc
index b5d6559355..d9f916f3d1 100644
--- a/src/tls_wrap.cc
+++ b/src/tls_wrap.cc
@@ -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"
diff --git a/src/tracing/traced_value.h b/src/tracing/traced_value.h
index 84e24c9525..7507978408 100644
--- a/src/tracing/traced_value.h
+++ b/src/tracing/traced_value.h
@@ -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>
diff --git a/src/udp_wrap.cc b/src/udp_wrap.cc
index 2e076e26b9..d838ef6e72 100644
--- a/src/udp_wrap.cc
+++ b/src/udp_wrap.cc
@@ -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"
diff --git a/src/util.h b/src/util.h
index 2fa16cadea..ea705b800b 100644
--- a/src/util.h
+++ b/src/util.h
@@ -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
diff --git a/src/uv.cc b/src/uv.cc
index 5422b0d240..59469fc307 100644
--- a/src/uv.cc
+++ b/src/uv.cc
@@ -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 {