diff --git a/test/objectwrap.cc b/test/objectwrap.cc index 0d61171ca..92a29ce74 100644 --- a/test/objectwrap.cc +++ b/test/objectwrap.cc @@ -28,7 +28,22 @@ class Test : public Napi::ObjectWrap { if(info.Length() > 0) { finalizeCb_ = Napi::Persistent(info[0].As()); } + // Create an own instance property. + info.This().As().DefineProperty( + Napi::PropertyDescriptor::Accessor(info.Env(), + info.This().As(), + "ownProperty", + OwnPropertyGetter, + napi_enumerable, this)); + + // Create an own instance property with a templated function. + info.This().As().DefineProperty( + Napi::PropertyDescriptor::Accessor("ownPropertyT", + napi_enumerable, this)); + } + static Napi::Value OwnPropertyGetter(const Napi::CallbackInfo& info) { + return static_cast(info.Data())->Getter(info); } void Setter(const Napi::CallbackInfo& /*info*/, const Napi::Value& value) { diff --git a/test/objectwrap.js b/test/objectwrap.js index de16a6067..e1281d3d2 100644 --- a/test/objectwrap.js +++ b/test/objectwrap.js @@ -72,6 +72,18 @@ const test = (binding) => { obj[clazz.kTestAccessorTInternal] = 'instance internal getset 4'; assert.strictEqual(obj[clazz.kTestAccessorTInternal], 'instance internal getset 4'); } + + // own property + { + obj.testSetter = 'own property value'; + // Make sure the properties are enumerable. + assert(Object.getOwnPropertyNames(obj).indexOf('ownProperty') >= 0); + assert(Object.getOwnPropertyNames(obj).indexOf('ownPropertyT') >= 0); + + // Make sure the properties return the right value. + assert.strictEqual(obj.ownProperty, 'own property value'); + assert.strictEqual(obj.ownPropertyT, 'own property value'); + } }; const testMethod = (obj, clazz) => { @@ -84,10 +96,12 @@ const test = (binding) => { }; const testEnumerables = (obj, clazz) => { - // Object.keys: only object - assert.deepEqual(Object.keys(obj), []); + // Object.keys: only object without prototype + assert(Object.keys(obj).length === 2); + assert(Object.keys(obj).includes('ownProperty')); + assert(Object.keys(obj).indexOf('ownPropertyT') >= 0); - // for..in: object + prototype + // for..in: object and prototype { const keys = []; for (let key in obj) {