Skip to content

Commit c8c638a

Browse files
committed
buffer: change prototype of Data() and Length()
Make Buffer:Data() and Buffer::Length() accept a Value instead of an Object.
1 parent eaf1343 commit c8c638a

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/node_buffer.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,21 @@ class NODE_EXTERN Buffer: public ObjectWrap {
7272

7373
static bool HasInstance(v8::Handle<v8::Value> val);
7474

75-
static inline char* Data(v8::Handle<v8::Object> obj) {
76-
return (char*)obj->GetIndexedPropertiesExternalArrayData();
75+
static inline char* Data(v8::Handle<v8::Value> val) {
76+
assert(val->IsObject());
77+
void* data = val.As<v8::Object>()->GetIndexedPropertiesExternalArrayData();
78+
return reinterpret_cast<char*>(data);
7779
}
7880

7981
static inline char* Data(Buffer *b) {
8082
return Buffer::Data(b->handle_);
8183
}
8284

83-
static inline size_t Length(v8::Handle<v8::Object> obj) {
84-
return (size_t)obj->GetIndexedPropertiesExternalArrayDataLength();
85+
static inline size_t Length(v8::Handle<v8::Value> val) {
86+
assert(val->IsObject());
87+
int len = val.As<v8::Object>()
88+
->GetIndexedPropertiesExternalArrayDataLength();
89+
return static_cast<size_t>(len);
8590
}
8691

8792
static inline size_t Length(Buffer *b) {

0 commit comments

Comments
 (0)