Re: [WebIDL] interface objects with [Constructor] and [[Call]]

On 10/7/10, Cameron McCormack <cam@mcc.id.au> wrote:
> Garrett Smith:
>> ECMA-262 [[Construct]] requires the target object to have a [[Call]]
>> property. It appears that you may have been misled by Maciej
>> Stachowiak's comment:
>>
>> "Another possibility when there are no legacy constraints is to not
>> implement [[Call]], so that there is only one way to invoke the
>> constructor."
>>
>> The problem with that statement is that the algorithm for
>> [[Construct]] invokes the object's [[Call]] property and so if the
>> new'd object does not implement [[Call]], then a TypeError would
>> result.
>
> Is that just for native Function objects, or for host objects as well?
> I see that the native Function object [[Construct]] (section 13.2.2 of
> ES5) calls [Call]], but I couldn’t find a requirement that host objects
> that implement [[Construct]] must also implement [[Call].
>

My statement in the previous paragraph is regarding the algorithm for
[[Construct]], as specified in ECMA-262. Were you discussing a
different [[Construct]]?

In ECMA-262, step 6 of [[Construct]] is:
| 6. Invoke the [[Call]] property of F, providing Result(1)
| as the this value and providing the argument list passed
| into [[Construct]] as the argument values.

Understand that an object that implements [[Construct]] implements
[[Call]]. What is not known is what either of those commands will do.
That is what specification is for.

How can an object implement [[Construct]] but not [[Call]]?

I get what you're after here, you want to specify that certain
constructors throw a TypeError if not invoked via [[Construct]]. So
its just a matter of putting that into specification terminology.

> For consistency, since that’s always the case with the built-ins, it’s
> probably a good idea.  Of course, you could always implement [[Call]] as
> just:
>
>   1. Throw a TypeError.
>
> :)
>
No, because then [[Construct]] would, by implication, have that effect
as well ([[Construct]] -> [[Call]] -> TypeError).

It seems you want to say: "When [XXX] is called as a function the
result is a TypeError."
-- 
Garrett

Received on Friday, 8 October 2010 05:26:49 UTC