Partial fix for bug 375682. This fixes the bug for Rhino's interpretive mode

only.
This commit is contained in:
nboyd%atg.com 2007-03-29 16:57:54 +00:00
Родитель 914ec3a6cc
Коммит 021a8f7bcf
2 изменённых файлов: 20 добавлений и 5 удалений

Просмотреть файл

@ -637,11 +637,11 @@ public class Interpreter
int fnType = scriptOrFn.getFunctionNode(fnIndex).
getFunctionType();
// Only function expressions or function expression
// statements needs closure code creating new function
// statements need closure code creating new function
// object on stack as function statements are initialized
// at script/function start
// In addition function expression can not present here
// at statement level, they must only present as expressions.
// at script/function start.
// In addition, function expressions can not be present here
// at statement level, they must only be present as expressions.
if (fnType == FunctionNode.FUNCTION_EXPRESSION_STATEMENT) {
addIndexOp(Icode_CLOSURE_STMT, fnIndex);
} else {
@ -649,6 +649,17 @@ public class Interpreter
throw Kit.codeBug();
}
}
// For function statements or function expression statements
// in scripts, we need to ensure that the result of the script
// is the function if it is the last statement in the script.
// For example, eval("function () {}") should return a
// function, not undefined.
if (!itsInFunctionFlag) {
addIndexOp(Icode_CLOSURE_EXPR, fnIndex);
stackChange(1);
addIcode(Icode_POP_RESULT);
stackChange(-1);
}
}
break;

Просмотреть файл

@ -365,7 +365,11 @@ public class Main
lineno, null);
if (script != null) {
Object result = evaluateScript(script, cx, global);
if (result != Context.getUndefinedValue()) {
// Avoid printing out undefined or function definitions.
if (result != Context.getUndefinedValue() &&
!(result instanceof Function &&
source.trim().startsWith("function")))
{
try {
ps.println(Context.toString(result));
} catch (RhinoException rex) {