Closed Bug 911553 Opened 12 years ago Closed 12 years ago

Proxy cannot trap ToPrimitive toString/valueOf calls

Categories

(Core :: JavaScript Engine, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla26

People

(Reporter: anba, Assigned: yaron.tausky)

Details

Attachments

(1 file, 2 obsolete files)

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])})
I think I found the problem, but I'm not sure who could review this. Any suggestions?
Comment on attachment 798540 [details] [diff] [review] 911553_fix_proxy_defaultvalue.patch v1 I'm volunteering efaust.
Attachment #798540 - Flags: review?(efaustbmo)
A |using BaseProxyHandler::defaultValue;| would be simpler, if possibly less expressive/breakpointable. I dunno which I'd prefer.
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 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-
Right, it does make more sense. Here's the revised patch.
Attachment #798540 - Attachment is obsolete: true
Attachment #799351 - Flags: review?(bobbyholley+bmo)
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+
Okay, added the comment. Carrying over the r+.
Attachment #799351 - Attachment is obsolete: true
Attachment #799832 - Flags: review+
Status: NEW → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla26
Assignee: general → yaron.tausky
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: