[Webkit-unassigned] [Bug 14547] typeof document.body.childNodes=="function" ("object" expected)

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Sat Oct 13 20:09:26 PDT 2007


http://bugs.webkit.org/show_bug.cgi?id=14547





------- Comment #16 from dhtmlkitchen at gmail.com  2007-10-13 20:09 PDT -------
(In reply to comment #15)
> (In reply to comment #14)
>
> Updated test case. Try & break it.
> http://dhtmlkitchen.com/jstest/isFunctionTest.html
>
> > I noticed several problems:
>
> > 1) constructor property missing:
>
> > "constructor" in document.getElementsByTagName("div"); // false
>
> In ECMAScript terms the object retuned from a call to - getElementsByTagName -
> is a host object, and host objects are not required to have a - constructor -
> property.
The constructor property would be on the object's [[Prototype]]


The W3C DOM specification for the NodeList interface also does not
> define a - constructor - property. So there is no technical justification for
> anyone to expect the object returned from a call to - getElementsByTagName - to
> have a - constructor - property. Thus the absence of such a property cannot be
> regarded as in any way erroneous. Instead any error would be in the thinking of
> anyone who expected/demanded it.
>

A NodeList is an object. Error in thinking, huh?


> > 2)
> > toString reflects the [[class]] as NodeList:
>
> Why would that be a problem? There is nothing that says it should not.
>
The fact that constructor is null.

[[class]] comes from the constructor.

So it sounds like you're trying to say that an object's [[class]] doesn't imply
that an object's has the same constructor. If that's what you're trying to say,
that is technically correct. The class doesn't imply the constructor, it's the
other way around.


Ab object (nodeList in this case) COULD get its [[class]]
from an internal private function, where private is implementation
defined. 



If the class property is NodeList, the object should be a NodeList.


> > document.getElementsByTagName("div").toString();// [object NodeList]
>
> Why would that be a problem? There is nothing that says it should not.
>
> > document.getElementsByTagName("div").__proto__ === null; // true
>
> Why would that be a problem? There is nothing that says it should not.
>

javascript:alert(document.body.childNodes[1].toString ===
Object.prototype.toString)

We got Object.prototype.toString and all the other methods off
Object.prototype. 

What happened to the constructor? 

The [[Prototype]] was not set, but all the methods are there.

To me, that seems strange.


> > "NodeList" in window; // false
>
> Why would that be a problem? There is nothing that says it should not.
>
That's true. 

> > 3)
> > prototype property is missing from built-in functions.
>
> Not all of them, and ECMA 262 3rd Ed, Section 15 paragraph 9 says:-
>
> "None of the built-in functions described in this section shall implement the
> internal [[Construct]] method unless otherwise specified in the description of
> a particular function. None of the built-in functions described in this section
> shall initially have a prototype property unless otherwise specified in the
> description of a particular function."
>
You're right.


>
> Generally this entire 'bug report' is bogus.

THAT is not true. This bug is valid.

document.body.childNodes IS NOT a function.


The W3C specifies NodeList,
> HTMLCollection, etc., as interfaces. For ECMAScript the implications of this
> are not that there should be a NodeList class in the environment but instead
> that when you get an object that "is a NodeList" what you actually get is an
> object that implements the NodeList interface (nothing more than an object that
> has all of the methods and properties defined in the ECMAScript binding for the
> interface), and that can be any object so long as it implements the interface
> correctly. In ECMAScript/javascript functions are objects, so there is no
> reason for the object implementing the NodeList interface not being a function
> object. That may not be required but it certainly is not excluded, or
> particularly unexpected by anyone with any experience of scripting web
> browsers. Historically the typeof operator would return 'function' for all
> objects implanting NodeList, NamedNodeMap, HTMLCollection and even all pre-DOM
> collections in Mac IE, Konqueror, Opera versions up 7, IceBrowser versions up
> to 5 and probably at least some others. And in all cases these object were
> callable.
>

Do you meant objects implementing NodeList? 



document.body.childNodes does not implement NodeList. It's
constructor, however, does. 

document.body.childNodes is an instance of a NodeList.

Thanks for bringing relevant javascript knowledge here to straighten out the
prototype property. You seem to have the manual clearly implanted in your
brain.

>


-- 
Configure bugmail: http://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.



More information about the webkit-unassigned mailing list