Join GitHub today
Store private fields on objects (take 2) #495
This is another take at what #487 was trying to accomplish.
The idea is to have the object represented by an empty (public) table forwarding all field accesses via a metatable to the real (private) table . The metatable would reject all unwanted accesses and the object methods would work on the private instance directly and thus have unhindered access to private fields.
"Privateness" is determined by a certain prefix, as before, but I had to change it to keep "private_mode" property name, so now it's "_" that marks a property or method as private.
I have also adjusted "is_wrapped" detection a bit. previously it would go and check the object's metatable for
Current coverage is 86.11% (diff: 100%)
@@ master #495 diff @@ ========================================== Files 40 40 Lines 4978 4976 -2 Methods 0 0 Messages 0 0 Branches 690 688 -2 ========================================== - Hits 4311 4285 -26 - Misses 507 530 +23 - Partials 160 161 +1
Just tried to move method wrapping into object wrapping stage, but emulation tests started to fail, because they relied on modifying
If the class is not normally available, I guess we can move back to "on-access" wrapping and just disallow setting properties on
@kmike, what do you think?