Skip to content

Commit

Permalink
Add test for getting wrapped value to ObjectWrap test suite
Browse files Browse the repository at this point in the history
Fixes warning about unused member variable
  • Loading branch information
kkoopa committed Aug 17, 2015
1 parent 13596c0 commit 00ee0fe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
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, "getValue", GetValue);

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

static NAN_METHOD(GetValue) {
MyObject* obj = ObjectWrap::Unwrap<MyObject>(info.This());
info.GetReturnValue().Set(obj->value_);
}

static Persistent<v8::Function> constructor;
double 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,12 +11,14 @@ const test = require('tap').test
, bindings = require('bindings')({ module_root: testRoot, bindings: 'objectwraphandle' });

test('objectwraphandle', function (t) {
t.plan(3);
t.plan(5);

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

var obj = new bindings.MyObject(10);

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

0 comments on commit 00ee0fe

Please sign in to comment.