You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ObjectWrap: enumerable properties seem to be broken #644
@gabrielschulhof
thanks, but using DefineClass() with InstanceAccessor(...,napi_enumerable) to specify per instance properties, the specified properties are not enumerable on the instance.
As @legendecas mentioned, this is because the properties are defined on the prototype and not on the instance
So having an instance obj of the ObjectWrap subclass, a call to Object.getOwnPropertyNames(obj) or Object.keys(obj) returns an empty array, JSON.stringify(obj) results in "{}", a.s.o.
@gms1 AFAICT #645 demonstrates that defining own properties as enumerable works. Thus, #645 doesn't fix this issue because this is not an issue. We'll keep and land #645 because it's a good test, but I don't think we can claim that it fixes this issue.
Activity
legendecas commentedon Jan 5, 2020
Instance property accessors are defined on class prototypes, not on class instances.
Try:
gms1 commentedon Jan 5, 2020
many thanks!
Is there a way to define enumerable properties on the class instance?
something like this from within the c-tor?
didn't get it working and have not found anything in the documentation or in the examples
gabrielschulhof commentedon Jan 5, 2020
@gms1 you specify per-instance properties as a parameter to the
DefineClass()call in yourObjectWrapsubclass.gms1 commentedon Jan 6, 2020
@gabrielschulhof
thanks, but using
DefineClass()withInstanceAccessor(...,napi_enumerable)to specify per instance properties, the specified properties are not enumerable on the instance.As @legendecas mentioned, this is because the properties are defined on the
prototypeand not on the instanceSo having an instance
objof theObjectWrapsubclass, a call toObject.getOwnPropertyNames(obj)orObject.keys(obj)returns an empty array,JSON.stringify(obj)results in"{}", a.s.o.gabrielschulhof commentedon Jan 6, 2020
@gms1 confirmed. The following test fails:
gms1 commentedon Jan 6, 2020
many thanks! the test fails as it should:
gabrielschulhof commentedon Jan 7, 2020
@gms1 AFAICT #645 demonstrates that defining own properties as enumerable works. Thus, #645 doesn't fix this issue because this is not an issue. We'll keep and land #645 because it's a good test, but I don't think we can claim that it fixes this issue.