Fix up bug where direct calls were getting the parent scope when they shouldn't have,

resulting in a NullPointerException on the following code when run on the MS VM with -opt 9:

var testcases = getTestCases();

function getTestCases() {
    return new Boolean(new MyObject(true));
}

function MyObject( value ) {
    this.value = value;
    this.valueOf = new Function( "return this.value" );
    return this;
}
This commit is contained in:
nboyd%atg.com 2000-05-23 20:59:13 +00:00
parent 5d1cd52439
commit 108f81d6ac
2 changed files with 16 additions and 4 deletions

View File

@ -1461,6 +1461,7 @@ public class Codegen extends Interpreter {
/**
* Generate the prologue for a function or script.
*
* @param cx the context
* @param tree the tree to generate code for
* @param inFunction true if generating the prologue for a function
* (as opposed to a script)
@ -1474,8 +1475,13 @@ public class Codegen extends Interpreter {
contextLocal = reserveWordLocal(1);
variableObjectLocal = reserveWordLocal(2);
thisObjLocal = reserveWordLocal(3);
if (inFunction && !cx.hasCompileFunctionsWithDynamicScope()) {
if (inFunction && !cx.hasCompileFunctionsWithDynamicScope() &&
directParameterCount == -1)
{
// Unless we're either using dynamic scope or we're in a
// direct call, use the enclosing scope of the function as our
// variable object.
aload(funObjLocal);
classFile.add(ByteCode.INVOKEINTERFACE,
"org/mozilla/javascript/Scriptable",

View File

@ -1461,6 +1461,7 @@ public class Codegen extends Interpreter {
/**
* Generate the prologue for a function or script.
*
* @param cx the context
* @param tree the tree to generate code for
* @param inFunction true if generating the prologue for a function
* (as opposed to a script)
@ -1474,8 +1475,13 @@ public class Codegen extends Interpreter {
contextLocal = reserveWordLocal(1);
variableObjectLocal = reserveWordLocal(2);
thisObjLocal = reserveWordLocal(3);
if (inFunction && !cx.hasCompileFunctionsWithDynamicScope()) {
if (inFunction && !cx.hasCompileFunctionsWithDynamicScope() &&
directParameterCount == -1)
{
// Unless we're either using dynamic scope or we're in a
// direct call, use the enclosing scope of the function as our
// variable object.
aload(funObjLocal);
classFile.add(ByteCode.INVOKEINTERFACE,
"org/mozilla/javascript/Scriptable",