-
Notifications
You must be signed in to change notification settings - Fork 461
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ObjectWrap: enumerable properties seem to be broken #644
Comments
Instance property accessors are defined on class prototypes, not on class instances. Try: assert.strictEqual(Object.getOwnPropertyDescriptor(Object.getPrototypeOf(obj), 'testGetter').enumerable, true); |
many thanks!
didn't get it working and have not found anything in the documentation or in the examples |
@gms1 you specify per-instance properties as a parameter to the |
@gabrielschulhof |
@gms1 confirmed. The following test fails: diff --git a/test/objectwrap.cc b/test/objectwrap.cc
index 0d61171..9c61f9e 100644
--- a/test/objectwrap.cc
+++ b/test/objectwrap.cc
@@ -29,6 +29,22 @@ public:
finalizeCb_ = Napi::Persistent(info[0].As<Napi::Function>());
}
+ // Create an own instance property.
+ info.This().As<Napi::Object>().DefineProperty(
+ Napi::PropertyDescriptor::Accessor(info.Env(),
+ info.This().As<Napi::Object>(),
+ "ownProperty",
+ OwnPropertyGetter,
+ napi_enumerable));
+
+ // Create an own instance property with a templated function.
+ info.This().As<Napi::Object>().DefineProperty(
+ Napi::PropertyDescriptor::Accessor<OwnPropertyGetter>("ownPropertyT",
+ napi_enumerable));
+ }
+
+ static Napi::Value OwnPropertyGetter(const Napi::CallbackInfo& info) {
+ return Napi::Number::New(info.Env(), 42);
}
void Setter(const Napi::CallbackInfo& /*info*/, const Napi::Value& value) {
diff --git a/test/objectwrap.js b/test/objectwrap.js
index de16a60..dd2b628 100644
--- a/test/objectwrap.js
+++ b/test/objectwrap.js
@@ -72,6 +72,17 @@ const test = (binding) => {
obj[clazz.kTestAccessorTInternal] = 'instance internal getset 4';
assert.strictEqual(obj[clazz.kTestAccessorTInternal], 'instance internal getset 4');
}
+
+ // own property
+ {
+ // 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, 42);
+ assert.strictEqual(obj.ownPropertyT, 42);
+ }
};
const testMethod = (obj, clazz) => { |
many thanks! the test fails as it should: - assert.deepEqual(Object.keys(obj), []);
+ assert.deepEqual(Object.keys(obj), ['ownProperty', 'ownPropertyT']); |
in 'test/objectwrap.cc' the property 'testGetter' is defined as enumerable:
but testing if this property is enumerable:
fails with:
The text was updated successfully, but these errors were encountered: