Closed
Bug 911553
Opened 12 years ago
Closed 12 years ago
Proxy cannot trap ToPrimitive toString/valueOf calls
Categories
(Core :: JavaScript Engine, defect)
Core
JavaScript Engine
Tracking
()
RESOLVED
FIXED
mozilla26
People
(Reporter: anba, Assigned: yaron.tausky)
Details
Attachments
(1 file, 2 obsolete files)
|
7.40 KB,
patch
|
yaron.tausky
:
review+
|
Details | Diff | Splinter Review |
Test case:
""+new Proxy({toString:() => "inner toString"}, {get:(t, pk) => (pk === "toString" ? () => "proxy toString" : t[pk])})
Expected:
"proxy toString" is returned
Actual:
"inner toString" is returned
The same problem can be reproduced with "valueOf":
""+new Proxy({valueOf:() => "inner valueOf"}, {get:(t, pk) => (pk === "valueOf" ? () => "proxy valueOf" : t[pk])})
| Assignee | ||
Comment 1•12 years ago
|
||
I think I found the problem, but I'm not sure who could review this. Any suggestions?
Comment 2•12 years ago
|
||
Comment on attachment 798540 [details] [diff] [review]
911553_fix_proxy_defaultvalue.patch v1
I'm volunteering efaust.
Attachment #798540 -
Flags: review?(efaustbmo)
Comment 3•12 years ago
|
||
A |using BaseProxyHandler::defaultValue;| would be simpler, if possibly less expressive/breakpointable. I dunno which I'd prefer.
Comment 4•12 years ago
|
||
Comment on attachment 798540 [details] [diff] [review]
911553_fix_proxy_defaultvalue.patch v1
I volunteer bholley. ;)
Attachment #798540 -
Flags: review?(efaustbmo) → review?(bobbyholley+bmo)
Comment 5•12 years ago
|
||
Comment on attachment 798540 [details] [diff] [review]
911553_fix_proxy_defaultvalue.patch v1
Review of attachment 798540 [details] [diff] [review]:
-----------------------------------------------------------------
This works, but it leaves us with a a slightly unintuitive inheritance hierarchy:
BaseProxyHandler (Runs the [[DefaultValue]] algorithm on the proxy, invoking other traps)
||
||
DirectProxyHandler (Runs the [[DefaultValue]] algorithm on the target object, ignoring handler traps)
// || \\
// || \\
SPH Wrapper SIPH
Where both ScriptedProxyHandler and ScriptedIndirectProxyHandler explicitly need to bounce back to the BaseProxyHandler version, and Wrapper uses the DPH version, which actually exists for Wrapper-related and non-ES6-related reasons.
So I think the more correct solution is to hoist the DirectProxyHandler::defaultValue override into Wrapper, and remove the overrides in SPH and SIPH.
Attachment #798540 -
Flags: review?(bobbyholley+bmo) → review-
| Assignee | ||
Comment 6•12 years ago
|
||
Right, it does make more sense. Here's the revised patch.
Attachment #798540 -
Attachment is obsolete: true
Attachment #799351 -
Flags: review?(bobbyholley+bmo)
Comment 7•12 years ago
|
||
Comment on attachment 799351 [details] [diff] [review]
911553_fix_proxy_defaultvalue.patch v2
Review of attachment 799351 [details] [diff] [review]:
-----------------------------------------------------------------
This looks great. r=bholley
Thanks for the patch!
::: js/src/jswrapper.cpp
@@ +22,5 @@
> using namespace js::gc;
>
> int js::sWrapperFamily;
>
> +bool
Please add a comment here indicating that wrappers forward directly to the target for efficiency, and transparency in a few edge cases.
Attachment #799351 -
Flags: review?(bobbyholley+bmo) → review+
| Assignee | ||
Comment 8•12 years ago
|
||
Okay, added the comment. Carrying over the r+.
Attachment #799351 -
Attachment is obsolete: true
Attachment #799832 -
Flags: review+
| Assignee | ||
Updated•12 years ago
|
Keywords: checkin-needed
Comment 9•12 years ago
|
||
Flags: in-testsuite+
Keywords: checkin-needed
Comment 10•12 years ago
|
||
Status: NEW → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla26
Updated•12 years ago
|
Assignee: general → yaron.tausky
You need to log in
before you can comment on or make changes to this bug.
Description
•