__prototype__ internal property is now also accessible as _prototype.

Simplified check for internal properties: Every property name starting with an
underscore is now interpreted as internal property.
Added check for null propertyName.
This commit is contained in:
hns 2002-07-18 20:32:28 +00:00
parent bfa99996c8
commit 02d64e6d1e

View file

@ -321,7 +321,9 @@ public class ESNode extends ObjectPrototype {
* the prototype functions in that case. * the prototype functions in that case.
*/ */
public ESValue getNodeProperty (String propertyName) throws EcmaScriptException { public ESValue getNodeProperty (String propertyName) throws EcmaScriptException {
// check for null
if (propertyName == null)
return ESNull.theNull;
// persistent or persistent capable nodes have a cache property that's a transient node. // persistent or persistent capable nodes have a cache property that's a transient node.
// it it hasn't requested before, initialize it now // it it hasn't requested before, initialize it now
if ("cache".equalsIgnoreCase (propertyName) && node instanceof Node) { if ("cache".equalsIgnoreCase (propertyName) && node instanceof Node) {
@ -337,18 +339,8 @@ public class ESNode extends ObjectPrototype {
return rel == null ? (ESValue) ESNull.theNull : new ESString (rel); return rel == null ? (ESValue) ESNull.theNull : new ESString (rel);
} }
if ("_id".equals (propertyName)) // Everything starting with an underscore is interpreted as internal property
return new ESString (node.getID ()); if (propertyName.startsWith ("_"))
if ("_parent".equals (propertyName)) {
INode n = node.getParent ();
if (n != null)
return eval.getNodeWrapper (n);
else
return ESNull.theNull;
}
// this is not very nice, but as a hack we return the id of a node as node.__id__
if (propertyName.startsWith ("__") && propertyName.endsWith ("__"))
return getInternalProperty (propertyName); return getInternalProperty (propertyName);
// this _may_ do a relational query if properties are mapped to a relational type. // this _may_ do a relational query if properties are mapped to a relational type.
@ -393,24 +385,24 @@ public class ESNode extends ObjectPrototype {
* used for debugging Helma applications. * used for debugging Helma applications.
*/ */
private ESValue getInternalProperty (String propertyName) throws EcmaScriptException { private ESValue getInternalProperty (String propertyName) throws EcmaScriptException {
if ("__id__".equalsIgnoreCase (propertyName)) { if ("__id__".equals (propertyName) || "_id".equals (propertyName)) {
return new ESString (node.getID ()); return new ESString (node.getID ());
} }
if ("__prototype__".equalsIgnoreCase (propertyName)) { if ("__prototype__".equals (propertyName) || "_prototype".equals (propertyName)) {
String p = node.getPrototype (); String p = node.getPrototype ();
if (p == null) if (p == null)
return ESNull.theNull; return ESNull.theNull;
else else
return new ESString (node.getPrototype ()); return new ESString (node.getPrototype ());
} }
// some more internal properties if ("__parent__".equals (propertyName) || "_parent".equals (propertyName)) {
if ("__parent__".equals (propertyName)) {
INode n = node.getParent (); INode n = node.getParent ();
if (n == null) if (n == null)
return ESNull.theNull; return ESNull.theNull;
else else
return eval.getNodeWrapper (n); return eval.getNodeWrapper (n);
} }
// some more internal properties
if ("__name__".equals (propertyName)) if ("__name__".equals (propertyName))
return new ESString (node.getName ()); return new ESString (node.getName ());
if ("__fullname__".equals (propertyName)) if ("__fullname__".equals (propertyName))