Skip to content

Commit

Permalink
Update the buffer-reusing constructor to return a MaybeLocal
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoopa committed Jul 4, 2015
1 parent 7747fd0 commit 3621ab6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
11 changes: 6 additions & 5 deletions nan.h
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ class TryCatch {
#endif
}

NAN_INLINE v8::Local<v8::Object> NewBuffer(
NAN_INLINE MaybeLocal<v8::Object> NewBuffer(
char* data
, uint32_t size
) {
Expand All @@ -727,7 +727,8 @@ class TryCatch {
#if NODE_MODULE_VERSION > IOJS_2_0_MODULE_VERSION
return node::Buffer::New(v8::Isolate::GetCurrent(), data, size);
#else
return node::Buffer::Use(v8::Isolate::GetCurrent(), data, size);
return MaybeLocal<v8::Object>(
node::Buffer::Use(v8::Isolate::GetCurrent(), data, size));
#endif
}

Expand Down Expand Up @@ -1074,16 +1075,16 @@ class Utf8String {
delete[] data;
}

NAN_INLINE v8::Local<v8::Object> NewBuffer(
NAN_INLINE MaybeLocal<v8::Object> NewBuffer(
char* data
, uint32_t size
) {
EscapableHandleScope scope;
// arbitrary buffer lengths requires
// NODE_MODULE_VERSION >= IOJS_3_0_MODULE_VERSION
assert(size <= imp::kMaxLength && "too large buffer");
return scope.Escape(New(
node::Buffer::New(data, size, FreeData, NULL)->handle_));
return MaybeLocal<v8::Object>(scope.Escape(New(
node::Buffer::New(data, size, FreeData, NULL)->handle_)));
}

NAN_INLINE bool HasInstance(
Expand Down
3 changes: 2 additions & 1 deletion test/cpp/buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ NAN_METHOD(New3) {
for (unsigned char i = 0; i < DATA_SIZE; i++) {
dynamic_data[i] = 'a' + i;
}
info.GetReturnValue().Set(NewBuffer(dynamic_data, DATA_SIZE));
info.GetReturnValue().Set(
NewBuffer(dynamic_data, DATA_SIZE).ToLocalChecked());
}

NAN_METHOD(Copy) {
Expand Down

0 comments on commit 3621ab6

Please sign in to comment.