Skip to content

Commit

Permalink
Make ObjectWrap::handle() const (#574)
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoopa committed May 28, 2016
1 parent 615c19d commit d19af99
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions nan_object_wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class ObjectWrap {
}


inline v8::Local<v8::Object> handle() {
return New(persistent());
inline v8::Local<v8::Object> handle() const {
return New(handle_);
}


Expand Down
6 changes: 6 additions & 0 deletions test/cpp/objectwraphandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class MyObject : public ObjectWrap {
tpl->InstanceTemplate()->SetInternalFieldCount(1);

SetPrototypeMethod(tpl, "getHandle", GetHandle);
SetPrototypeMethod(tpl, "getHandleConst", GetHandleConst);
SetPrototypeMethod(tpl, "getValue", GetValue);

constructor().Reset(Nan::GetFunction(tpl).ToLocalChecked());
Expand Down Expand Up @@ -49,6 +50,11 @@ class MyObject : public ObjectWrap {
info.GetReturnValue().Set(obj->handle());
}

static NAN_METHOD(GetHandleConst) {
MyObject const *obj = ObjectWrap::Unwrap<MyObject>(info.Holder());
info.GetReturnValue().Set(obj->handle());
}

static NAN_METHOD(GetValue) {
MyObject* obj = ObjectWrap::Unwrap<MyObject>(info.Holder());
info.GetReturnValue().Set(obj->value_);
Expand Down
4 changes: 3 additions & 1 deletion test/js/objectwraphandle-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ const test = require('tap').test
, bindings = require('bindings')({ module_root: testRoot, bindings: 'objectwraphandle' });

test('objectwraphandle', function (t) {
t.plan(7);
t.plan(9);

t.type(bindings.MyObject, 'function');

var obj = new bindings.MyObject(10);

t.type(obj.getHandle, 'function');
t.type(obj.getHandleConst, 'function');
t.type(obj.getValue, 'function');
t.type(obj.getHandle(), 'object');
t.type(obj.getHandleConst(), 'object');
t.type(obj.getValue(), 'number');

var derived = Object.create(obj);
Expand Down

0 comments on commit d19af99

Please sign in to comment.