From 34aac23d0b14bd081fc6785873063a147fa5fa65 Mon Sep 17 00:00:00 2001 From: Ali Ijaz Sheikh Date: Sun, 14 Feb 2016 08:38:35 +0500 Subject: [PATCH] buffer: cleanup CallbackInfo Dynamic checks that CallbackInfo holds an ArrayBuffer handle can be converted into compiler enforced checks. Removed unused code, and other minor cleanup. PR-URL: https://github.com/nodejs/node/pull/5204 Reviewed-By: bnoordhuis - Ben Noordhuis Reviewed-By: indutny - Fedor Indutny --- src/node_buffer.cc | 40 ++++++++++++++-------------------------- 1 file changed, 14 insertions(+), 26 deletions(-) diff --git a/src/node_buffer.cc b/src/node_buffer.cc index 026a04028a1eb8..f1c0c35ffc7ccf 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -79,20 +79,18 @@ class CallbackInfo { public: static inline void Free(char* data, void* hint); static inline CallbackInfo* New(Isolate* isolate, - Local object, + Local object, FreeCallback callback, void* hint = 0); - inline void Dispose(Isolate* isolate); - inline Persistent* persistent(); private: - static void WeakCallback(const WeakCallbackData&); - inline void WeakCallback(Isolate* isolate, Local object); + static void WeakCallback(const WeakCallbackData&); + inline void WeakCallback(Isolate* isolate, Local object); inline CallbackInfo(Isolate* isolate, - Local object, + Local object, FreeCallback callback, void* hint); ~CallbackInfo(); - Persistent persistent_; + Persistent persistent_; FreeCallback const callback_; void* const hint_; DISALLOW_COPY_AND_ASSIGN(CallbackInfo); @@ -105,30 +103,25 @@ void CallbackInfo::Free(char* data, void*) { CallbackInfo* CallbackInfo::New(Isolate* isolate, - Local object, + Local object, FreeCallback callback, void* hint) { return new CallbackInfo(isolate, object, callback, hint); } -void CallbackInfo::Dispose(Isolate* isolate) { - WeakCallback(isolate, PersistentToLocal(isolate, persistent_)); -} - - -Persistent* CallbackInfo::persistent() { - return &persistent_; -} - - CallbackInfo::CallbackInfo(Isolate* isolate, - Local object, + Local object, FreeCallback callback, void* hint) : persistent_(isolate, object), callback_(callback), hint_(hint) { + ArrayBuffer::Contents obj_c = object->GetContents(); + char* const data = static_cast(obj_c.Data()); + if (object->ByteLength() != 0) + CHECK_NE(data, nullptr); + persistent_.SetWeak(this, WeakCallback); persistent_.SetWrapperClassId(BUFFER_ID); persistent_.MarkIndependent(); @@ -142,19 +135,14 @@ CallbackInfo::~CallbackInfo() { void CallbackInfo::WeakCallback( - const WeakCallbackData& data) { + const WeakCallbackData& data) { data.GetParameter()->WeakCallback(data.GetIsolate(), data.GetValue()); } -void CallbackInfo::WeakCallback(Isolate* isolate, Local object) { - CHECK(object->IsArrayBuffer()); - Local buf = object.As(); +void CallbackInfo::WeakCallback(Isolate* isolate, Local buf) { ArrayBuffer::Contents obj_c = buf->GetContents(); char* const obj_data = static_cast(obj_c.Data()); - if (buf->ByteLength() != 0) - CHECK_NE(obj_data, nullptr); - buf->Neuter(); callback_(obj_data, hint_); int64_t change_in_bytes = -static_cast(sizeof(*this));