Bug 139981

Summary: typeof() many array-like builtin objects returns "function"
Product: [Applications] konqueror Reporter: Stevan White <stevan_white>
Component: kjsAssignee: Konqueror Developers <konq-bugs>
Severity: normal CC: maksim
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Ubuntu   
OS: Linux   
Latest Commit: Version Fixed In:

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.
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


 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