mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-14 18:51:28 +00:00
I changed InterpreterData.itsNestedFunctions from InterpretedFunction[] to InterpreterData[] because due recent changes/fixes InterpreterData.itsNestedFunctions was used effectively only to get information already available InterpreterData.
This commit is contained in:
parent
cc6a8ec5e9
commit
784105585e
@ -47,7 +47,6 @@ final class InterpretedFunction extends NativeFunction
|
||||
itsData = theData;
|
||||
functionName = itsData.itsName;
|
||||
source = itsData.itsSource;
|
||||
nestedFunctions = itsData.itsNestedFunctions;
|
||||
version = (short)cx.getLanguageVersion();
|
||||
argNames = itsData.argNames;
|
||||
argCount = (short)itsData.argCount;
|
||||
|
@ -44,7 +44,6 @@ final class InterpretedScript extends NativeScript
|
||||
{
|
||||
itsData = theData;
|
||||
functionName = "";
|
||||
nestedFunctions = itsData.itsNestedFunctions;
|
||||
version = (short)cx.getLanguageVersion();
|
||||
argNames = itsData.argNames;
|
||||
argCount = (short)itsData.argCount;
|
||||
|
@ -143,7 +143,7 @@ public class Interpreter {
|
||||
if (functionList == null) return;
|
||||
|
||||
int N = functionList.size();
|
||||
InterpretedFunction[] array = new InterpretedFunction[N];
|
||||
InterpreterData[] array = new InterpreterData[N];
|
||||
for (int i = 0; i != N; i++) {
|
||||
FunctionNode def = (FunctionNode)functionList.get(i);
|
||||
Interpreter jsi = new Interpreter();
|
||||
@ -154,7 +154,7 @@ public class Interpreter {
|
||||
jsi.itsInFunctionFlag = true;
|
||||
jsi.debugSource = debugSource;
|
||||
jsi.generateFunctionICode(cx, scope, def);
|
||||
array[i] = new InterpretedFunction(cx, jsi.itsData);
|
||||
array[i] = jsi.itsData;
|
||||
def.putIntProp(Node.FUNCTION_PROP, i);
|
||||
}
|
||||
itsData.itsNestedFunctions = array;
|
||||
@ -1285,8 +1285,8 @@ public class Interpreter {
|
||||
}
|
||||
case TokenStream.CLOSURE : {
|
||||
int i = getIndex(iCode, pc);
|
||||
InterpretedFunction f = idata.itsNestedFunctions[i];
|
||||
out.println(tname + " " + f);
|
||||
InterpreterData data2 = idata.itsNestedFunctions[i];
|
||||
out.println(tname + " " + data2);
|
||||
pc += 2;
|
||||
break;
|
||||
}
|
||||
@ -1624,7 +1624,7 @@ public class Interpreter {
|
||||
if (idata.itsFunctionType != 0 && !idata.itsNeedsActivation)
|
||||
Context.codeBug();
|
||||
for (int i = 0; i < idata.itsNestedFunctions.length; i++) {
|
||||
InterpreterData fdata = idata.itsNestedFunctions[i].itsData;
|
||||
InterpreterData fdata = idata.itsNestedFunctions[i];
|
||||
if (fdata.itsFunctionType == FunctionNode.FUNCTION_STATEMENT) {
|
||||
createFunction(cx, scope, fdata, idata.itsFromEvalCode);
|
||||
}
|
||||
@ -2436,7 +2436,7 @@ public class Interpreter {
|
||||
break;
|
||||
case TokenStream.CLOSURE : {
|
||||
int i = getIndex(iCode, pc + 1);
|
||||
InterpreterData closureData = idata.itsNestedFunctions[i].itsData;
|
||||
InterpreterData closureData = idata.itsNestedFunctions[i];
|
||||
InterpretedFunction closure = createFunction(cx, scope, closureData,
|
||||
idata.itsFromEvalCode);
|
||||
closure.itsClosure = scope;
|
||||
|
@ -69,7 +69,7 @@ final class InterpreterData implements Serializable, DebuggableScript {
|
||||
|
||||
String[] itsStringTable;
|
||||
double[] itsDoubleTable;
|
||||
InterpretedFunction[] itsNestedFunctions;
|
||||
InterpreterData[] itsNestedFunctions;
|
||||
Object[] itsRegExpLiterals;
|
||||
|
||||
byte[] itsICode;
|
||||
|
@ -1588,21 +1588,43 @@ class Parser {
|
||||
static String decompile(NativeFunction f, int version,
|
||||
int indent, boolean justbody)
|
||||
{
|
||||
StringBuffer result = new StringBuffer();
|
||||
Object[] srcData = new Object[1];
|
||||
decompile_r(f, version, indent, true, justbody, srcData, result);
|
||||
return result.toString();
|
||||
StringBuffer result = new StringBuffer();
|
||||
Object[] srcData = new Object[1];
|
||||
int type = f.fromFunctionConstructor ? CONSTRUCTED_FUNCTION
|
||||
: TOP_LEVEL_SCRIPT_OR_FUNCTION;
|
||||
|
||||
// The following casts can be avoided via additional interface
|
||||
// but it is not worth it to replace a simple if sequence by more
|
||||
// spread code
|
||||
Object fdata;
|
||||
if (f instanceof InterpretedFunction) {
|
||||
fdata = ((InterpretedFunction)f).itsData;
|
||||
} else if (f instanceof InterpretedScript) {
|
||||
fdata = ((InterpretedScript)f).itsData;
|
||||
} else {
|
||||
fdata = f;
|
||||
}
|
||||
decompile_r(fdata, version, indent, type, justbody, srcData, result);
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
private static void decompile_r(NativeFunction f, int version, int indent,
|
||||
boolean toplevel, boolean justbody,
|
||||
private static void decompile_r(Object fdata, int version, int indent,
|
||||
int type, boolean justbody,
|
||||
Object[] srcData, StringBuffer result)
|
||||
{
|
||||
String source = f.source;
|
||||
int length = source.length();
|
||||
String source;
|
||||
Object[] nestedFunctions;
|
||||
if (fdata instanceof InterpreterData) {
|
||||
InterpreterData idata = (InterpreterData)fdata;
|
||||
source = idata.itsSource;
|
||||
nestedFunctions = idata.itsNestedFunctions;
|
||||
} else {
|
||||
NativeFunction f = (NativeFunction)fdata;
|
||||
source = f.source;
|
||||
nestedFunctions = f.nestedFunctions;
|
||||
}
|
||||
|
||||
NativeFunction[] nestedFunctions = f.nestedFunctions;
|
||||
boolean fromFunctionConstructor = f.fromFunctionConstructor;
|
||||
int length = source.length();
|
||||
|
||||
// Spew tokens in source, for debugging.
|
||||
// as TYPE number char
|
||||
@ -1634,7 +1656,7 @@ class Parser {
|
||||
// decompiling the toplevel script, otherwise it a function
|
||||
// and should start with TokenStream.FUNCTION
|
||||
|
||||
if (toplevel) {
|
||||
if (type != NESTED_FUNCTION) {
|
||||
// add an initial newline to exactly match js.
|
||||
if (!justbody)
|
||||
result.append('\n');
|
||||
@ -1648,7 +1670,7 @@ class Parser {
|
||||
if (!justbody) {
|
||||
result.append("function ");
|
||||
|
||||
/* version != 1.2 Function constructor behavior -
|
||||
/* version != 1.2 Function constructor behavior -
|
||||
* print 'anonymous' as the function name if the
|
||||
* version (under which the function was compiled) is
|
||||
* less than 1.2... or if it's greater than 1.2, because
|
||||
@ -1656,7 +1678,7 @@ class Parser {
|
||||
*/
|
||||
if (source.charAt(i) == TokenStream.LP
|
||||
&& version != Context.VERSION_1_2
|
||||
&& fromFunctionConstructor)
|
||||
&& type == CONSTRUCTED_FUNCTION)
|
||||
{
|
||||
result.append("anonymous");
|
||||
}
|
||||
@ -1766,7 +1788,7 @@ class Parser {
|
||||
new Integer(functionNumber)));
|
||||
}
|
||||
decompile_r(nestedFunctions[functionNumber], version,
|
||||
indent, false, false, srcData, result);
|
||||
indent, NESTED_FUNCTION, false, srcData, result);
|
||||
break;
|
||||
}
|
||||
case TokenStream.COMMA:
|
||||
@ -1784,7 +1806,7 @@ class Parser {
|
||||
* toplevel function and we're called from
|
||||
* decompileFunctionBody.
|
||||
*/
|
||||
if (justbody && toplevel && i + 1 == length)
|
||||
if (justbody && type != NESTED_FUNCTION && i + 1 == length)
|
||||
break;
|
||||
|
||||
if (nextIs(source, length, i, TokenStream.EOL))
|
||||
@ -2182,7 +2204,7 @@ class Parser {
|
||||
}
|
||||
|
||||
// add that trailing newline if it's an outermost function.
|
||||
if (toplevel && !justbody)
|
||||
if (type != NESTED_FUNCTION && !justbody)
|
||||
result.append('\n');
|
||||
}
|
||||
|
||||
@ -2254,6 +2276,10 @@ class Parser {
|
||||
// less how much for case labels
|
||||
private final static int SETBACK = 2;
|
||||
|
||||
private static final int TOP_LEVEL_SCRIPT_OR_FUNCTION = 0;
|
||||
private static final int CONSTRUCTED_FUNCTION = 1;
|
||||
private static final int NESTED_FUNCTION = 2;
|
||||
|
||||
// whether to do a debug print of the source information, when
|
||||
// decompiling.
|
||||
private static final boolean printSource = false;
|
||||
|
Loading…
Reference in New Issue
Block a user