danShumway / vAnalyze.js

A middleware script that seeks to allow functions in local javascript to be automatically wrapped in custom code wrappers. These can then be used to aid profiling/error checking/code understanding.
GNU General Public License v2.0
4 stars 1 forks source link

ES6 Proxy Proposal as new base for wrapping Functions and Properties #17

Open danShumway opened 9 years ago

danShumway commented 9 years ago

Problem: wrapped functions may not catch existing references to function.

Problem: Host properties need to continually refresh themselves / Host must continuously check for new properties.

Possible future solution: Implement 2-way synchronous data-synchronization using ES6 Proxies and by infecting the prototype chain with invisible objects.

danShumway commented 9 years ago

Basic proposal script is up here: http://jsfiddle.net/danShumway/evrdgxjc/ - reminder that it won't work on Chrome.

This fixes the problem with instanceof as well as demonstrates some test cases. Basically the way that it works is to generate an Infection object (distinct from what we normally return) that is attached to the prototype of a Host. The code is then returned a Proxy object linked to that Infection.

The result is that accessing either object will result in up-to-date information about the other object.

To adapt this to vAnalyze's use-case, I would likely attach additional code to the call handler, as well as log additional information whenever anything is accessed via the proxy.