It's my understanding from ECMA-375, 2nd edition, section 11.2.4, that
given
xml = <xml><e id="1"/><e id="2"/></xml>;
the following code
xml.*.(@id == "1")
(which returns the <e id="1"/> element) could also be written as
xml.*.(attribute("id") == "1")
I.e., not only the node's properties but also its methods should be
available to the filters. However, this is not the case in Rhino. It
does work in Flex/ActionScript, but not in Firefox, which, however,
allows the following odd syntax:
xml.*.(function::attribute("id") == "1")
Now, comparing XMLWithScope.java with NativeWith.java, one finds that
the latter not only calls setPrototype() but also setParentScope(),
which XMLWithScope does not. If one applies the following patch, the
attribute() example works as expected:
---
rhino-7r2-commonjs-3rd/xmlimplsrc/org/mozilla/javascript/xmlimpl/XMLWithScope.java
2008-04-13 12:24:46.000000000 +0200
+++
rhino-7r2-lcs/xmlimplsrc/org/mozilla/javascript/xmlimpl/XMLWithScope.java
2010-03-02 22:59:36.503843503 +0100
@@ -75,6 +75,7 @@
XMLList xl = (XMLList)prototype;
if (xl.length() > 0) {
setPrototype((Scriptable)(xl.get(0, null)));
+ setParentScope(getPrototype());
}
}
// Always return the outer-most type of XML lValue of
@@ -109,6 +110,7 @@
// the WITH selector.
_currIndex = idx;
setPrototype((Scriptable)(orgXmlL.get(idx, null)));
+ setParentScope(getPrototype());
// continue looping
return null;
Is this the correct solution, and if so, could we have it added to CVS?
--
---- Martin Blom --------------------------- [email protected] ----
Eccl 1:18 http://martin.blom.org/
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino