Simplify property access to only use node or nodeless methods, not both
Fix bug in getById() reported by Juerg Lehni Throw EvaluatorException instead of JavaScript exception Remove catched exception not anymore thrown by new rhino snapshot
This commit is contained in:
parent
286d522f0d
commit
0655b03c60
1 changed files with 42 additions and 41 deletions
|
@ -73,7 +73,7 @@ public class HopObject extends ScriptableObject implements Wrapper {
|
||||||
*/
|
*/
|
||||||
public static Object jsConstructor(Context cx, Object[] args,
|
public static Object jsConstructor(Context cx, Object[] args,
|
||||||
Function ctorObj, boolean inNewExpr)
|
Function ctorObj, boolean inNewExpr)
|
||||||
throws JavaScriptException, ScriptingException {
|
throws EvaluatorException, ScriptingException {
|
||||||
RhinoEngine engine = (RhinoEngine) cx.getThreadLocal("engine");
|
RhinoEngine engine = (RhinoEngine) cx.getThreadLocal("engine");
|
||||||
RhinoCore c = engine.core;
|
RhinoCore c = engine.core;
|
||||||
String prototype = ((FunctionObject) ctorObj).getFunctionName();
|
String prototype = ((FunctionObject) ctorObj).getFunctionName();
|
||||||
|
@ -96,14 +96,14 @@ public class HopObject extends ScriptableObject implements Wrapper {
|
||||||
if (value instanceof Throwable) {
|
if (value instanceof Throwable) {
|
||||||
((Throwable) value).printStackTrace();
|
((Throwable) value).printStackTrace();
|
||||||
}
|
}
|
||||||
throw new JavaScriptException("Error in Java constructor: "+value);
|
throw new EvaluatorException("Error in Java constructor: "+value);
|
||||||
} catch (Exception ignore) {
|
} catch (Exception ignore) {
|
||||||
// constructor arguments didn't match
|
// constructor arguments didn't match
|
||||||
}
|
}
|
||||||
throw new ScriptingException("No matching Java Constructor found in "+clazz);
|
throw new ScriptingException("No matching Java Constructor found in "+clazz);
|
||||||
} catch (Exception x) {
|
} catch (Exception x) {
|
||||||
System.err.println("Error in Java constructor: "+x);
|
System.err.println("Error in Java constructor: "+x);
|
||||||
throw new JavaScriptException(x);
|
throw new EvaluatorException(x.toString());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
INode n = new helma.objectmodel.db.Node(prototype, prototype,
|
INode n = new helma.objectmodel.db.Node(prototype, prototype,
|
||||||
|
@ -155,7 +155,12 @@ public class HopObject extends ScriptableObject implements Wrapper {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public Object unwrap() {
|
public Object unwrap() {
|
||||||
return node;
|
if (node != null) {
|
||||||
|
checkNode();
|
||||||
|
return node;
|
||||||
|
} else {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -319,7 +324,11 @@ public class HopObject extends ScriptableObject implements Wrapper {
|
||||||
}
|
}
|
||||||
|
|
||||||
checkNode();
|
checkNode();
|
||||||
Object n = node.getSubnode(id.toString());
|
|
||||||
|
String idString = (id instanceof Double) ?
|
||||||
|
Long.toString(((Double) id).longValue()) :
|
||||||
|
id.toString();
|
||||||
|
Object n = node.getSubnode(idString);
|
||||||
|
|
||||||
if (n == null) {
|
if (n == null) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -624,24 +633,12 @@ public class HopObject extends ScriptableObject implements Wrapper {
|
||||||
* @return ...
|
* @return ...
|
||||||
*/
|
*/
|
||||||
public boolean has(String name, Scriptable start) {
|
public boolean has(String name, Scriptable start) {
|
||||||
if (super.has(name, start)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((prototype != null) && prototype.has(name, start)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (node != null) {
|
if (node != null) {
|
||||||
|
|
||||||
checkNode();
|
checkNode();
|
||||||
|
return (node.get(name) != null);
|
||||||
if (node.get(name) != null) {
|
} else {
|
||||||
return true;
|
return super.has(name, start);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -650,13 +647,11 @@ public class HopObject extends ScriptableObject implements Wrapper {
|
||||||
* @param name ...
|
* @param name ...
|
||||||
*/
|
*/
|
||||||
public void delete(String name) {
|
public void delete(String name) {
|
||||||
super.delete(name);
|
|
||||||
|
|
||||||
if ((node != null)) {
|
if ((node != null)) {
|
||||||
|
|
||||||
checkNode();
|
checkNode();
|
||||||
|
|
||||||
node.unset(name);
|
node.unset(name);
|
||||||
|
} else {
|
||||||
|
super.delete(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -670,21 +665,27 @@ public class HopObject extends ScriptableObject implements Wrapper {
|
||||||
*/
|
*/
|
||||||
public Object get(String name, Scriptable start) {
|
public Object get(String name, Scriptable start) {
|
||||||
// System.err.println ("GET from "+node+": "+name);
|
// System.err.println ("GET from "+node+": "+name);
|
||||||
Object retval = super.get(name, start);
|
Object retval = null;
|
||||||
|
|
||||||
if (retval != ScriptableObject.NOT_FOUND) {
|
if (node == null) {
|
||||||
return retval;
|
return super.get(name, start);
|
||||||
|
} else {
|
||||||
|
// Note: we do not normally consult the prototype in get(),
|
||||||
|
// but we do so here because calling get on the Node may trigger
|
||||||
|
// db select statements (resulting in errors) and getting a
|
||||||
|
// property on the parent prototype is much cheaper and safer.
|
||||||
|
// NOTE: because of this, prototype inheritance is reversed for HopObjects!
|
||||||
|
Scriptable prototype = getPrototype();
|
||||||
|
|
||||||
|
while (prototype != null) {
|
||||||
|
retval = prototype.get(name, this);
|
||||||
|
if (retval != NOT_FOUND) {
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
prototype = prototype.getPrototype();
|
||||||
|
}
|
||||||
|
return getFromNode(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (prototype != null) {
|
|
||||||
retval = prototype.get(name, start);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (retval != ScriptableObject.NOT_FOUND) {
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
return getFromNode(name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -729,10 +730,10 @@ public class HopObject extends ScriptableObject implements Wrapper {
|
||||||
Object[] args = { new Long(d.getTime()) };
|
Object[] args = { new Long(d.getTime()) };
|
||||||
try {
|
try {
|
||||||
return cx.newObject(core.global, "Date", args);
|
return cx.newObject(core.global, "Date", args);
|
||||||
} catch (PropertyException px) {
|
/* } catch (PropertyException px) {
|
||||||
return NOT_FOUND;
|
return NOT_FOUND; */
|
||||||
} catch (NotAFunctionException nafx) {
|
/* } catch (NotAFunctionException nafx) {
|
||||||
return NOT_FOUND;
|
return NOT_FOUND; */
|
||||||
} catch (JavaScriptException nafx) {
|
} catch (JavaScriptException nafx) {
|
||||||
return NOT_FOUND;
|
return NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue