[Harmony proxies] [[Construct]] semantics breaks the expectation of seeing an object as return value
Tom Van Cutsem
tomvc.be at gmail.com
Fri Sep 23 08:17:05 PDT 2011
I believe the relevant use cases here were value types/value proxies, which
- if added in the future - would want their constructors to return
non-object values. I searched the archives but can't seem to find the
relevant threads, still, I'm sure it was discussed here previously.
2011/9/23 David Bruant <david.bruant at labri.fr>
> In ES5.1 - 13.2.2 is defined functions instances [[Construct]]. As one can
> notice, it always returns something of type Object (as per ES5.1 - 8.6).
> Consequently, a call to "new A()" always reliably either returns an object
> or throws an exception.
> Proxies semantics of [[Construct]] states that (step 5) the [[Call]]
> internal method of constructhandler should be called. It opens the door to
> returning things which are not objects (number, boolean, undefined, ...).
> I can't think of precedents of this for host objects and I don't really see
> a use case in allowing "new A()" to return something else than an object
> When writing functions intended to be used as constructors, people may be
> used of |this| being used as the to-be-returned object and expect this
> behavior even if defining a constructor.
> So i would be in favor of adding a type check between step 5 and 6.
> es-discuss mailing list
> es-discuss at mozilla.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss