Closed
Bug 778085
Opened 12 years ago
Closed 12 years ago
Implement getPrototype proxy trap
Categories
(Core :: JavaScript Engine, defect)
Core
JavaScript Engine
Tracking
()
RESOLVED
FIXED
mozilla17
People
(Reporter: bholley, Assigned: bholley)
References
(Depends on 1 open bug)
Details
(Whiteboard: [js:t])
Attachments
(7 files)
(deleted),
patch
|
ejpbruel
:
review+
|
Details | Diff | Splinter Review |
(deleted),
patch
|
luke
:
review+
|
Details | Diff | Splinter Review |
(deleted),
patch
|
ejpbruel
:
review+
|
Details | Diff | Splinter Review |
(deleted),
patch
|
ejpbruel
:
review+
|
Details | Diff | Splinter Review |
(deleted),
patch
|
ejpbruel
:
review+
|
Details | Diff | Splinter Review |
(deleted),
patch
|
ejpbruel
:
review+
|
Details | Diff | Splinter Review |
(deleted),
patch
|
efaust
:
review+
|
Details | Diff | Splinter Review |
Right now, proxies don't function under normal prototype semantics, which makes them difficult to use on the prototype chain. Specifically, if the JS engine encounters a proxy on the prototype chain, it will call the getPropertyDescriptor and then return. If the proxy wants to bounce lookups up the prototype chain, it has to do so manually.
According to Eddy, there's currently some spec discussion about how to properly integrate prototypes with proxies. In the near-term though, here's a proposal for a simple solution:
Add a getPrototype trap to BaseProxyHandler. Make it optional (with a flag or something), and keep the default behavior the same. Then, figure out the places in the JS engine where we call the non-own variants of various proxy traps. If the proxy implements the getPrototype trap, the caller should do an |own| lookup on the object and bounce to the prototype on failure.
This is straightforward for getPropertyDescriptor and getPropertyNames. I can imagine it being tricky for the various derived traps, because DirectProxyHandler forwards those directly to the target object in order to transparently handle things like PropertyOps. I _think_ they're all manageable though with sufficient creativity.
Updated•12 years ago
|
Whiteboard: [js:t]
Comment 1•12 years ago
|
||
Would be nice for DOM proxies, for sure!
Assignee | ||
Comment 2•12 years ago
|
||
This blocks my XBL stuff, so I'm working on it.
Assignee: general → bobbyholley+bmo
Assignee | ||
Updated•12 years ago
|
Summary: Implement getProto proxy trap → Implement getPrototype proxy trap
Comment 3•12 years ago
|
||
Check out the 'proto and proxies' section:
http://wiki.ecmascript.org/doku.php?id=harmony:direct_proxies#discussed_during_tc39_july_2012_meeting_microsoft_redmond
Assignee | ||
Comment 4•12 years ago
|
||
Attachment #647623 -
Flags: review?(ejpbruel)
Assignee | ||
Comment 5•12 years ago
|
||
Attachment #647624 -
Flags: review?(luke)
Assignee | ||
Comment 6•12 years ago
|
||
Attachment #647625 -
Flags: review?(ejpbruel)
Assignee | ||
Comment 7•12 years ago
|
||
These are helpful for testing, and will also be useful in XPConnect. Note that the Wrapper
and Proxy hierarchy will soon be merged.
Attachment #647626 -
Flags: review?(ejpbruel)
Assignee | ||
Comment 8•12 years ago
|
||
This allows us to test this stuff in script.
Attachment #647627 -
Flags: review?(ejpbruel)
Assignee | ||
Comment 9•12 years ago
|
||
Attachment #647628 -
Flags: review?(ejpbruel)
Updated•12 years ago
|
Attachment #647624 -
Flags: review?(luke) → review+
Comment 10•12 years ago
|
||
Comment on attachment 647623 [details] [diff] [review]
Part 1 - Add optional getPrototypeOf trap. v1
Review of attachment 647623 [details] [diff] [review]:
-----------------------------------------------------------------
This patch looks good in principle, but should getPrototypeOf be optional? The default implementation, BaseProxyHandler::getPrototypeOf, does the same thing as ObjectImpl::getProto does right now (i.e. it returns the prototype of the proxy object). Assuming that you intend to reimplement ObjectImpl::getProto to forward to the getPrototypeOf trap (which is what I would do), making it mandatory does not change any semantics, and does not require any changes in existing code. Making getPrototypeOf the only optional Proxy trap seems unnecessarily complex, unless you had a good reason for it.
r- for now, at least until either one of us convinces the other that he is right :-)
Attachment #647623 -
Flags: review-
Comment 11•12 years ago
|
||
Ok, so looking at part 4 it seems that you made getPrototype an optional trap because certain traps, such as BaseProxyHandler::has would never be called if you made getPrototype mandatory. However, to take the has trap as an example, the only reason this is so is that you reimplemented Proxy::has in term of the getPrototypeOf and hasOwn traps. This makes sense, but I feel like this should be more properly done on the has trap itself.
To be more precise, I think Proxy::has should stay as it is, and BaseProxyHandler::has should be reimplemented in terms of getPrototypeOf and hasOwn (ditto for the other derived traps). This would allow getPrototypeOf to become a mandatory trap, something that seems necessary anyway because direct proxies will have both getPrototypeOf and has, as per spec: http://wiki.ecmascript.org/doku.php?id=harmony:direct_proxies.
Comment 12•12 years ago
|
||
Comment on attachment 647625 [details] [diff] [review]
Part 3 - Add prototype suppport in Proxy::foo implementations. v1
Review of attachment 647625 [details] [diff] [review]:
-----------------------------------------------------------------
r- due to my previous comment. I hope I'm not being overly anal here :-)
Attachment #647625 -
Flags: review-
Comment 13•12 years ago
|
||
Since the remaining patches are based on the assumption that getPrototypeOf should be optional, I'll wait with reviewing them until bholley and I have reached a agreement on what approach to take.
I don't entirely understand what's happening in this bug. However, it would be really helpful to me if the prototype of a cross-compartment wrapper were lazily computed (by wrapping the target's proto on-demand). Hopefully that would allow us to remove the code here:
http://hg.mozilla.org/mozilla-central/file/030feb4315fc/js/src/jscompartment.cpp#l266
which has been causing lots of problems for me, and which doesn't really make sense given the mutability of __proto__.
Is it possible that this bug could accomplish this? If so, I would be extremely grateful.
Assignee | ||
Comment 15•12 years ago
|
||
(In reply to Bill McCloskey (:billm) from comment #14)
> I don't entirely understand what's happening in this bug. However, it would
> be really helpful to me if the prototype of a cross-compartment wrapper were
> lazily computed (by wrapping the target's proto on-demand). Hopefully that
> would allow us to remove the code here:
>
> http://hg.mozilla.org/mozilla-central/file/030feb4315fc/js/src/jscompartment.
> cpp#l266
> which has been causing lots of problems for me, and which doesn't really
> make sense given the mutability of __proto__.
>
> Is it possible that this bug could accomplish this? If so, I would be
> extremely grateful.
This bug as it stands will not do that. But we could maybe get there. I'll be in MV the week of the 20th. We could meet up and talk about it then?
Comment 16•12 years ago
|
||
Comment on attachment 647623 [details] [diff] [review]
Part 1 - Add optional getPrototypeOf trap. v1
Review of attachment 647623 [details] [diff] [review]:
-----------------------------------------------------------------
Figured out a way with bholley to make these patches work with direct proxies once they get the getPrototypeOf trap. The idea is to add a bitmap that allows a proxy to tell whether it has an explicit override for each non-own trap. An alternative solution would have been to simply have a default implementation for each non-own trap in terms of getPrototypeOf and the corresponding own trap, but if a proxy provides an explicit override in this case, we are already in the compartment of the wrappee (in the case of CrossCompartmentWrapper), so this is problematic. We would have to re-enter the compartment of the wrapper in this case. Either way, the bitmap solution involves the least change to the existing proxy hierarchy, which is why it is preferred.
Now that we have this solution, this patch is ok as it stands.
Attachment #647623 -
Flags: review?(ejpbruel)
Attachment #647623 -
Flags: review-
Attachment #647623 -
Flags: review+
Comment 17•12 years ago
|
||
Comment on attachment 647625 [details] [diff] [review]
Part 3 - Add prototype suppport in Proxy::foo implementations. v1
Review of attachment 647625 [details] [diff] [review]:
-----------------------------------------------------------------
I'd just like to say that I *hate* the fact that we use a macro in this patch. That's XPConnect crap. We don't do that in SpiderMonkey :-P
Seriously though, I don't see any other way to avoid unnecessary code duplication here, so I guess I'll have to go along with it ;-)
Attachment #647625 -
Flags: review?(ejpbruel)
Attachment #647625 -
Flags: review-
Attachment #647625 -
Flags: review+
Comment 18•12 years ago
|
||
Comment on attachment 647626 [details] [diff] [review]
Part 4 - Add simple withPrototype versions of DirectWrapper and CrossCompartmentWrapper. v1
Review of attachment 647626 [details] [diff] [review]:
-----------------------------------------------------------------
Nothing wrong with this patch :-)
Attachment #647626 -
Flags: review?(ejpbruel) → review+
Updated•12 years ago
|
Attachment #647627 -
Flags: review?(ejpbruel) → review+
Updated•12 years ago
|
Attachment #647628 -
Flags: review?(ejpbruel) → review+
Assignee | ||
Comment 19•12 years ago
|
||
Thanks Eddy!
Pushed to try: https://tbpl.mozilla.org/?tree=Try&rev=3b864d646268
Assignee | ||
Comment 20•12 years ago
|
||
Sigh. Some new handle API stuff landed that broke stuff when I rebased these patches. Let's pass the handles in a few more places.
Updated•12 years ago
|
Attachment #650817 -
Flags: review+
Assignee | ||
Comment 21•12 years ago
|
||
Trying again: https://tbpl.mozilla.org/?tree=Try&rev=221ea4d810cc
Assignee | ||
Comment 22•12 years ago
|
||
Looks green! Pushed to m-i:
https://hg.mozilla.org/integration/mozilla-inbound/rev/4c02e5467a98
https://hg.mozilla.org/integration/mozilla-inbound/rev/595868a94674
https://hg.mozilla.org/integration/mozilla-inbound/rev/087ae309f7dd
https://hg.mozilla.org/integration/mozilla-inbound/rev/b591dd65cc5d
https://hg.mozilla.org/integration/mozilla-inbound/rev/5159ce49551c
https://hg.mozilla.org/integration/mozilla-inbound/rev/a014e9ee1ed5
https://hg.mozilla.org/integration/mozilla-inbound/rev/440c8b75f1ce
Comment 23•12 years ago
|
||
https://hg.mozilla.org/mozilla-central/rev/4c02e5467a98
https://hg.mozilla.org/mozilla-central/rev/595868a94674
https://hg.mozilla.org/mozilla-central/rev/087ae309f7dd
https://hg.mozilla.org/mozilla-central/rev/b591dd65cc5d
https://hg.mozilla.org/mozilla-central/rev/5159ce49551c
https://hg.mozilla.org/mozilla-central/rev/a014e9ee1ed5
https://hg.mozilla.org/mozilla-central/rev/440c8b75f1ce
Status: NEW → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla17
Comment 24•12 years ago
|
||
You need to log in
before you can comment on or make changes to this bug.
Description
•