David Bruant (2013-07-30T19:40:30.000Z)
domenic at domenicdenicola.com (2013-08-04T22:54:11.193Z)
Le 30/07/2013 18:57, Allen Wirfs-Brock a écrit : > So far in ES<=6 dealing with such private data slots is something that > could be treated in a relatively ad hoc manner within the ES spec. and > by implementations. But in ES7 we really want and need user definable > per instance private data. The issues we are encountering here are a > precursor of the issue we will see down the line and what we do now > may constrain what we can do later. I could not agree more. Should proxies be deferred waiting for private data, then? Or, maybe they can be put in quarantaine in some way. For instance, making the constructor throw if the target isn't a regular object. That's for the time being until the "private state" (whether "private internal slots" or user data) is sorted out. A max-min sort of proxy, I guess. > Tests are normative and you can't write a valid test suite in the > absence of an accurate specification. I was answering to your concern about built-in implementations and memory safety hazard. If a test suite contains a good share of tests to exercise how built-ins react when passed proxies as arguments (including 'this'), this would provide some level of confidence that the implementations aren't too memory unsafe. What the tests exactly returns will of course have to be determine by an accurate spec, no doubt here. I was thinking of tests as a coverage method here, not as a conformance tool. > I also raised this objection and it is what led to the recent update > to the virtual object API referenced above. What that change does is > make it easier for ES programmer to create proxies that behave in this > manner. > > But, in the end we could not come up with a solution for the > Date.prototype.getMonth.call(proxy) issue. The [[Invoke]] MOP > operation/trap was added to minimize the actual occurrence of this > scenario. You can't use 'call' to force a built-in to operate upon > the wrong kind of object. The introduction of [[invoke]] in this particular context might be an instance of "may constrain what we can do later". Specifically, it may collide and feel duplicate if a more generic solution is found for Date.prototype.getMonth.call(proxy); a more "useful" example of which is Set.call(proxy). > ES spec. largely exists to constrain how implementors deal with such > issue in order to guarantee that different implementations have > observably identical behavior. How did the discussion shift from "memory safety issue" to "observably identical behavior"? In any case, I agree with you. > I think you are glossing over real issues that require real design > thinking and which probably can't be addressed until ES7. I think I understand the real issues :-) I don't have a idea to solve them and even less an idea TC39 would agree on, but I understand them. I feel that the [[invoke]] proposal is an attempt to get the maximum out of proxies without addressing them and I wonder whether it would be better to wait. > I complete disagree WRT tests. Tests written without reference to some > normative specification are just a reflection of how their developer > thinks the system should work. Again, I thought of tests as a coverage tool more than a conformance one (though obviously, testing conformance along the way is obviously a nice property, but has to wait for an actual spec) > The ForwardingHandler semantics is close to what you want. The part I'm being insistent on is the delta between what this handler enables and what it does not. The use of 'this' has been special-cased. I understand the biais that leads to this decision, but I don't think it's a good rationale. I think it's an equivalent biais than the one of the original Proxy design where the [[prototype]] was passed to the proxy.create function as if the [[Prototype]] internal property was that special in the MOP. 'this' is the 0th argument of functions (and .call shifts the order making this statement false in absolute terms), there is no good reason to give it a special treatment. > But it still doesn't work the way you would like for direct "call" > invocation or for things like Array.isArray. The base issue for > either of these is that they don't indirect through the proxy handler > and hence the handler doesn't have an opportunity to replace the proxy > reference with the target reference. Wouldn't replacing the proxy reference for the target reference be violating stratification? Per exotic type traps would solve the issue generically, I think. > Do you have new use cases, that motivate the design of an enhanced > Array.isArray? I cited membrane transparency a couple of times. Tom seems to agree. Others have opinions? > It would be quite easy to extend Array.isArray(obj) so that it > delegated back to obj with a @@areYouAnArray method such as we are > doing with @@isRegExp in certain places. However, if we do that you > loose support for the original Array.isArray use case because any > object could decide to return true from Array.isArray. > ... If, for instance, you have an "areYouAnArray" trap that only works if the target is an Array (recursive definition with actual arrays as base case), then Array.isArray isn't spoofable by any object. Mark and Tom once used a expression about direct proxies. Something like "invariant forwarding" or something like that, where the target imposes restrictions on the handler. This could be extended to exotic objects by adding per exotic type only traps. >> This thread feedback brings new data and it seems that the current >> handler offering isn't enough (and I understand can't be). > > yup Glad we agree here :-p