mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 22:32:46 +00:00
Changing (XML|XMLList).(propertyIsEnumeratable|attribute|child) to confirm to the published ECMA 357 specification.
This commit is contained in:
parent
907a84e3c8
commit
4edb63b66a
@ -2579,9 +2579,19 @@ todo need to handle namespace prefix not found in XML look for namespace type in
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
boolean propertyIsEnumerable(XMLName xmlName)
|
||||
boolean propertyIsEnumerable(Object name)
|
||||
{
|
||||
return (getPropertyList(xmlName).length() > 0);
|
||||
boolean result;
|
||||
if (name instanceof Integer) {
|
||||
result = (((Integer)name).intValue() == 0);
|
||||
} else if (name instanceof Number) {
|
||||
double x = ((Number)name).doubleValue();
|
||||
// Check that number is posotive 0
|
||||
result = (x == 0.0 && 1.0 / x > 0);
|
||||
} else {
|
||||
result = ScriptRuntime.toString(name).equals("0");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -121,17 +121,36 @@ public final class XMLLibImpl extends XMLLib
|
||||
QName qname = (QName)nameValue;
|
||||
uri = qname.uri();
|
||||
localName = qname.localName();
|
||||
} else if (nameValue instanceof Scriptable) {
|
||||
} else if (nameValue instanceof Boolean
|
||||
|| nameValue instanceof Number
|
||||
|| nameValue == Undefined.instance
|
||||
|| nameValue == null)
|
||||
{
|
||||
throw badXMLName(nameValue);
|
||||
} else {
|
||||
uri = "";
|
||||
localName = ScriptRuntime.toString(nameValue);
|
||||
} else {
|
||||
throw ScriptRuntime.typeError("Bad attribute name: "+nameValue);
|
||||
}
|
||||
XMLName xmlName = XMLName.formProperty(uri, localName);
|
||||
xmlName.setAttributeName();
|
||||
return xmlName;
|
||||
}
|
||||
|
||||
private static RuntimeException badXMLName(Object value)
|
||||
{
|
||||
String msg;
|
||||
if (value instanceof Number) {
|
||||
msg = "Can not construct XML name from number: ";
|
||||
} else if (value instanceof Boolean) {
|
||||
msg = "Can not construct XML name from boolean: ";
|
||||
} else if (value == Undefined.instance || value == null) {
|
||||
msg = "Can not construct XML name from ";
|
||||
} else {
|
||||
throw new IllegalArgumentException(value.toString());
|
||||
}
|
||||
return ScriptRuntime.typeError(msg+ScriptRuntime.toString(value));
|
||||
}
|
||||
|
||||
XMLName toXMLName(Context cx, Object nameValue)
|
||||
{
|
||||
XMLName result;
|
||||
@ -141,6 +160,14 @@ public final class XMLLibImpl extends XMLLib
|
||||
} else if (nameValue instanceof QName) {
|
||||
QName qname = (QName)nameValue;
|
||||
result = XMLName.formProperty(qname.uri(), qname.localName());
|
||||
} else if (nameValue instanceof String) {
|
||||
result = toXMLNameFromString(cx, (String)nameValue);
|
||||
} else if (nameValue instanceof Boolean
|
||||
|| nameValue instanceof Number
|
||||
|| nameValue == Undefined.instance
|
||||
|| nameValue == null)
|
||||
{
|
||||
throw badXMLName(nameValue);
|
||||
} else {
|
||||
String name = ScriptRuntime.toString(nameValue);
|
||||
result = toXMLNameFromString(cx, name);
|
||||
@ -176,8 +203,7 @@ public final class XMLLibImpl extends XMLLib
|
||||
ScriptRuntime.storeUint32Result(cx, l);
|
||||
result = null;
|
||||
} else {
|
||||
String str = ScriptRuntime.toString(d);
|
||||
result = toXMLNameFromString(cx, str);
|
||||
throw badXMLName(value);
|
||||
}
|
||||
} else if (value instanceof QName) {
|
||||
QName qname = (QName)value;
|
||||
@ -195,6 +221,11 @@ public final class XMLLibImpl extends XMLLib
|
||||
if (!number) {
|
||||
result = XMLName.formProperty(uri, qname.localName());
|
||||
}
|
||||
} else if (value instanceof Boolean
|
||||
|| value == Undefined.instance
|
||||
|| value == null)
|
||||
{
|
||||
throw badXMLName(value);
|
||||
} else {
|
||||
String str = ScriptRuntime.toString(value);
|
||||
long test = ScriptRuntime.testUint32String(str);
|
||||
@ -294,7 +325,7 @@ public final class XMLLibImpl extends XMLLib
|
||||
} else {
|
||||
prefix = ScriptRuntime.toString(prefixValue);
|
||||
if (prefix.length() != 0) {
|
||||
throw ScriptRuntime.constructError("TypeError",
|
||||
throw ScriptRuntime.typeError(
|
||||
"Illegal prefix '"+prefix+"' for 'no namespace'.");
|
||||
}
|
||||
}
|
||||
|
@ -1254,9 +1254,26 @@ class XMLList extends XMLObjectImpl implements Function
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
boolean propertyIsEnumerable(XMLName xmlName)
|
||||
boolean propertyIsEnumerable(Object name)
|
||||
{
|
||||
return hasXMLProperty(xmlName);
|
||||
long index;
|
||||
if (name instanceof Integer) {
|
||||
index = ((Integer)name).intValue();
|
||||
} else if (name instanceof Number) {
|
||||
double x = ((Number)name).doubleValue();
|
||||
index = (long)x;
|
||||
if ((double)index != x) {
|
||||
return false;
|
||||
}
|
||||
if (index == 0 && 1.0 / x < 0) {
|
||||
// Negative 0
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
String s = ScriptRuntime.toString(name);
|
||||
index = ScriptRuntime.testUint32String(s);
|
||||
}
|
||||
return (0 <= index && index < length());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -117,7 +117,7 @@ abstract class XMLObjectImpl extends XMLObject
|
||||
abstract Object parent();
|
||||
abstract XML prependChild(Object xml);
|
||||
abstract Object processingInstructions(XMLName xmlName);
|
||||
abstract boolean propertyIsEnumerable(XMLName xmlName);
|
||||
abstract boolean propertyIsEnumerable(Object member);
|
||||
abstract XML removeNamespace(Namespace ns);
|
||||
abstract XML replace(long index, Object xml);
|
||||
abstract XML replace(XMLName name, Object xml);
|
||||
@ -548,14 +548,7 @@ abstract class XMLObjectImpl extends XMLObject
|
||||
case Id_appendChild:
|
||||
return realThis.appendChild(arg(args, 0));
|
||||
case Id_attribute: {
|
||||
Object arg0 = arg(args, 0);
|
||||
if (arg0 == null || arg0 == Undefined.instance) {
|
||||
// XXX: E4X requires to throw the exception in this case
|
||||
// (whoch toAttributeName will) but the test suite assumes
|
||||
// it should be OK. Trust test suite for now.
|
||||
arg0 = ScriptRuntime.toString(arg0);
|
||||
}
|
||||
XMLName xmlName = lib.toAttributeName(cx, arg0);
|
||||
XMLName xmlName = lib.toAttributeName(cx, arg(args, 0));
|
||||
return realThis.attribute(xmlName);
|
||||
}
|
||||
case Id_attributes:
|
||||
@ -634,9 +627,8 @@ abstract class XMLObjectImpl extends XMLObject
|
||||
return realThis.processingInstructions(xmlName);
|
||||
}
|
||||
case Id_propertyIsEnumerable: {
|
||||
XMLName xmlName = lib.toXMLName(cx, arg(args, 0));
|
||||
return ScriptRuntime.wrapBoolean(
|
||||
realThis.propertyIsEnumerable(xmlName));
|
||||
realThis.propertyIsEnumerable(arg(args, 0)));
|
||||
}
|
||||
case Id_removeNamespace: {
|
||||
Namespace ns = lib.castToNamespace(cx, arg(args, 0));
|
||||
|
Loading…
Reference in New Issue
Block a user