From: Asen Bozhilov on
Thomas 'PointedEars' Lahn wrote:

> If so, IMNSHO that could not be farther from the truth.  With regard to
> Mozilla, it is pretty simple (I think): If it is defined in JavaScript, it
> is a native object (even if it is a standards-compliant extension of
> ECMAScript, like forEach()); if it is defined for the Gecko DOM instead, it
> is/refers to a host object (like `document').

And you think LiveConnect objects are native?
<URL: https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference#LiveConnect
/>
From: Jorge on
On Mar 22, 7:21 pm, Dr J R Stockton <reply1...(a)merlyn.demon.co.uk>
wrote:
> In comp.lang.javascript message <41a8ac2a-6368-4a40-87ab-842a3f0c7fec(a)e1
> g2000yqh.googlegroups.com>, Sun, 21 Mar 2010 15:42:33, Peter Michaux
> <petermich...(a)gmail.com> posted:
>
> >On Mar 21, 4:02 pm, Garrett Smith <dhtmlkitc...(a)gmail.com> wrote:
> >> Potential alternative question:
> >> "What is a host object?"
>
> >That is a way better question and the answer will be much more
> >valuable.
>
> "DOM" is commonly used in the group - over 10% of the articles currently
> in my newsbase include the acronym - and should be explained in the FAQ.

The (html) DOM deserves a chapter of its own.

An entry to aid in distinguishing between ES built-ins and host-
provided objects too.
--
Jorge.
From: kangax on
On 3/22/10 5:10 PM, Asen Bozhilov wrote:
> Thomas 'PointedEars' Lahn wrote:
>
>> What is true is that host objects *do* *not* *need* *to* implement the
>> internal properties and methods as their specified algorithms describe,
>> but they do need to implement those properties and methods (8.6.2), and
>> they MAY implement them as specified.
>
> It's not true. Specification is completely about this case:
>
> | 8.6.2
> | The following table summarises the internal properties
> | used by this specification. The description indicates their
> | behaviour for native ECMAScript objects.
> | Host objects may implement these internal methods with any
> | implementation-dependent behaviour, or it may be
> | that a host object implements only some internal methods and
> | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> | not others.
> ^^^^^^^^^^^^

But look further ;)

"Every object (including host objects) must implement the [[Prototype]]
and [[Class]] properties and the [[Get]], [[Put]], [[CanPut]],
[[HasProperty]], [[Delete]], and [[DefaultValue]] methods. (Note,
however, that the [[DefaultValue]] method may, for some objects, simply
throw a TypeError exception.)"

>
> Native objects should follow specification in "8.6.2" and if they
> differ from that behavior, they are host objects. Think about it.

I see what you mean about non-specified behavior and host objects.

The problem here, as I see it, is that ES3 and ES5 differ in
explanations of what host objects are. ES3 basically says that host
object is anything that's not a native object, where native object is
"[...] any object *supplied* by an ECMAScript implementation". It's not
clear if "supplied" refers to *binding* (which is what I emphasized on)
or *behavior*/*semantics* (which is what you emphasized on). To muddy
the water even more, ES3 goes on to bring "standard" word into the
picture � saying "*Standard* native objects are defined in this
specification", implying that there could be *non-standard* native objects.

Now, ES5 rewords slightly what "native object" means: "[...] object in
an ECMAScript implementation whose semantics are fully defined by this
specification rather than by the host environment.". So now there's
"semantics", which wasn't there before (and which could well be a
clarification on what ES3 failed to mention). But again, a note
following that definition confuses the matters with "*standard* native
object".

What's strange to me about your definition, is that ES5 only indirectly
defines host objects as something, semantics of which is not defined in
specs. 4.3.8 clearly focuses on where/what defines an object, saying
that host object is "object supplied by the host environment to complete
the execution environment of ECMAScript."

Another problem with saying "host object is an object semantics of which
is not defined in specs", is that it's easy to confuse semantics with
binding (at least I did); so when giving this kind of explanation it
might make sense to emphasize that it's not "binding" we are talking
about. Perhaps give explaining example too.

I'll bring this on ES5-discuss mailing list when/if I get chance.

--
kangax
From: Garrett Smith on
kangax wrote:
> On 3/22/10 10:50 AM, Asen Bozhilov wrote:
>> kangax wrote:
>>
>>> 4.3.6 also says:
>>>
>>> "A native object is any object supplied by an ECMAScript implementation
>>> independent of the host environment. Standard native objects are
>>> ^^^^^^^^^^^^^^^^^^^^^^^
>>> defined in this specification."
>>>
>>> ...implying that there could be other (not "standard") native objects.
>>
>> If it's non standard "native" object will be a host object:
>>
>> | ECMA-262-3
>> | 4.3.8 Host Object
>> | 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.
>
> Yes, if it's not native it's host object. But if it's not native
> *standard*, it could just be native *non-standard*; i.e. it's provided
> by implementation (not host environment), but is not part of ECMA-262
> specification.
>

A built-in object is native. In ES5, a built-in object can be
non-standard. Therefore, a native object can be non-standard.

ES5, s 4.3.7
| built-in object
| object supplied by an ECMAScript implementation, independent of the
| host environment, that is present at the start of the execution of an
| ECMAScript program.
|
| NOTE Standard built-in objects are defined in this specification, and
| an ECMAScript implementation may specify and define others. Every
| built-in object is a native object. A built-in constructor is a
| built-in object that is also a constructor.

This definition of built-in has the effect of differentiating between
things that are part of the ecmascript implementation from objects that
are made available by the host environment.

Examples non-standard (native) built-in objects include `atob`,
`Array.slice`, `String.prototype.trimRight`, and `Enumerator` (JScript).

A host object may be implemented as a native object. For example,
XMLHttpRequest. This does not, however, make that host object built-in.

>>
>> ES5 has better definition of native objects:
>>
>> | ECMA-262-5
>> | 4.3.6
>> | native object
>> | object in an ECMAScript implementation whose semantics are
>> | fully defined by this specification rather than by
>> | the host environment.
>
> That's why I mentioned vagueness. Specs seem to be confused on the
> distinction of host objects and native non-standard objects.
>

AIUI, "semantics" is regarding section 8.6. The semantics describe what
happens when applying the call operator to `String.prototype.trimRight`
(e.g. call the [[Call]] property), but do not explain what that method
will do (throw error, etc).

[...]
>
>> If `Foo` refer object, which semantic is defined by ECMA-262
>> standard that mean, `Foo` refer native object.
>
> So you say that object referenced originally by
> `Array.prototype.forEach` (which is not defined in ECMA-262, but is
> present in, say, Mozilla's Spidermonkey implementation) is a host object?
>

`Array.prototype.forEach` fits the definition of built-in object.
--
Garrett
comp.lang.javascript FAQ: http://jibbering.com/faq/
From: Asen Bozhilov on
Garrett Smith wrote:
> kangax wrote:

> A built-in object is native. In ES5, a built-in object can be
> non-standard. Therefore, a native object can be non-standard.

Therefore:

var myObj = new Object();

is non standard native object? I don't think so. ES5 define standard
built-in objects in: "15 Standard Built-in ECMAScript Objects". There
definition of properties and behavior of standard built-in objects.

| 4.3.7
| Standard built-in objects are defined in this specification,
| and an ECMAScript implementation may specify and
| define others. Every built-in object is a native object.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
From that point, there aren't non standard native objects.
Implementation can provide non standard built-in objects, which aren't
specified in section 15. If any object isn't native, that object isn't
non-standard native object. It's a host object, from:

| 4.3.8
| Any object that is not native is a host object.

> Examples non-standard (native) built-in objects include `atob`,
> `Array.slice`, `String.prototype.trimRight`, and `Enumerator` (JScript).

These are non standard built-in objects, but are standard native
objects.