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
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to