W3C home > Mailing lists > Public > public-script-coord@w3.org > October to December 2010

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

From: Allen Wirfs-Brock <Allen.Wirfs-Brock@microsoft.com>
Date: Tue, 12 Oct 2010 18:09:58 +0000
To: Maciej Stachowiak <mjs@apple.com>, Cameron McCormack <cam@mcc.id.au>
CC: Garrett Smith <dhtmlkitchen@gmail.com>, "Mark S. Miller" <erights@google.com>, James Graham <jgraham@opera.com>, Travis Leithead <travil@microsoft.com>, Simon Pieters <simonp@opera.com>, "public-script-coord@w3.org" <public-script-coord@w3.org>, "annevk@opera.com" <annevk@opera.com>
Message-ID: <90EDC335A511F2479C63F7337D3CE7DB59624A5B@TK5EX14MBXC116.redmond.corp.microsoft.com>
> -----Original Message-----
> From: public-script-coord-request@w3.org [mailto:public-script-coord-
> request@w3.org] On Behalf Of Maciej Stachowiak
> Sent: Thursday, October 07, 2010 11:09 PM
> To: Cameron McCormack
> Cc: Garrett Smith; Mark S. Miller; James Graham; Travis Leithead; Simon Pieters;
> public-script-coord@w3.org; annevk@opera.com
> Subject: Re: [WebIDL] interface objects with [Constructor] and [[Call]]
> And in fact, some built-in objects have behavior "when called as a constructor"
> which cannot be explained as the 13.2.2 [[Construct]] algorithm invoking their
> [[Call]] behavior. One example is the String constructor. The spec doesn't seem
> to explicitly define its [[Call]] and [[Construct]] internal properties, but this is the
> only sane interpretation.
> Regards,
> Maciej

There is a paragraph near the end of the introductory section of ES5 Chapter 15 that says:

"This clause generally describes distinct behaviours for when a constructor is "called as a function" and for when it is "called as part of a new expression". The "called as a function" behaviour corresponds to the invocation of the constructor's [[Call]] internal method and the "called as part of a new expression" behaviour corresponds to the invocation of the constructor's [[Construct]] internal method. "

My recollection is that this text grew out of  a discussion of this on either the es-discuss list or perhaps it was at a f2f meeting.  Some of the various chapter 15 functions  either "when called as a constructor" or "when called as function" do things that cannot be directly expressed as a pure ECMAScript function definition.  In addition, chapter 15 does not specify exactly how its functions are to be implemented.  Using ECMAScript code to implement them is presumably valid, if that code can fully expressed the required semantics.  However, implementing them using non-ECMAScript code is also valid (and generally the norm).

The definitions of [[Call]] and [[Construct]] in 13.2 specifically applies to function objects whose behavior is specified via a /FunctionBody/.  In other words, functions defined using ECMAScript code via a /FunctionDeclaration/, /FunctionExpression/, or a call to the Function constructor. 

The chapter 15 functions are not necessarily defined in this manner, so the 13.2 definitions of [[Call]] and [[Construct]] don't necessarily apply to them. 

Given that fact and the spec. language quoted above, the most reasonable way to interpret chapter 15 is as a set of specifications for objects with distinct [[Call]] and [[Construct]]  internal methods.  The algorithms in chapter 15 are the definitions of the [[Call]] or [[Construct]] internal methods of the corresponding objects.  When an algorithm is for the "when called as a constructor" case it is specifying the [[Call]] internal method of the object.  When an algorithm  is specified for the "when called as a function" case or is a non-constructor object it is specifying the [[Call]] internal method.  Constructors general have both forms and hence they specify both [[Call]] and [[Construct]] behaviors.  Most non-constructor chapter 15 function only specify [[Call]] behavior.  In fact, Chapter 15 explicitly says: " None of the built-in functions described in this clause that are not constructors shall implement the [[Construct]] internal method unless otherwise specified in the description of a particular function. "

Received on Tuesday, 12 October 2010 18:10:38 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 17:14:02 UTC