VirtualHandler fundamental traps default values
bruant.d at gmail.com
Sat Sep 1 12:58:40 PDT 2012
Direct proxies landed in Firefox a couple of days ago, so I thought I'd
rewrite every sample I had written to the new API.
I have started with the emulation of native arrays with proxies (and
"normal objects") . Most of my tests related to the proxyArray length
fail because I only override the defineProperty trap (but not the get
trap). That's fine, that's what the VirtualHandler API  is here for.
This one is not implemented yet in Firefox , but I thought a bit more
about how I would use it.
Line 53 , I use "this.delete" (this refers to the handler). Since I
don't override the delete trap, this will throw an error (by definition
of the VirtualHandler API as currently specified).
In my case, I will have to override the delete trap with Reflect.delete
(to respect ES5.1 specification of an array). Likewise for all
An alternative to throwing for missing trap is using the corresponding
method in the Reflect module as mention in the wiki page open issue. I
think it would be a good idea here.
To go further with this idea, VirtualHandler.prototype, instead of
inheriting from Object.prototype could inherit from Reflect. And a
virtual handler instance prototype chain would then look like:
instance --> VirtualHandler.prototype --> Reflect --> Object.prototype
VirtualHandler would just be one (convenient) way to override Reflect to
More information about the es-discuss