diff --git a/src/node_internals.h b/src/node_internals.h index 5c94168c916816..ae1256756c31db 100644 --- a/src/node_internals.h +++ b/src/node_internals.h @@ -247,78 +247,78 @@ void ClearFatalExceptionHandlers(Environment* env); enum NodeInstanceType { MAIN, WORKER }; class NodeInstanceData { - public: - NodeInstanceData(NodeInstanceType node_instance_type, - uv_loop_t* event_loop, - int argc, - const char** argv, - int exec_argc, - const char** exec_argv, - bool use_debug_agent_flag) - : node_instance_type_(node_instance_type), - exit_code_(1), - event_loop_(event_loop), - argc_(argc), - argv_(argv), - exec_argc_(exec_argc), - exec_argv_(exec_argv), - use_debug_agent_flag_(use_debug_agent_flag) { - CHECK_NE(event_loop_, nullptr); - } - - uv_loop_t* event_loop() const { - return event_loop_; - } - - int exit_code() { - CHECK(is_main()); - return exit_code_; - } - - void set_exit_code(int exit_code) { - CHECK(is_main()); - exit_code_ = exit_code; - } - - bool is_main() { - return node_instance_type_ == MAIN; - } - - bool is_worker() { - return node_instance_type_ == WORKER; - } - - int argc() { - return argc_; - } - - const char** argv() { - return argv_; - } - - int exec_argc() { - return exec_argc_; - } - - const char** exec_argv() { - return exec_argv_; - } - - bool use_debug_agent() { - return is_main() && use_debug_agent_flag_; - } - - private: - const NodeInstanceType node_instance_type_; - int exit_code_; - uv_loop_t* const event_loop_; - const int argc_; - const char** argv_; - const int exec_argc_; - const char** exec_argv_; - const bool use_debug_agent_flag_; - - DISALLOW_COPY_AND_ASSIGN(NodeInstanceData); + public: + NodeInstanceData(NodeInstanceType node_instance_type, + uv_loop_t* event_loop, + int argc, + const char** argv, + int exec_argc, + const char** exec_argv, + bool use_debug_agent_flag) + : node_instance_type_(node_instance_type), + exit_code_(1), + event_loop_(event_loop), + argc_(argc), + argv_(argv), + exec_argc_(exec_argc), + exec_argv_(exec_argv), + use_debug_agent_flag_(use_debug_agent_flag) { + CHECK_NE(event_loop_, nullptr); + } + + uv_loop_t* event_loop() const { + return event_loop_; + } + + int exit_code() { + CHECK(is_main()); + return exit_code_; + } + + void set_exit_code(int exit_code) { + CHECK(is_main()); + exit_code_ = exit_code; + } + + bool is_main() { + return node_instance_type_ == MAIN; + } + + bool is_worker() { + return node_instance_type_ == WORKER; + } + + int argc() { + return argc_; + } + + const char** argv() { + return argv_; + } + + int exec_argc() { + return exec_argc_; + } + + const char** exec_argv() { + return exec_argv_; + } + + bool use_debug_agent() { + return is_main() && use_debug_agent_flag_; + } + + private: + const NodeInstanceType node_instance_type_; + int exit_code_; + uv_loop_t* const event_loop_; + const int argc_; + const char** argv_; + const int exec_argc_; + const char** exec_argv_; + const bool use_debug_agent_flag_; + + DISALLOW_COPY_AND_ASSIGN(NodeInstanceData); }; namespace Buffer { diff --git a/src/string_bytes.cc b/src/string_bytes.cc index a916caf75e8960..d1c6a573250b7e 100644 --- a/src/string_bytes.cc +++ b/src/string_bytes.cc @@ -27,75 +27,75 @@ using v8::MaybeLocal; template class ExternString: public ResourceType { - public: - ~ExternString() override { - free(const_cast(data_)); - isolate()->AdjustAmountOfExternalAllocatedMemory(-byte_length()); - } - - const TypeName* data() const override { - return data_; - } + public: + ~ExternString() override { + free(const_cast(data_)); + isolate()->AdjustAmountOfExternalAllocatedMemory(-byte_length()); + } - size_t length() const override { - return length_; - } + const TypeName* data() const override { + return data_; + } - int64_t byte_length() const { - return length() * sizeof(*data()); - } + size_t length() const override { + return length_; + } - static Local NewFromCopy(Isolate* isolate, - const TypeName* data, - size_t length) { - EscapableHandleScope scope(isolate); + int64_t byte_length() const { + return length() * sizeof(*data()); + } - if (length == 0) - return scope.Escape(String::Empty(isolate)); + static Local NewFromCopy(Isolate* isolate, + const TypeName* data, + size_t length) { + EscapableHandleScope scope(isolate); - TypeName* new_data = - static_cast(malloc(length * sizeof(*new_data))); - if (new_data == nullptr) { - return Local(); - } - memcpy(new_data, data, length * sizeof(*new_data)); + if (length == 0) + return scope.Escape(String::Empty(isolate)); - return scope.Escape(ExternString::New(isolate, - new_data, - length)); + TypeName* new_data = + static_cast(malloc(length * sizeof(*new_data))); + if (new_data == nullptr) { + return Local(); } + memcpy(new_data, data, length * sizeof(*new_data)); - // uses "data" for external resource, and will be free'd on gc - static Local New(Isolate* isolate, - const TypeName* data, - size_t length) { - EscapableHandleScope scope(isolate); + return scope.Escape(ExternString::New(isolate, + new_data, + length)); + } - if (length == 0) - return scope.Escape(String::Empty(isolate)); + // uses "data" for external resource, and will be free'd on gc + static Local New(Isolate* isolate, + const TypeName* data, + size_t length) { + EscapableHandleScope scope(isolate); + if (length == 0) + return scope.Escape(String::Empty(isolate)); - ExternString* h_str = new ExternString(isolate, - data, - length); - MaybeLocal str = String::NewExternal(isolate, h_str); - isolate->AdjustAmountOfExternalAllocatedMemory(h_str->byte_length()); + ExternString* h_str = new ExternString(isolate, + data, + length); + MaybeLocal str = String::NewExternal(isolate, h_str); + isolate->AdjustAmountOfExternalAllocatedMemory(h_str->byte_length()); - if (str.IsEmpty()) { - delete h_str; - return Local(); - } - return scope.Escape(str.ToLocalChecked()); + if (str.IsEmpty()) { + delete h_str; + return Local(); } - inline Isolate* isolate() const { return isolate_; } + return scope.Escape(str.ToLocalChecked()); + } + + inline Isolate* isolate() const { return isolate_; } - private: - ExternString(Isolate* isolate, const TypeName* data, size_t length) - : isolate_(isolate), data_(data), length_(length) { } - Isolate* isolate_; - const TypeName* data_; - size_t length_; + private: + ExternString(Isolate* isolate, const TypeName* data, size_t length) + : isolate_(isolate), data_(data), length_(length) { } + Isolate* isolate_; + const TypeName* data_; + size_t length_; }; diff --git a/src/util.h b/src/util.h index 8254bbe9713871..8c2b0a1be4c47a 100644 --- a/src/util.h +++ b/src/util.h @@ -194,99 +194,99 @@ inline bool StringEqualNoCase(const char* a, const char* b); // the stack is used, otherwise malloc(). template class MaybeStackBuffer { - public: - const T* out() const { - return buf_; - } - - T* out() { - return buf_; - } - - // operator* for compatibility with `v8::String::(Utf8)Value` - T* operator*() { - return buf_; - } - - const T* operator*() const { - return buf_; - } - - size_t length() const { - return length_; - } - - // Call to make sure enough space for `storage` entries is available. - // There can only be 1 call to AllocateSufficientStorage or Invalidate - // per instance. - void AllocateSufficientStorage(size_t storage) { - if (storage <= kStackStorageSize) { - buf_ = buf_st_; - } else { - // Guard against overflow. - CHECK_LE(storage, sizeof(T) * storage); - - buf_ = static_cast(malloc(sizeof(T) * storage)); - CHECK_NE(buf_, nullptr); - } - - // Remember how much was allocated to check against that in SetLength(). - length_ = storage; - } - - void SetLength(size_t length) { - // length_ stores how much memory was allocated. - CHECK_LE(length, length_); - length_ = length; - } - - void SetLengthAndZeroTerminate(size_t length) { - // length_ stores how much memory was allocated. - CHECK_LE(length + 1, length_); - SetLength(length); - - // T() is 0 for integer types, nullptr for pointers, etc. - buf_[length] = T(); - } - - // Make derefencing this object return nullptr. - // Calling this is mutually exclusive with calling - // AllocateSufficientStorage. - void Invalidate() { - CHECK_EQ(buf_, buf_st_); - length_ = 0; - buf_ = nullptr; - } - - MaybeStackBuffer() : length_(0), buf_(buf_st_) { - // Default to a zero-length, null-terminated buffer. - buf_[0] = T(); + public: + const T* out() const { + return buf_; + } + + T* out() { + return buf_; + } + + // operator* for compatibility with `v8::String::(Utf8)Value` + T* operator*() { + return buf_; + } + + const T* operator*() const { + return buf_; + } + + size_t length() const { + return length_; + } + + // Call to make sure enough space for `storage` entries is available. + // There can only be 1 call to AllocateSufficientStorage or Invalidate + // per instance. + void AllocateSufficientStorage(size_t storage) { + if (storage <= kStackStorageSize) { + buf_ = buf_st_; + } else { + // Guard against overflow. + CHECK_LE(storage, sizeof(T) * storage); + + buf_ = static_cast(malloc(sizeof(T) * storage)); + CHECK_NE(buf_, nullptr); } - ~MaybeStackBuffer() { - if (buf_ != buf_st_) - free(buf_); - } + // Remember how much was allocated to check against that in SetLength(). + length_ = storage; + } + + void SetLength(size_t length) { + // length_ stores how much memory was allocated. + CHECK_LE(length, length_); + length_ = length; + } + + void SetLengthAndZeroTerminate(size_t length) { + // length_ stores how much memory was allocated. + CHECK_LE(length + 1, length_); + SetLength(length); + + // T() is 0 for integer types, nullptr for pointers, etc. + buf_[length] = T(); + } + + // Make derefencing this object return nullptr. + // Calling this is mutually exclusive with calling + // AllocateSufficientStorage. + void Invalidate() { + CHECK_EQ(buf_, buf_st_); + length_ = 0; + buf_ = nullptr; + } + + MaybeStackBuffer() : length_(0), buf_(buf_st_) { + // Default to a zero-length, null-terminated buffer. + buf_[0] = T(); + } + + ~MaybeStackBuffer() { + if (buf_ != buf_st_) + free(buf_); + } - private: - size_t length_; - T* buf_; - T buf_st_[kStackStorageSize]; + private: + size_t length_; + T* buf_; + T buf_st_[kStackStorageSize]; }; class Utf8Value : public MaybeStackBuffer { - public: - explicit Utf8Value(v8::Isolate* isolate, v8::Local value); + public: + explicit Utf8Value(v8::Isolate* isolate, v8::Local value); }; class TwoByteValue : public MaybeStackBuffer { - public: - explicit TwoByteValue(v8::Isolate* isolate, v8::Local value); + public: + explicit TwoByteValue(v8::Isolate* isolate, v8::Local value); }; class BufferValue : public MaybeStackBuffer { - public: - explicit BufferValue(v8::Isolate* isolate, v8::Local value); + public: + explicit BufferValue(v8::Isolate* isolate, v8::Local value); }; } // namespace node