Skip to content

Support instances of classes with private fields #2

@mcmire

Description

@mcmire

When using createSwappableProxy to wrap an object which is an instance of a class and using that object to make a method call which ends up accessing private fields within that class, the following error is produced:

Cannot read private member #secret from an object whose class did not declare it

The proxy object is defined such that when a property is accessed, the same property is accessed on the target object, but nothing more. According to the MDN docs, we would want to wrap all methods such that this is bound to the target object: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy#no_private_property_forwarding

It appears that there are no tests for calling methods on proxy objects, so we should make sure the tests reflect this and also include a test for the bug fix.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions