[[Class]] Property of Host Object
Garrett Smith
dhtmlkitchen at gmail.com
Sat Jul 17 12:17:40 PDT 2010
On 7/17/10, Mark S. Miller <erights at google.com> wrote:
> [+es5-discuss as a possible errata issue arises below]
>
>
> On Sat, Jul 17, 2010 at 12:37 AM, Garrett Smith
> <dhtmlkitchen at gmail.com>wrote:
>
>> On 7/16/10, Mark S. Miller <erights at google.com> wrote:
>> > On Fri, Jul 16, 2010 at 9:54 PM, Garrett Smith
>> > <dhtmlkitchen at gmail.com>wrote:
>> >
>> >> I have a question reqarding [[Class]] property as defined In ES5:
>> >>
>> >> | The value of the [[Class]] internal property of a host object
>> >> | may be any String value except one of "Arguments", "Array",
>> >> | "Boolean", "Date", "Error", "Function", "JSON", "Math", "Number",
>> >> | "Object", "RegExp", and "String"
>> >>
>> >> May it be something other than a string value? Or must it be a string
>> >> value?
>> >>
>> >
>> > It must be a string value.
>> >
>>
>> The specification says "may".
>>
>
> Ah. I see the ambiguity. "may" there is modifying "any". It should probably
> have been stated:
>
> ...must be a String value and may be any String value except...
>
> In reviewing the document, the possibility that text would allow non-String
> [[Class]]es had not occurred to me. Now that you point it out, and can see
> some reasons why we might want to leave the current text alone and allow
> non-String [[Class]]es.
>
I don't.
[[Class]] must be a string value. If the [[Class]] property is absent,
what happens when the object is supplied to Object.prototype.toString?
TypeError. Why not avoid that possibility and require host object to
have [[Class]] be a string value?
>
>
>>
>> >
>> >>
>> >> Why must a host object's class be none of the built-in classes listed?
>> >>
>> >
>> > So that the [[Class]] property serve as a reliable nominal type check
>> > for
>> > the contract that the other internal properties and methods satisfy.
>> > This
>> is
>> > used primarily within the spec itself. Previously, it wasn't clear what
>> was
>> > meant when the spec said, for example, "if F is a function". Now we
>> clearly
>> > say "if the [[Class]] of F is 'Function' " if that's what we mean.
>> >
>>
>> I think I see the problem.
>>
>> What you really want to say there is:
>>
>> | The value of the [[Class]] internal property of any non-native host
>> | object must be any String value except one of...
>>
>
> Saying "non-native" and "host" together is redundant. Although the language
> of 4.3.6 and 4.3.8 is not as clear as it should be, I read these as stating
> that all EcmaScript objects are either host or native. No object can be both
> host and native. And no object can be neither host nor native.
>
It is not redundant. Repeating what was written in my last message:
| While the specification does not preclude the possibility that a host
| object may be implemented with native semantics, it nonetheless
| defines a host object:
I understand that the values for [[Class]] are used internally by the
specification. One example of that is Array.isArray(x), where the
[[Class]] property is used internally. Another example is behavior for
`JSON` reviver.
The specification allows for two types of host objects:
* host objects as native objects
* host objects as not native objects (does not use native semantics)
More information about the es-discuss
mailing list