What's Wrong with Extending the DOM?

T

Thomas 'PointedEars' Lahn

Garrett said:

| Host objects have no rules
|
| Next problem with DOM extension is that DOM objects are host objects, and
| host objects are the worst bunch. By specification (ECMA-262 3rd. ed),
| host objects are allowed to do things, no other objects can even dream
| of. To quote relevant section [8.6.2]:
|
| 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.
|
| The internal methods specification talks about are [[Prototype]],
| [[Class]], [[Value]], [[Get]], [[Put]], etc. Note how it says that
| internal methods behavior is implementation-dependent.

The (unfortunately usual) lack of several proper English pronouns aside, it
is absolutely incorrect to refer to the [[Prototype]], [[Class]],
[[Value]], [[Get]], and [[Put]] properties as methods (of those, only
[[Get]] and [[Put]] are), and to make it look as if the quoted text from
the Specification referred to them while omitting the fact that

,-[ES3F, 8.6.2]
|
| [...]
| Every object (including host objects) must implement the [[Prototype]]
| and [[Class]] properties and the [[Get]], [[Put]], [[CanPut]],
| [[HasProperty]], [[Delete]], and [[DefaultValue]] methods.

In fact,

| For native objects the [[Get]], [[Put]], [[CanPut]], [[HasProperty]],
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| [[Delete]] and [[DefaultValue]] methods behave as described in described
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| in sections 8.6.2.1, 8.6.2.2, 8.6.2.3, 8.6.2.4, 8.6.2.5 and 8.6.2.6,
| respectively, except that Array objects have a slightly different
| implementation of the [[Put]] method (section 15.4.5.1). Host objects may
| implement these methods in any manner unless specified otherwise; for
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| example, one possibility is that [[Get]] and [[Put]] for a particular
| host object indeed fetch and store property values but [[HasProperty]]
| always generates false."

meaning that host objects are _not_ free to implement the [[Prototype]] and
[[Class]] properties as they want.

The examples that follow

| document.createElement('p').offsetParent; // "Unspecified error."
| new ActiveXObject("MSXML2.XMLHTTP").send; // "Object doesn't support
| this property or method"

are particularly bogus (and multi-line pre-comments should be used instead
of single-line post-comments):

It is to be expected that a newly created element object would not provide
access to its `offsetParent' property as it has not been inserted into the
documented tree, and the value of its `offsetParent' property would not
make any sense at this point even if it had one. It is further to be
expected that a newly created XHR object would not allow access to its
`send' property before its `open' property had been called.

And probably I have only scratched the surface.

I find it quite fascinating that after all those discussions and attempts
at clarifications here it is still possible for Web articles to describe
the situation so utterly misleading and wrong.


PointedEars
 
T

Thomas 'PointedEars' Lahn

Thomas said:
Garrett said:

| Host objects have no rules
|
| Next problem with DOM extension is that DOM objects are host objects,
| and host objects are the worst bunch. By specification (ECMA-262 3rd.
| ed), host objects are allowed to do things, no other objects can even
| dream of. To quote relevant section [8.6.2]:
|
| 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.
|
| The internal methods specification talks about are [[Prototype]],
| [[Class]], [[Value]], [[Get]], [[Put]], etc. Note how it says that
| internal methods behavior is implementation-dependent.

The (unfortunately usual) lack of several proper English pronouns aside,
^^^^^^^^
I meant "articles" (in the grammatical sense of the word), of course.
 
D

David Mark

Thomas said:
Garrett said:

| Host objects have no rules
|
| Next problem with DOM extension is that DOM objects are host objects, and
| host objects are the worst bunch. By specification (ECMA-262 3rd. ed),
| host objects are allowed to do things, no other objects can even dream
| of. To quote relevant section [8.6.2]:
|
| 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.
|
| The internal methods specification talks about are [[Prototype]],
| [[Class]], [[Value]], [[Get]], [[Put]], etc. Note how it says that
| internal methods behavior is implementation-dependent.

The (unfortunately usual) lack of several proper English pronouns aside, it
is absolutely incorrect to refer to the [[Prototype]], [[Class]],
[[Value]], [[Get]], and [[Put]] properties as methods (of those, only
[[Get]] and [[Put]] are), and to make it look as if the quoted text from
the Specification referred to them while omitting the fact that

,-[ES3F, 8.6.2]
|
| [...]
| Every object (including host objects) must implement the [[Prototype]]
| and [[Class]] properties and the [[Get]], [[Put]], [[CanPut]],
| [[HasProperty]], [[Delete]], and [[DefaultValue]] methods.

In fact,

| For native objects the [[Get]], [[Put]], [[CanPut]], [[HasProperty]],
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| [[Delete]] and [[DefaultValue]] methods behave as described in described
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| in sections 8.6.2.1, 8.6.2.2, 8.6.2.3, 8.6.2.4, 8.6.2.5 and 8.6.2.6,
| respectively, except that Array objects have a slightly different
| implementation of the [[Put]] method (section 15.4.5.1). Host objects may
| implement these methods in any manner unless specified otherwise; for
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| example, one possibility is that [[Get]] and [[Put]] for a particular
| host object indeed fetch and store property values but [[HasProperty]]
| always generates false."

meaning that host objects are _not_ free to implement the [[Prototype]] and
[[Class]] properties as they want.

The examples that follow

| document.createElement('p').offsetParent; // "Unspecified error."
| new ActiveXObject("MSXML2.XMLHTTP").send; // "Object doesn't support
| this property or method"

are particularly bogus (and multi-line pre-comments should be used instead
of single-line post-comments):

It is to be expected that a newly created element object would not provide
access to its `offsetParent' property as it has not been inserted into the
documented tree, and the value of its `offsetParent' property would not
make any sense at this point even if it had one. It is further to be
expected that a newly created XHR object would not allow access to its
`send' property before its `open' property had been called.

It doesn't let you type convert it (or assign a reference to it) even
after - open - has been called. It's a method of an ActiveX object (and
implemented as a SafeArray object) and therefore type "unknown". All
you can do safely is call it or use the typeof operator to find out this
is the case.
 
T

Thomas 'PointedEars' Lahn

David said:
It doesn't let you type convert it (or assign a reference to it) even
after - open - has been called. It's a method of an ActiveX object (and
implemented as a SafeArray object) and therefore type "unknown". All
you can do safely is call it or use the typeof operator to find out this
is the case.

I figured as much. That is beside the point, though. It is the example
that is misleading as it is.


PointedEars
 
A

Asen Bozhilov

Thomas said:
In fact,

| For native objects the [[Get]], [[Put]], [[CanPut]], [[HasProperty]],
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| [[Delete]] and [[DefaultValue]] methods behave as described in described
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| in sections 8.6.2.1, 8.6.2.2, 8.6.2.3, 8.6.2.4, 8.6.2.5 and 8.6.2.6,
| respectively, except that Array objects have a slightly different
| implementation of the [[Put]] method (section 15.4.5.1). Host objects may
| implement these methods in any manner unless specified otherwise; for
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

[[DefaultValue]] of Date objects without hint argument, call first
`toString' instead of `valueOf'. 8.6.2.6 [[DefaultValue]] (hint)
The examples that follow

|   document.createElement('p').offsetParent; // "Unspecified error."
|   new ActiveXObject("MSXML2.XMLHTTP").send; // "Object doesn't support
| this property or method"

are particularly bogus (and multi-line pre-comments should be used instead
of single-line post-comments):

It is to be expected that a newly created element object would not provide
access to its `offsetParent' property as it has not been inserted into the
documented tree, and the value of its `offsetParent' property would not
make any sense at this point even if it had one.  
It is further to be
expected that a newly created XHR object would not allow access to its
`send' property before its `open' property had been called.
</nonsense>

Those examples demonstrate how host objects can implement internal
methods as they want. Both have different implementation of [[Get]]
regard ECMA-262 standard. Internal [[Get]] of these objects throw
error depend by context of usage. For example:

xhr.open(HTTP_METHOD, PATH, true);

During evaluation of CallExpression there isn't error when invoke
xhr[[Get]]('open').

xhr.open;

But in evaluation of Property Accessors expression internal [[Get]]
throw error.

Regards.
 
T

Thomas 'PointedEars' Lahn

Asen said:
Thomas said:
In fact,

| For native objects the [[Get]], [[Put]], [[CanPut]], [[HasProperty]],
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| [[Delete]] and [[DefaultValue]] methods behave as described in
| [[described
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| in sections 8.6.2.1, 8.6.2.2, 8.6.2.3, 8.6.2.4, 8.6.2.5 and 8.6.2.6,
| respectively, except that Array objects have a slightly different
| implementation of the [[Put]] method (section 15.4.5.1). Host objects
| may implement these methods in any manner unless specified otherwise;
| for
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

[[DefaultValue]] of Date objects without hint argument, call first
`toString' instead of `valueOf'. 8.6.2.6 [[DefaultValue]] (hint)
Relevance?
The examples that follow

| document.createElement('p').offsetParent; // "Unspecified error."
| new ActiveXObject("MSXML2.XMLHTTP").send; // "Object doesn't support
| this property or method"

<nonsense>

It's not nonsense, stupid.


PointedEars
 
T

Thomas 'PointedEars' Lahn

kangax said:
The goal was to show examples of property access on host objects that
result in errors being thrown. Whether they are bogus or not doesn't
really matter here.

Understanding is key. You SHOULD provide better, realistic examples.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top