[Harmony proxies] [[Construct]] semantics breaks the expectation of seeing an object as return value
david.bruant at labri.fr
Fri Sep 23 06:32:40 PDT 2011
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.
More information about the es-discuss