W3C home > Mailing lists > Public > www-dom@w3.org > October to December 2011

[Bug 14743] New: Indexing NodeList out of range should return undefined

From: <bugzilla@jessica.w3.org>
Date: Wed, 09 Nov 2011 18:47:17 +0000
To: www-dom@w3.org
Message-ID: <bug-14743-4009@http.www.w3.org/Bugs/Public/>
http://www.w3.org/Bugs/Public/show_bug.cgi?id=14743

           Summary: Indexing NodeList out of range should return undefined
           Product: WebAppsWG
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DOM Core
        AssignedTo: annevk@opera.com
        ReportedBy: ayg@aryeh.name
         QAContact: member-webapi-cvs@w3.org
                CC: mike@w3.org, www-dom@w3.org


Try this on Live DOM Viewer:

<!DOCTYPE html>
<script>
try {w(document.childNodes[-1])} catch(e) {w(e)}
try {w(document.childNodes.item(-1))} catch(e) {w(e)}
try {w(document.childNodes[20])} catch(e) {w(e)}
try {w(document.childNodes.item(20))} catch(e) {w(e)}
</script>

IE9: undefined, null, undefined, null
Firefox 9.0a2: INDEX_SIZE_ERR, null, undefined, null
Chrome 16 dev: undefined, INDEX_SIZE_ERR, undefined, null
Opera 12.00: undefined, null, undefined, null

Correct behavior is clearly IE/Opera, IMO.  Throwing anywhere here is annoying
because it means you can't use if (document.childNodes[i]) to test whether the
child exists.

The current spec says NodeList.prototype.item is a getter, and therefore as far
as I can tell its behavior has to match actual indexing per WebIDL.  The
correct fix is probably to make item() not a getter, and define separate
getting behavior that returns undefined.

-- 
Configure bugmail: http://www.w3.org/Bugs/Public/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
Received on Wednesday, 9 November 2011 18:47:23 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Friday, 22 June 2012 06:14:08 GMT