Bug 139981 - typeof() many array-like builtin objects returns "function"
Summary: typeof() many array-like builtin objects returns "function"
Status: RESOLVED FIXED
Alias: None
Product: konqueror
Classification: Applications
Component: kjs (show other bugs)
Version: unspecified
Platform: Ubuntu Linux
: NOR normal
Target Milestone: ---
Assignee: Konqueror Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-01-12 17:57 UTC by Stevan White
Modified: 2008-08-13 22:45 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stevan White 2007-01-12 17:57:45 UTC
Version:           3.5.2 (using KDE KDE 3.5.2)
Installed from:    Ubuntu Packages
OS:                Linux

The call
    typeof( self.document.forms )
returns "function", but self.document.forms also has a "length" property.  I don't think of functions as having member properties.  No other browser thinks this property is a function.

In other browsers, this call returns "object" (that has a "length" property and an item() method). One could also imagine calling it an "array".  But I think "function" is not appropriate.
 
Other examples in self.document.
    all
    anchors
    images
    applets
    links
    layers
    styleSheets
    childNodes
It looks as if everything I would think of as a list or array is reported as a function.

This happens throughout the object tree, not just in document.
Comment 1 Maksim Orlovich 2007-01-12 18:07:28 UTC
All functions in core JS have properties, in particular .length, actually.
(Which does mean a different thing then for collections --- it's the minimum number of "required" arguments, actually)

The reason these are reported as functions is that they can be called as such, IIRC, I think  document.forms(1) works as well if my memory serves me right.

Anyway, is there a practical problem this is causing?
Comment 2 Stevan White 2007-01-12 23:47:48 UTC
Yes, it has caused a problem.

I can confirm that self.properties.forms(0) gives the same result as the array form in Konqueror, but not in Firefox.

That's fine with me, but real-world code is written to support the traditional structures.  Since Konqueror supports the traditional structures as well, it would be better that it advertized them as such as well.

I looked in the DOM specs on this, and it isn't clear to me.  There it says these are read-only properties.  This might mean, I suppose, that they are accessed via a function call.  But I would prefer that the browser used "function" for methods of the DOM, and "object" "string" "number" for properties.

But generally, would be better if Konqueror behaved like the other browsers in this respect.

Otherwise, we have to write browser-specific code, and spend hours freetting over little things.
Comment 3 Harri Porten 2007-04-04 22:32:12 UTC
I don't think there is any written standard about this. By the ECMAScript standard these objects would count as functions but they are "DOM 0" hacks not following any rule. But I agree that it would be wise to follow what others are doing for the sake of portability. 
Comment 4 Maksim Orlovich 2008-08-13 22:42:59 UTC
SVN commit 846672 by orlovich:

Add support for making typeof() of calleable things not be 
"function" but "object" in KJS, and use it for the array-like
things that support the IE call notation in KHTML.

(Actually, one is still unchanged, but I am in process of removing it)
BUG: 139981


 M  +1 -0      khtml/ecma/kjs_css.h  
 M  +1 -0      khtml/ecma/kjs_dom.h  
 M  +1 -0      khtml/ecma/kjs_html.h  
 M  +1 -1      kjs/bytecode/machine.cpp.in  
 M  +5 -0      kjs/object.cpp  
 M  +10 -0     kjs/object.h  


WebSVN link: http://websvn.kde.org/?view=rev&revision=846672
Comment 5 Maksim Orlovich 2008-08-13 22:45:53 UTC
SVN commit 846675 by orlovich:

Regression test for #139981

CCBUG:139981


 A             baseline/dom/typeof-arraylike.html-dom  
 AM            baseline/dom/typeof-arraylike.html-dump.png  
 A             baseline/dom/typeof-arraylike.html-render  
 A             tests/dom/typeof-arraylike.html  


WebSVN link: http://websvn.kde.org/?view=rev&revision=846675