Fix for out-of-range indices in HTML collections

David Faure faure at kde.org
Fri Oct 8 19:38:09 CEST 2004


document.forms[big number] returned null instead of undefined (as it does in Mozilla).
Fixed by this commit.

Note that HTMLCollection was improved in CVS HEAD to have some caching,
so that calling length() can be O(1) if already called once and nothing changed
in the DOM tree meanwhile.

----------  Forwarded Message  ----------

Subject: kdelibs/khtml
Date: Friday 08 October 2004 19:31
From: David Faure <faure at kde.org>
To: kde-cvs at kde.org
Cc: khtml-cvs at kde.org

CVS commit by faure: 

As seen in George's stderr, forms[42] returns null; in mozilla it returns undefined.
(thanks to Harri for pointing this out)


  M +5 -0      ChangeLog   1.293
  M +5 -2      ecma/kjs_html.cpp   1.272


--- kdelibs/khtml/ChangeLog  #1.292:1.293
@@ -1,2 +1,7 @@
+2004-10-08  David Faure  <faure at kde.org>
+
+        * ecma/kjs_html.cpp (KJS::HTMLCollection::tryGet): 
+        return Undefined instead of Null for out-of-range indices.
+
 2004-10-07  Germain Garand  <germain at ebooksfrance.org>
 

--- kdelibs/khtml/ecma/kjs_html.cpp  #1.271:1.272
@@ -3061,6 +3061,9 @@ Value KJS::HTMLCollection::tryGet(ExecSt
   unsigned int u = propertyName.toULong(&ok);
   if (ok) {
+    if ( u < collection.length() ) {
     DOM::Node node = collection.item(u);
     return getDOMNode(exec,node);
+    } else
+      return Undefined();
   }
   else




-------------------------------------------------------

-- 
David Faure, faure at kde.org, sponsored by Trolltech to work on KDE,
Konqueror (http://www.konqueror.org), and KOffice (http://www.koffice.org).


More information about the Khtml-devel mailing list