Subj : Re: E4X: result of parent() method call on XMLList To : Martin.Honnen From : Brendan Eich Date : Sat Apr 16 2005 05:18 pm Martin Honnen wrote: > > The E4X specification says that undefined should be returned on calling > parent() on an empty XMLList 13.5.4.16 XMLList.prototype.parent() Overview If all items in this XMLList object have the same parent, it is returned. Otherwise, the parent method returns undefined. Semantics When the parent method is called on an XMLList object l, the following steps are taken: 1. If l.[[Length]] = 0, return undefined .... > but Spidermonkey returns null. No, it returns undefined per spec: ]$ Linux_All_DBG.OBJ/js -x js> l=<> js> l.parent() js> typeof l.parent() undefined The code is clear, too: if (xml->xml_class == JSXML_CLASS_LIST) { *rval = JSVAL_VOID; n = xml->xml_kids.length; if (n == 0) return JS_TRUE; ... > The errata (https://bugzilla.mozilla.org/attachment.cgi?id=169406) > already mentions the discrepancy. The discrepancy mentioned there is between XML.prototype.parent returning null for no parent and XMLList.prototype.parent returning undefined for empty list or inconsistent parents of list elements. It's intentional, and ECMA TG1 agreed to keep it, so I withdraw that erratum. > Is there any decision by now what should be returned, null or undefined? The spec is clear, and SpiderMonkey follows it. Could you show the test you used to get a different result, and say with what version of jsxml.c (and a consistent js shell build)? /be .