Added HopObject constructor, improved variable naming in jsConstructor
This commit is contained in:
parent
8da0efb7c0
commit
1d73c147d0
2 changed files with 21 additions and 13 deletions
|
@ -68,6 +68,16 @@ public class HopObject extends ScriptableObject implements Wrapper {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new HopObject prototype.
|
||||||
|
*
|
||||||
|
* @param cname ...
|
||||||
|
*/
|
||||||
|
protected HopObject(String cname, Scriptable proto) {
|
||||||
|
className = cname;
|
||||||
|
setPrototype(proto);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is used as HopObject constructor from JavaScript.
|
* This method is used as HopObject constructor from JavaScript.
|
||||||
*/
|
*/
|
||||||
|
@ -75,13 +85,13 @@ public class HopObject extends ScriptableObject implements Wrapper {
|
||||||
Function ctorObj, boolean inNewExpr)
|
Function ctorObj, boolean inNewExpr)
|
||||||
throws EvaluatorException, ScriptingException {
|
throws EvaluatorException, ScriptingException {
|
||||||
RhinoEngine engine = (RhinoEngine) cx.getThreadLocal("engine");
|
RhinoEngine engine = (RhinoEngine) cx.getThreadLocal("engine");
|
||||||
RhinoCore c = engine.core;
|
RhinoCore core = engine.core;
|
||||||
String prototype = ((FunctionObject) ctorObj).getFunctionName();
|
String protoname = ((FunctionObject) ctorObj).getFunctionName();
|
||||||
|
|
||||||
// if this is a java object prototype, create a new java object
|
// if this is a java object prototype, create a new java object
|
||||||
// of the given class instead of a HopObject.
|
// of the given class instead of a HopObject.
|
||||||
if (c.app.isJavaPrototype(prototype)) {
|
if (core.app.isJavaPrototype(protoname)) {
|
||||||
String classname = c.app.getJavaClassForPrototype(prototype);
|
String classname = core.app.getJavaClassForPrototype(protoname);
|
||||||
try {
|
try {
|
||||||
Class clazz = Class.forName(classname);
|
Class clazz = Class.forName(classname);
|
||||||
// try to get the constructor matching our arguments
|
// try to get the constructor matching our arguments
|
||||||
|
@ -98,14 +108,13 @@ public class HopObject extends ScriptableObject implements Wrapper {
|
||||||
throw new EvaluatorException(x.toString());
|
throw new EvaluatorException(x.toString());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
INode n = new helma.objectmodel.db.Node(prototype, prototype,
|
INode node = new helma.objectmodel.db.Node(protoname, protoname,
|
||||||
c.app.getWrappedNodeManager());
|
core.app.getWrappedNodeManager());
|
||||||
HopObject hobj = new HopObject(prototype);
|
Scriptable proto = core.getPrototype(protoname);
|
||||||
|
HopObject hobj = new HopObject(protoname, proto);
|
||||||
|
|
||||||
hobj.init(c, n);
|
hobj.init(core, node);
|
||||||
Scriptable p = c.getPrototype(prototype);
|
if (proto != null) {
|
||||||
if (p != null) {
|
|
||||||
hobj.setPrototype(p);
|
|
||||||
engine.invoke(hobj, "constructor", args, false);
|
engine.invoke(hobj, "constructor", args, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -605,9 +605,8 @@ public final class RhinoCore {
|
||||||
protoname = "hopobject";
|
protoname = "hopobject";
|
||||||
}
|
}
|
||||||
|
|
||||||
esn = new HopObject(protoname);
|
esn = new HopObject(protoname, op);
|
||||||
esn.init(this, n);
|
esn.init(this, n);
|
||||||
esn.setPrototype(op);
|
|
||||||
|
|
||||||
wrappercache.put(n, esn);
|
wrappercache.put(n, esn);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue