[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

Hi David,

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>

> Hi,
> 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.
> David
> ______________________________**_________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/**listinfo/es-discuss<https://mail.mozilla.org/listinfo/es-discuss>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20110923/7a6baee3/attachment.html>

More information about the es-discuss mailing list