[Bug 22808] Throw if object is constructed without new

https://www.w3.org/Bugs/Public/show_bug.cgi?id=22808

--- Comment #17 from Allen Wirfs-Brock <allen@wirfs-brock.com> ---
(In reply to Boris Zbarsky from comment #16)

The problem is that many of the ECMAScript library constructors, which are
allspecified to be "Built-In Function objects", do support being "called as a
function". So if we added [[FunctionKind]] to Built-in Function I would also
have to specify it's setting for each ES built-in.  I might consider doing that
if I wasn't within about a week of having to freeze the final ES6 draft.

As an alternative approach consider treating this similarly to what you do for
parameter type checking. You can determine whether you are called by as
function rather than via [[Construct]] by checking the value of NewTarget.  It
has the value undefined if the function is being invoked via [[Call]]. 

So, in your WebIDL parameter checking also check NewTarget (for constructors).

This is essentially what the ES6 spec. does,  individually for each built-in
constructor that is not callable.  For example see:
http://people.mozilla.org/~jorendorff/es6-draft.html#sec-map-iterable

-- 
You are receiving this mail because:
You are on the CC list for the bug.

Received on Monday, 9 February 2015 18:34:57 UTC