1. Marking NativeCall.parentActivationCall transient so serialization would not see it.

2. Removal of never used NativeCall.thisObj field and code to initialize it.

3. Renaming NativeCall.funObj to NativeCall.function for better readability.
This commit is contained in:
igor%mir2.org 2004-09-14 14:59:21 +00:00
parent 93e0d48454
commit c72dbebee7
6 changed files with 19 additions and 36 deletions

View File

@ -55,10 +55,10 @@ final class Arguments extends IdScriptableObject
setParentScope(parent);
setPrototype(ScriptableObject.getObjectPrototype(parent));
args = activation.getOriginalArguments();
args = activation.originalArgs;
lengthObj = new Integer(args.length);
NativeFunction f = activation.getFunctionObject();
NativeFunction f = activation.function;
calleeObj = f;
if (f.version <= Context.VERSION_1_3
@ -91,7 +91,7 @@ final class Arguments extends IdScriptableObject
Object value = args[index];
if (value != NOT_FOUND) {
if (sharedWithActivation(index)) {
NativeFunction f = activation.getFunctionObject();
NativeFunction f = activation.function;
String argName = f.argNames[index];
value = activation.get(argName, activation);
if (value == NOT_FOUND) Kit.codeBug();
@ -104,7 +104,7 @@ final class Arguments extends IdScriptableObject
private boolean sharedWithActivation(int index)
{
NativeFunction f = activation.getFunctionObject();
NativeFunction f = activation.function;
int definedCount = f.argCount;
if (index < definedCount) {
// Check if argument is not hidden by later argument with the same
@ -127,14 +127,13 @@ final class Arguments extends IdScriptableObject
if (0 <= index && index < args.length) {
if (args[index] != NOT_FOUND) {
if (sharedWithActivation(index)) {
NativeFunction f = activation.getFunctionObject();
String argName = f.argNames[index];
String argName = activation.function.argNames[index];
activation.put(argName, activation, value);
return;
}
synchronized (this) {
if (args[index] != NOT_FOUND) {
if (args == activation.getOriginalArguments()) {
if (args == activation.originalArgs) {
args = (Object[])args.clone();
}
args[index] = value;
@ -151,7 +150,7 @@ final class Arguments extends IdScriptableObject
if (0 <= index && index < args.length) {
synchronized (this) {
if (args[index] != NOT_FOUND) {
if (args == activation.getOriginalArguments()) {
if (args == activation.originalArgs) {
args = (Object[])args.clone();
}
args[index] = NOT_FOUND;

View File

@ -3240,7 +3240,7 @@ switch (op) {
if (useActivation) {
scope = ScriptRuntime.createFunctionActivation(
fnOrScript, scope, thisObj, args);
fnOrScript, scope, args);
}
} else {
scope = callerScope;

View File

@ -55,11 +55,9 @@ public final class NativeCall extends IdScriptableObject
NativeCall() { }
NativeCall(Scriptable scope, NativeFunction funObj,
Scriptable thisObj, Object[] args)
NativeCall(NativeFunction function, Scriptable scope, Object[] args)
{
this.funObj = funObj;
this.thisObj = thisObj;
this.function = function;
setParentScope(scope);
// leave prototype null
@ -67,9 +65,9 @@ public final class NativeCall extends IdScriptableObject
this.originalArgs = (args == null) ? ScriptRuntime.emptyArgs : args;
// initialize values of arguments
String[] argNames = funObj.argNames;
String[] argNames = function.argNames;
if (argNames != null) {
for (int i=0; i < funObj.argCount; i++) {
for (int i=0; i < function.argCount; i++) {
Object val = i < args.length ? args[i]
: Undefined.instance;
super.put(argNames[i], this, val);
@ -83,7 +81,7 @@ public final class NativeCall extends IdScriptableObject
}
if (argNames != null) {
for (int i = funObj.argCount; i != argNames.length; i++) {
for (int i = function.argCount; i != argNames.length; i++) {
String name = argNames[i];
if (!super.has(name, this)) {
super.put(name, this, Undefined.instance);
@ -97,16 +95,6 @@ public final class NativeCall extends IdScriptableObject
return "Call";
}
NativeFunction getFunctionObject()
{
return funObj;
}
Object[] getOriginalArguments()
{
return originalArgs;
}
protected int findPrototypeId(String s)
{
return s.equals("constructor") ? Id_constructor : 0;
@ -147,10 +135,9 @@ public final class NativeCall extends IdScriptableObject
Id_constructor = 1,
MAX_PROTOTYPE_ID = 1;
private NativeFunction funObj;
private Scriptable thisObj;
private Object[] originalArgs;
NativeFunction function;
Object[] originalArgs;
NativeCall parentActivationCall;
transient NativeCall parentActivationCall;
}

View File

@ -111,7 +111,7 @@ public class NativeFunction extends BaseFunction
NativeCall activation = ScriptRuntime.findFunctionActivation(cx, this);
if (activation == null)
return argCount;
return activation.getOriginalArguments().length;
return activation.originalArgs.length;
}
public int getArity()

View File

@ -2871,10 +2871,9 @@ public class ScriptRuntime {
public static Scriptable createFunctionActivation(NativeFunction funObj,
Scriptable scope,
Scriptable thisObj,
Object[] args)
{
return new NativeCall(scope, funObj, thisObj, args);
return new NativeCall(funObj, scope, args);
}
@ -2900,7 +2899,7 @@ public class ScriptRuntime {
{
NativeCall call = cx.currentActivationCall;
while (call != null) {
if (call.getFunctionObject() == f)
if (call.function == f)
return call;
call = call.parentActivationCall;
}

View File

@ -1288,12 +1288,10 @@ class BodyCodegen
debugVariableName = "activation";
cfw.addALoad(funObjLocal);
cfw.addALoad(variableObjectLocal);
cfw.addALoad(thisObjLocal);
cfw.addALoad(argsLocal);
addScriptRuntimeInvoke("createFunctionActivation",
"(Lorg/mozilla/javascript/NativeFunction;"
+"Lorg/mozilla/javascript/Scriptable;"
+"Lorg/mozilla/javascript/Scriptable;"
+"[Ljava/lang/Object;"
+")Lorg/mozilla/javascript/Scriptable;");
cfw.addAStore(variableObjectLocal);