diff options
54 files changed, 153 insertions, 158 deletions
diff --git a/src/async_wrap.cc b/src/async_wrap.cc index 47a99551275..70fc86702f0 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 09cf809dec3..57c02fb3265 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 db239f9becd..67308bdb9c8 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 d9db2d52e0d..6dac86f002b 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 ed5e42fcbe8..7e8a23d3ae3 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 249a4bb973c..acc83d017e0 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 84cbf07c1ee..a1ca118e6c1 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 0bf43c6fbb1..d94cf4173d1 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 e4137079fa5..32dea04db5a 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 243352fe644..8599029fea1 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 5ea8f01b41b..85f3c19e690 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 2f4a4c66619..ccc338f9417 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 fedec0cd345..5f4f20554ae 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 bda172e2810..920869a2f2b 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 b29ca1db057..9075845442f 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 cd3986cef56..dfabde0747b 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 d16e23ddb38..ee11cd68aa7 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 d1ebb064e24..63cba55ab56 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 8757f6bf0d8..35c8e01a28c 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 1489d8b6f88..a3ce022835e 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 4dc33d84c2a..8347510c9d0 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 48d669a7593..7a955cc1e9e 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 c081bde93be..edc7f56093a 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 7faa5e57ef2..a0a398ac818 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 70c82dd2fcd..0d4fe74ebf3 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 a538839bcc6..aa4b92bf749 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 012e50b9e81..f272dd46bef 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 667d7b6b9dd..a3a5e0233aa 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 505f42daf67..4a372f4e428 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 703ef81ce48..fe418ad4417 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 0053ebf6119..1c4cf01c871 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 d9c87173abe..ccc40b65753 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 7cf06393bb7..9564a0a2b32 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 048c47493d3..a53bcba5554 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 1841f32aad7..d7402c4d043 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 ba81d9d6e7f..2a7d90cfe2b 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 c61f1e6600b..8ed0e416702 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 30004957a47..cb496005844 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 4c65ede612c..639d7f87c5a 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 6259cbdd191..8ad1e0f594a 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 d0514d64e08..37afaf8ff96 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 eb16719b051..5a600d2e210 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 53fdee11d5a..0ed6b9dff3a 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 739964eb85a..a55cb60cfc5 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 931972a48c3..e58aa929e4b 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 e4c4c0a7dbb..53bb95d80da 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 ceee1c9d762..9cf1bd671b3 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 c924908b8b6..95c746ea89e 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 f0ee1db4152..f80e9e6be4d 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 b5d6559355c..d9f916f3d16 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 84e24c95252..7507978408f 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 2e076e26b9f..d838ef6e725 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 2fa16cadeac..ea705b800bd 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 5422b0d2403..59469fc3075 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 { |