VirtualHandler fundamental traps default values

Tom Van Cutsem tomvc.be at gmail.com
Tue Sep 11 12:14:23 PDT 2012


I just updated the "virtual object API" wiki page to reflect the proposed
changes from the July meeting.

I agree that having Handler.prototype inherit from Reflect is actually
sensible. As currently specified, Handler.prototype simply delegates all
fundamental traps to the Reflect object. We have a tool to automate such
code, and it's called prototypal inheritance :-)

Note that in ES6, Reflect should probably be represented as a module
instance, not as a global object. So then Handler.prototype would inherit
from a module instance object. I don't see anything necessarily wrong with
that, but I just want to point it out.

Cheers,
Tom

2012/9/1 David Bruant <bruant.d at gmail.com>

> Hi,
>
> 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") [1]. 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 [2] is here for.
> This one is not implemented yet in Firefox [3], but I thought a bit more
> about how I would use it.
>
> Line 53 [4], 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
> fundamental traps.
> 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
> --> null
> VirtualHandler would just be one (convenient) way to override Reflect to
> generate handlers.
>
> David
>
> [1] https://github.com/DavidBruant/HarmonyProxyLab/tree/master/ProxyArray
> [2] http://wiki.ecmascript.org/doku.php?id=harmony:virtual_object_api
> [3] https://bugzilla.mozilla.org/show_bug.cgi?id=787713
> [4]
>
> https://github.com/DavidBruant/HarmonyProxyLab/blob/master/ProxyArray/ProxyArray.js#L53
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120911/79cfc02b/attachment.html>


More information about the es-discuss mailing list