>> The more important issue is our intent regarding the definitions of "host" 
>> and "native" objects.

First regarding, alert in IE.  Historically it is what it is and nobody should 
make any assumptions concerning the future based upon previous versions of IE 
or what they have observed so for in IE9 preview builds.  I don't think there 
is any disagreement that the [[class]] of alert should be 'Function'. However, 
if you want to pin that down in a standard then WebIDL is probably the place 
you need to do it.

I agree that there is still a lack of clarity in the ES5 spec. regarding the 
definition of "host object" and the distinction between "host" and "native" 
objects.  The ES5 spec. is better than the previous editions in this regard but 
could still be improved.  This isn't an error that can be corrected by an 
errata but it is something that can be improved by rewrites in future editions. 
In particular, the spec. is fuzzy about whether the sets of native and host 
objects are disjoint.

Here is what I believe is the intent:

Native Object: as stated in 4.3.6, an object that fully implements the object 
semantics defined by the Ecma-262 specification. Such objects might be 
built-in, user defined using ECMAScript code, or provided by the host  (and 
that presumably includes libraries of native objects that are accessed via host 
defined facilities).  The important point and the characteristic that makes 
then "native" is that they fully conform to the standards semantics for objects.

Host object: as stated in 4.3.8, an object supplied by the host environment.  
If a host object fully implements the standard object semantics then it is also 
a native object (hence native and host objects are not two disjoint sets).  
However, host objects are not required to implement this standard semantics.  
In addition, the note to 4.3.8 says that any object that isn't native (ie, 
doesn't implement standard object semantics) is a host object.

So essentially, they are two kinds of host objects: native host objects and 
non-native host objects.  The spec. doesn't explicitly talk about native host 
objects because their hostness is semantically irrelevant if they are also 
native.  Hence, when the spec. talks about "host objects" in most cases it is 
really talking about non-native host objects in order to impose specific 
sematic constraints upon them.  I believe that in most cases in the ES5 spec,  
"host object" should be read as meaning "non-native host object".

By these terms, an  Array instance (or other built-in object "class" instance) 
can be a host object but if it is, it must be a native host object. That is, it 
most fully implement the specific semantics for that kind of object.

Allen

From: Mark S. Miller [mailto:erig...@google.com]
Sent: Sunday, July 18, 2010 9:52 AM
To: Allen Wirfs-Brock
Cc: Garrett Smith; es5-disc...@mozilla.org; es-discuss
Subject: Re: [[Class]] Property of Host Object

Hi Allen, that answers the "must is be a String?" issue, thanks.

The more important issue is our intent regarding the definitions of "host" and 
"native" objects. What is your memory of this issue? How well do you think the 
spec reflects this intent?
On Sun, Jul 18, 2010 at 7:31 AM, Allen Wirfs-Brock 
<allen.wirfs-br...@microsoft.com<mailto:allen.wirfs-br...@microsoft.com>> wrote:
Table 8, section 8.6.2
Internal Property: [[Class]]
Value Type Domain: String
Description: A String value indicating a specification defined classification 
of objects

Allen

From: es-discuss-boun...@mozilla.org<mailto:es-discuss-boun...@mozilla.org> 
[mailto:es-discuss-boun...@mozilla.org<mailto:es-discuss-boun...@mozilla.org>] 
On Behalf Of Mark S. Miller
Sent: Saturday, July 17, 2010 12:54 PM
To: Garrett Smith
Cc: es5-disc...@mozilla.org<mailto:es5-disc...@mozilla.org>; es-discuss
Subject: Re: [[Class]] Property of Host Object

In short, I largely agree with you about the language in the ES5 spec text. My 
interpretation of that text derives in large part from my memories of the 
conversations that led up to it, and my sense of the intent we were trying to 
capture. In the absence of that context, I would probably arrive at the same 
reading of ES5 that you have.

At this point, I will wait until others who participated in those conversations 
weigh in and state their sense of our agreed intent. Once we understand what 
agreed intent there actually was, we can proceed from there.

On Sat, Jul 17, 2010 at 12:17 PM, Garrett Smith 
<dhtmlkitc...@gmail.com<mailto:dhtmlkitc...@gmail.com>> wrote:
On 7/17/10, Mark S. Miller <erig...@google.com<mailto:erig...@google.com>> 
wrote:
> [+es5-discuss as a possible errata issue arises below]
>
>
> On Sat, Jul 17, 2010 at 12:37 AM, Garrett Smith
> <dhtmlkitc...@gmail.com<mailto:dhtmlkitc...@gmail.com>>wrote:
>
>> On 7/16/10, Mark S. Miller <erig...@google.com<mailto:erig...@google.com>> 
>> wrote:
>> > On Fri, Jul 16, 2010 at 9:54 PM, Garrett Smith
>> > <dhtmlkitc...@gmail.com<mailto:dhtmlkitc...@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)

>From the implementors point of view, what matters the ability derive
an inference from [[Class]]; if [[Class]] is x then [action]. However,
from a programmer's perspective, `Object.prototype.toString.call(x)`
cannot discriminate between objects originating in the host
environment (what is currently defined as "host object") and native
objects. Mostly they shouldn't care, but should follow the
specification approach to derive [[Class]] based inference, however
they can't follow that because that is not compatible with existing
implementations (notably IE versions and Opera (which copied IE)), and
making an "isStrict" supported global flag is not going to provide a
closely related inference about various types of host objects across a
wide range of implementations in the wild.

Internet Explorer 9 host objects seem to be absent of problems seen in
previous versions of IE but there are still host objects that are
callable, have [[Class]] "Object", and are not implemented with native
semantics. Two examples of such object are alert and addEventListener.

>
>
>>
>> Because that allows `alert` to be any native ECMAScript object
>> (Function, Object, etc), while still letting it be defined as a host
>> object and not violating that spec.
>
>
>
> "that spec"? What specification demands that alert be a host object? I have
I cited 4.3.8; the definition of host object.

> not heard of any. This might be a consequence of the upcoming WebIDL-to-ES5
> language bindings, but I have seen no draft and so have no idea. My own
> preference would be for these language bindings to result in alert being a
> native Function, but that's an argument for a different standards committee
> ;).
>
> If an implementation's alert is a Function, then it is a native object and
> its [[Class]] must be "Function". It can still be an object provided by a
> host environment whose [[Call]] behavior is written in C++. This simply
> makes it a host provided native built-in object (4.3.7), not a host object.
>
No, alert is not a defined by ECMAScript specification. It is
therefore host object, by definition of "host object" in ES5, s 4.3.8.

>
>
>
>> Iff, however, following my
>> proposed amendment, `alert` had [[Class]] "Object", and it was not a
>> native ES object (as in IE versions), then it would be a specification
>> violation.
>>
>> > But it is also used from JS. Host objects are exempt from most of the
>> > specific behaviors specified for specific kinds of native objects. Were
>> > a
>> > host object to be able to allege to be a kind of native object without
>> > behaving as that kind of native object behaves, that would be bad.
>> >
>>
>> This is not in the spec:
>> "without behaving as that kind of native object behaves"
>>
>
> See 4.3.6.
>
That is where native object is defined.

>
>>
>> While the specification does not preclude the possibility that a host
>> object may be implemented with native semantics, it nonetheless
>> defines a host object:
>>
>> | 4.3.8
>> |  host object
>> |  object supplied by the host environment to complete the
>> |  execution environment of ECMAScript.
>> |
>> |  NOTE Any object that is not native is a host object.
>>
>> And that means that `alert`, `window`, `document`, XMLHttpRequest, are
>> all host objects. Whether or not those objects are implemented as
>> native ECMAScript objects is another matter altogether.
>>
>
> This is the crux. The language there is indeed poorly phrased. But native
> objects are not host objects.
>
Where is that stated anywhere in the specification?

> Indeed, it is so poorly phrased that perhaps we should add an errata to
> clean this up. Sigh. cc'ing es5-discuss.
>
>
>>
>> It seems the the spec is wrong and that you have misinterpreted it. I
>> believe that instead it should be written:
>>
>>
> Text missing?
Yes, as I wrote before:

|  The value of the [[Class]] internal property of any non-native host
|  object must be any String value except one of..
The other possibility is that you have misinterpreted the definition
of host object to mean something along the lines of "any object that
is not a native object".

And going by that, referring to the example, `alert` could be a native
object and would then not be a host object.

[...]

>> > (alert instanceof Function) is not a reliable test in either direction.
>>
>> No of course not.
>>
>> A
>> > host object as well as a native non-function is perfectly free to
>> > inherit
>> > from Function.prototype and thus pass this test. And an actual function
>> may
>> > be an instance of Function constructor from another frame and so fail
>> > the
>> > test. But yes, iff alert is indeed a native function, it's [[Class]]
>> should
>> > be "Function".
>> >
>>
>> Therein lies a contradiction: A host object here may be a function.
>>
>
> No it may not. A host object may be callable and it may inherit from
> Function.prototype, but it may not be a function.
>
Once again, ES5 does not preclude the possibility that a host object
may be implemented with native semantics.

>
>> Yet because it is a host object, that same object's [[Class]] must not
>> be "Function", and yet again, since it is a function, and any function
>> must have [[Class]] "Function", then this object's [[Class]] must be
>> "Function".
>>
>> >
>> >
>> >>
>> >> However according to ES5 specs, any host object must not be withing
>> >
>> > the set of values that are not allowable and so the assertion could be
>> >> made that if any object has a [[Class]] that is one of those values,
>> >> then the object is not a host object.
>> >
>> >
>> > Yes, that is intentional.
>>
>> Then it will fail today, as
>>
>> javascript: alert(({}).toString.call(alert))
>>
>> - will result "[object Object]" or "[object Function]"
>>
>
> 1) No current implementations claim ES5 conformance.
> 2) On ES5 conformant implementations, alert may well be a function in which
> case the second result will remain correct.
The only way that could be anything other than a contradiction is if
you have redefined "host object" to be as I suggested above (I'll
repeat that one more time).

`alert` is a host object by definition of host object in s. 4.3.8. It
seems as if you have misinterpreted that definition as: "any object
that is not a native object". Is that how you read it?

That is a significantly different definition than either definition in
Eds 3 or 5.

Ed 3:

|   A host object is any object supplied by the host
|  environment to complete the execution environment of
|  ECMAScript. Any object that is not native is a host object.

Ed 5:
|  object supplied by the host environment to complete
|  the execution environment of ECMAScript.
|
|  NOTE Any object that is not native is a host object.
Perhaps this is a case of denying the antecedent?
1. if (not native) then host object.
2. alert is native,
therefore, alert is not host object. (false conclusion)

<http://en.wikipedia.org/wiki/Denying_the_antecedent>

If the definition of host object is correct then the clause that
mentions "[[Class]]" property must change as I initially suggested.
However, if what appears to be your definition of host object was also
what was intended by the editor, then that definition should be
rewritten instead.

If a host object is defined as being any object supplied by the host
environment that is not a native object, then the spec should state
so. If, however, a host object may be a native object -- and that is
how it is currently defined, then for any host object that is not a
native object, that object's [[Class]] property must not be in the set
of class values for native types.

Garrett



--
    Cheers,
    --MarkM



--
    Cheers,
    --MarkM
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to