Use the application's classloader for the Packages object if available.

Merged in changes from FESI 1.1.5
This commit is contained in:
hns 2002-11-29 17:56:20 +00:00
parent 148cd5de94
commit 19fd7b0f7d

View file

@ -33,6 +33,8 @@ import java.util.StringTokenizer;
import java.io.*;
import java.util.zip.*;
import helma.scripting.fesi.FesiEngine;
/**
* Defines the evaluation interface and contains the evaluation context.
* <P><B>Important:</B> This object is also used as the synchronization
@ -45,7 +47,7 @@ public class Evaluator {
// used to stop thread, 06.12.99 Hannes Wallnoefer
public volatile Thread thread;
// used to retrieve wrappers with correct Prototype for path elements in ESLoader
public helma.scripting.fesi.FesiEngine engine;
public final FesiEngine engine;
private static String eol = System.getProperty("line.separator", "\n");
@ -53,7 +55,7 @@ public class Evaluator {
* Return the version identifier of the interpreter
*/
public static String getVersion() {
return "1.1.4 (30-Jan-2000)";
return "1.1.5 (29-July-2000)";
}
/**
@ -104,16 +106,25 @@ public class Evaluator {
varDeclarationVisitor = new EcmaScriptVariableVisitor(this);
// evaluationVisitor = new EcmaScriptEvaluateVisitor(this);
globalObject = GlobalObject.makeGlobalObject(this);
packageObject = new ESPackages(this);
packageObject = engine == null ?
new ESPackages(this) :
new ESPackages(this, engine.getClassLoader ());
extensions = new Hashtable(); // forget extensions
}
/**
* Create a new empty evaluator
*/
public Evaluator () {
this.engine = null;
reset();
}
/**
* Create a new empty evaluator
*/
public Evaluator (FesiEngine engine) {
this.engine = engine;
reset();
}
@ -283,6 +294,7 @@ public class Evaluator {
*/
public void setDatePrototype(ESObject o) {
datePrototype = o;
}
/**
* Get the Date prototype object
@ -300,7 +312,6 @@ public class Evaluator {
return packageObject;
}
//------------------------------------------------------------
// Extension support
//------------------------------------------------------------
@ -503,11 +514,16 @@ public class Evaluator {
*/
public ESValue evaluateEvalString(String theSource) throws EcmaScriptException {
ESValue theValue = ESUndefined.theUndefined;
ASTProgram programNode = null;
StringEvaluationSource es = new StringEvaluationSource(theSource, null);
// Hack - this ensures correct parsing of // comments
// even if no EOL is present (as in an eval('1//a'))
if (!theSource.endsWith("\n")) {
theSource += "\n";
}
java.io.StringReader is =
new java.io.StringReader(theSource);
EcmaScript parser = new EcmaScript(is);
ASTProgram programNode = null;
StringEvaluationSource es = new StringEvaluationSource(theSource, null);
try {
// ASTProgram n = parser.Program();
programNode = (ASTProgram)parser.Program();
@ -760,7 +776,6 @@ public class Evaluator {
// currentEvaluationSource = es;
try {
for (Enumeration e = localVariableNames.elements() ; e.hasMoreElements() ;) {
String variable =(String)(e.nextElement());
createVariable(variable, variable.hashCode());
}
@ -836,6 +851,8 @@ public class Evaluator {
EcmaScriptEvaluateVisitor evaluationVisitor = new EcmaScriptEvaluateVisitor(this);
try {
// Hannes Wallnoefer, 2002/11/29: Pass thisObject to EcmaScriptFunctionVisitor so that
// functions are assigned to the prototype instead of the global object
functionDeclarationVisitor.processFunctionDeclarations(node, program.getEvaluationSource(), thisObject);
Vector variables = program.getVariableNames();
for (Enumeration e = variables.elements() ; e.hasMoreElements() ;) {
@ -973,6 +990,11 @@ public class Evaluator {
ESValue v = null;
EvaluationSource es = new UserEvaluationSource(source, null);
try {
// Hack - this ensures correct parsing of // comments
// even if no EOL is present (as in an eveal command)/
if (!text.endsWith("\n")) {
text += "\n";
}
is = new java.io.StringReader(text);
v = evaluate(is, globalObject, es, false);
} finally {
@ -1004,7 +1026,6 @@ public class Evaluator {
synchronized public ESValue evaluate(File file, ESObject thisObject)
throws EcmaScriptException, IOException {
EvaluationSource es = new FileEvaluationSource(file.getPath(), null);
FileReader fr = null;
ESValue value = null;
try {
@ -1050,6 +1071,11 @@ public class Evaluator {
java.io.StringReader is = null;
ESValue v = null;
EvaluationSource es = new StringEvaluationSource(theSource, null);
// Hack - this ensures correct parsing of // comments
// even if no EOL is present (as in an eveal command)/
if (!theSource.endsWith("\n")) {
theSource += "\n";
}
try {
is = new java.io.StringReader(theSource);
v = evaluate(is, thisObject, es, returnAccepted);