Skip to content

Commit 34aac23

Browse files
ofrobotsAli Sheikh
authored andcommitted
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: #5204 Reviewed-By: bnoordhuis - Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: indutny - Fedor Indutny <fedor.indutny@gmail.com>
1 parent a45e1f9 commit 34aac23

File tree

1 file changed

+14
-26
lines changed

1 file changed

+14
-26
lines changed

src/node_buffer.cc

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -79,20 +79,18 @@ class CallbackInfo {
7979
public:
8080
static inline void Free(char* data, void* hint);
8181
static inline CallbackInfo* New(Isolate* isolate,
82-
Local<Object> object,
82+
Local<ArrayBuffer> object,
8383
FreeCallback callback,
8484
void* hint = 0);
85-
inline void Dispose(Isolate* isolate);
86-
inline Persistent<Object>* persistent();
8785
private:
88-
static void WeakCallback(const WeakCallbackData<Object, CallbackInfo>&);
89-
inline void WeakCallback(Isolate* isolate, Local<Object> object);
86+
static void WeakCallback(const WeakCallbackData<ArrayBuffer, CallbackInfo>&);
87+
inline void WeakCallback(Isolate* isolate, Local<ArrayBuffer> object);
9088
inline CallbackInfo(Isolate* isolate,
91-
Local<Object> object,
89+
Local<ArrayBuffer> object,
9290
FreeCallback callback,
9391
void* hint);
9492
~CallbackInfo();
95-
Persistent<Object> persistent_;
93+
Persistent<ArrayBuffer> persistent_;
9694
FreeCallback const callback_;
9795
void* const hint_;
9896
DISALLOW_COPY_AND_ASSIGN(CallbackInfo);
@@ -105,30 +103,25 @@ void CallbackInfo::Free(char* data, void*) {
105103

106104

107105
CallbackInfo* CallbackInfo::New(Isolate* isolate,
108-
Local<Object> object,
106+
Local<ArrayBuffer> object,
109107
FreeCallback callback,
110108
void* hint) {
111109
return new CallbackInfo(isolate, object, callback, hint);
112110
}
113111

114112

115-
void CallbackInfo::Dispose(Isolate* isolate) {
116-
WeakCallback(isolate, PersistentToLocal(isolate, persistent_));
117-
}
118-
119-
120-
Persistent<Object>* CallbackInfo::persistent() {
121-
return &persistent_;
122-
}
123-
124-
125113
CallbackInfo::CallbackInfo(Isolate* isolate,
126-
Local<Object> object,
114+
Local<ArrayBuffer> object,
127115
FreeCallback callback,
128116
void* hint)
129117
: persistent_(isolate, object),
130118
callback_(callback),
131119
hint_(hint) {
120+
ArrayBuffer::Contents obj_c = object->GetContents();
121+
char* const data = static_cast<char*>(obj_c.Data());
122+
if (object->ByteLength() != 0)
123+
CHECK_NE(data, nullptr);
124+
132125
persistent_.SetWeak(this, WeakCallback);
133126
persistent_.SetWrapperClassId(BUFFER_ID);
134127
persistent_.MarkIndependent();
@@ -142,19 +135,14 @@ CallbackInfo::~CallbackInfo() {
142135

143136

144137
void CallbackInfo::WeakCallback(
145-
const WeakCallbackData<Object, CallbackInfo>& data) {
138+
const WeakCallbackData<ArrayBuffer, CallbackInfo>& data) {
146139
data.GetParameter()->WeakCallback(data.GetIsolate(), data.GetValue());
147140
}
148141

149142

150-
void CallbackInfo::WeakCallback(Isolate* isolate, Local<Object> object) {
151-
CHECK(object->IsArrayBuffer());
152-
Local<ArrayBuffer> buf = object.As<ArrayBuffer>();
143+
void CallbackInfo::WeakCallback(Isolate* isolate, Local<ArrayBuffer> buf) {
153144
ArrayBuffer::Contents obj_c = buf->GetContents();
154145
char* const obj_data = static_cast<char*>(obj_c.Data());
155-
if (buf->ByteLength() != 0)
156-
CHECK_NE(obj_data, nullptr);
157-
158146
buf->Neuter();
159147
callback_(obj_data, hint_);
160148
int64_t change_in_bytes = -static_cast<int64_t>(sizeof(*this));

0 commit comments

Comments
 (0)