* Always throw exception when there's an error in global code
* Reimplement hasFunction() on prototypes for HopObjects. * rename putPrototype() to registerPrototype()
This commit is contained in:
parent
7bdbcf1de8
commit
fad97efc60
1 changed files with 43 additions and 6 deletions
|
@ -58,6 +58,9 @@ public final class RhinoCore {
|
||||||
// the prototype for path objects
|
// the prototype for path objects
|
||||||
PathWrapper pathProto;
|
PathWrapper pathProto;
|
||||||
|
|
||||||
|
// Any error that may have been found in global code
|
||||||
|
EcmaError globalError;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a Rhino evaluator for the given application and request evaluator.
|
* Create a Rhino evaluator for the given application and request evaluator.
|
||||||
*/
|
*/
|
||||||
|
@ -100,10 +103,10 @@ public final class RhinoCore {
|
||||||
XmlRpcObject.init(global);
|
XmlRpcObject.init(global);
|
||||||
MailObject.init(global, app.getProperties());
|
MailObject.init(global, app.getProperties());
|
||||||
|
|
||||||
putPrototype("hopobject",
|
registerPrototype("hopobject",
|
||||||
(ScriptableObject) ScriptableObject
|
(ScriptableObject) ScriptableObject
|
||||||
.getClassPrototype(global, "HopObject"));
|
.getClassPrototype(global, "HopObject"));
|
||||||
putPrototype("global", global);
|
registerPrototype("global", global);
|
||||||
|
|
||||||
// add some convenience functions to string, date and number prototypes
|
// add some convenience functions to string, date and number prototypes
|
||||||
Scriptable stringProto = ScriptableObject.getClassPrototype(global, "String");
|
Scriptable stringProto = ScriptableObject.getClassPrototype(global, "String");
|
||||||
|
@ -168,7 +171,7 @@ public final class RhinoCore {
|
||||||
System.err.println("Error creating prototype: " + ignore);
|
System.err.println("Error creating prototype: " + ignore);
|
||||||
ignore.printStackTrace();
|
ignore.printStackTrace();
|
||||||
}
|
}
|
||||||
putPrototype(name, op);
|
registerPrototype(name, op);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register a constructor for all types except global.
|
// Register a constructor for all types except global.
|
||||||
|
@ -201,7 +204,7 @@ public final class RhinoCore {
|
||||||
// or it has changed...
|
// or it has changed...
|
||||||
setParentPrototype(prototype, op);
|
setParentPrototype(prototype, op);
|
||||||
|
|
||||||
info.error = null;
|
globalError = info.error = null;
|
||||||
|
|
||||||
// loop through the prototype's code elements and evaluate them
|
// loop through the prototype's code elements and evaluate them
|
||||||
// first the zipped ones ...
|
// first the zipped ones ...
|
||||||
|
@ -363,6 +366,9 @@ public final class RhinoCore {
|
||||||
* invalid, a ScriptingException is thrown.
|
* invalid, a ScriptingException is thrown.
|
||||||
*/
|
*/
|
||||||
public Scriptable getValidPrototype(String protoName) {
|
public Scriptable getValidPrototype(String protoName) {
|
||||||
|
if (globalError != null) {
|
||||||
|
throw new RuntimeException(globalError.toString());
|
||||||
|
}
|
||||||
TypeInfo info = getPrototypeInfo(protoName);
|
TypeInfo info = getPrototypeInfo(protoName);
|
||||||
if (info != null && info.error != null) {
|
if (info != null && info.error != null) {
|
||||||
throw new RuntimeException(info.error.toString());
|
throw new RuntimeException(info.error.toString());
|
||||||
|
@ -418,12 +424,39 @@ public final class RhinoCore {
|
||||||
/**
|
/**
|
||||||
* Register an object prototype for a prototype name.
|
* Register an object prototype for a prototype name.
|
||||||
*/
|
*/
|
||||||
private void putPrototype(String protoName, ScriptableObject op) {
|
private void registerPrototype(String protoName, ScriptableObject op) {
|
||||||
if ((protoName != null) && (op != null)) {
|
if ((protoName != null) && (op != null)) {
|
||||||
prototypes.put(protoName, new TypeInfo(op, protoName));
|
prototypes.put(protoName, new TypeInfo(op, protoName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if an object has a function property (public method if it
|
||||||
|
* is a java object) with that name.
|
||||||
|
*/
|
||||||
|
public boolean hasFunction(String protoname, String fname) {
|
||||||
|
// System.err.println ("HAS_FUNC: "+fname);
|
||||||
|
try {
|
||||||
|
Scriptable op = getPrototype(protoname);
|
||||||
|
|
||||||
|
// if this is an untyped object return false
|
||||||
|
if (op == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Object func = ScriptableObject.getProperty(op, fname);
|
||||||
|
|
||||||
|
if ((func != null) && func instanceof Function) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} catch (Exception esx) {
|
||||||
|
// System.err.println ("Error in hasFunction: "+esx);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert an input argument from Java to the scripting runtime
|
* Convert an input argument from Java to the scripting runtime
|
||||||
* representation.
|
* representation.
|
||||||
|
@ -686,7 +719,11 @@ public final class RhinoCore {
|
||||||
}
|
}
|
||||||
// mark prototype as broken
|
// mark prototype as broken
|
||||||
if (info.error == null && e instanceof EcmaError) {
|
if (info.error == null && e instanceof EcmaError) {
|
||||||
info.error = (EcmaError) e;
|
if ("global".equals(info.protoName)) {
|
||||||
|
globalError = (EcmaError) e;
|
||||||
|
} else {
|
||||||
|
info.error = (EcmaError) e;
|
||||||
|
}
|
||||||
wrappercache.clear();
|
wrappercache.clear();
|
||||||
}
|
}
|
||||||
// e.printStackTrace();
|
// e.printStackTrace();
|
||||||
|
|
Loading…
Add table
Reference in a new issue