зеркало из https://github.com/mozilla/pjs.git
Store function array inside ScriptOrFnNode as field, not as a node property.
This commit is contained in:
Родитель
fc20f85a8f
Коммит
93721f0a59
|
@ -2021,7 +2021,7 @@ public class Context {
|
|||
|
||||
if (debugger != null) {
|
||||
if (sourceString == null) Context.codeBug();
|
||||
tree.originalSource = sourceString;
|
||||
tree.setOriginalSource(sourceString);
|
||||
}
|
||||
|
||||
Object result = compiler.compile(this, scope, tree,
|
||||
|
|
|
@ -145,15 +145,14 @@ public class Interpreter {
|
|||
}
|
||||
|
||||
private void generateNestedFunctions(Context cx, Scriptable scope,
|
||||
Node tree)
|
||||
ScriptOrFnNode tree)
|
||||
{
|
||||
ObjArray functionList = (ObjArray) tree.getProp(Node.FUNCTION_PROP);
|
||||
if (functionList == null) return;
|
||||
int functionCount = tree.getFunctionCount();
|
||||
if (functionCount == 0) return;
|
||||
|
||||
int N = functionList.size();
|
||||
InterpreterData[] array = new InterpreterData[N];
|
||||
for (int i = 0; i != N; i++) {
|
||||
FunctionNode def = (FunctionNode)functionList.get(i);
|
||||
InterpreterData[] array = new InterpreterData[functionCount];
|
||||
for (int i = 0; i != functionCount; i++) {
|
||||
FunctionNode def = tree.getFunctionNode(i);
|
||||
Interpreter jsi = new Interpreter();
|
||||
jsi.itsSourceFile = itsSourceFile;
|
||||
jsi.itsData = new InterpreterData(itsData.securityDomain);
|
||||
|
|
|
@ -112,8 +112,8 @@ public class NodeTransformer {
|
|||
}
|
||||
|
||||
} else {
|
||||
FunctionNode fnNode = (FunctionNode)
|
||||
node.getProp(Node.FUNCTION_PROP);
|
||||
FunctionNode
|
||||
fnNode = (FunctionNode)node.getProp(Node.FUNCTION_PROP);
|
||||
if (inFunction) {
|
||||
// Functions containing other functions require
|
||||
// activation objects
|
||||
|
@ -127,12 +127,7 @@ public class NodeTransformer {
|
|||
NodeTransformer inner = newInstance();
|
||||
fnNode = (FunctionNode)inner.transform(fnNode);
|
||||
node.putProp(Node.FUNCTION_PROP, fnNode);
|
||||
ObjArray fns = (ObjArray) tree.getProp(Node.FUNCTION_PROP);
|
||||
if (fns == null) {
|
||||
fns = new ObjArray();
|
||||
tree.putProp(Node.FUNCTION_PROP, fns);
|
||||
}
|
||||
fns.add(fnNode);
|
||||
tree.addFunction(fnNode);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
|
@ -47,12 +47,40 @@ public class ScriptOrFnNode extends Node {
|
|||
|
||||
public final String getOriginalSource() { return originalSource; }
|
||||
|
||||
public final void setOriginalSource(String originalSource) {
|
||||
// One time action
|
||||
if (originalSource == null || this.originalSource != null)
|
||||
Context.codeBug();
|
||||
this.originalSource = originalSource;
|
||||
}
|
||||
|
||||
public final String getSourceName() { return sourceName; }
|
||||
|
||||
public final int getBaseLineno() { return baseLineno; }
|
||||
|
||||
public final int getEndLineno() { return baseLineno; }
|
||||
|
||||
public final int getFunctionCount() {
|
||||
if (functions == null) { return 0; }
|
||||
return functions.size();
|
||||
}
|
||||
|
||||
public final FunctionNode getFunctionNode(int i) {
|
||||
return (FunctionNode)functions.get(i);
|
||||
}
|
||||
|
||||
public final void replaceFunctionNode(int i, FunctionNode fnNode) {
|
||||
if (fnNode == null) Context.codeBug();
|
||||
functions.set(i, fnNode);
|
||||
}
|
||||
|
||||
public final int addFunction(FunctionNode fnNode) {
|
||||
if (fnNode == null) Context.codeBug();
|
||||
if (functions == null) { functions = new ObjArray(); }
|
||||
functions.add(fnNode);
|
||||
return functions.size();
|
||||
}
|
||||
|
||||
public final int getRegexpCount() {
|
||||
if (regexps == null) { return 0; }
|
||||
return regexps.size() / 2;
|
||||
|
@ -67,6 +95,7 @@ public class ScriptOrFnNode extends Node {
|
|||
}
|
||||
|
||||
public final int addRegexp(String string, String flags) {
|
||||
if (string == null) Context.codeBug();
|
||||
if (regexps == null) { regexps = new ObjArray(); }
|
||||
regexps.add(string);
|
||||
regexps.add(flags);
|
||||
|
@ -75,10 +104,11 @@ public class ScriptOrFnNode extends Node {
|
|||
|
||||
VariableTable variableTable;
|
||||
String encodedSource;
|
||||
String originalSource;
|
||||
private String originalSource;
|
||||
String sourceName;
|
||||
int baseLineno = -1;
|
||||
int endLineno = -1;
|
||||
private ObjArray functions;
|
||||
private ObjArray regexps;
|
||||
|
||||
}
|
||||
|
|
|
@ -385,10 +385,10 @@ public class Codegen extends Interpreter {
|
|||
private String
|
||||
generateCode(ScriptOrFnNode tree, ObjArray names, ObjArray classFiles)
|
||||
{
|
||||
ObjArray fns = (ObjArray) tree.getProp(Node.FUNCTION_PROP);
|
||||
if (fns != null) {
|
||||
for (int i = 0; i != fns.size(); ++i) {
|
||||
OptFunctionNode fn = (OptFunctionNode) fns.get(i);
|
||||
int functionCount = tree.getFunctionCount();
|
||||
if (functionCount != 0) {
|
||||
for (int i = 0; i != functionCount; ++i) {
|
||||
OptFunctionNode fn = (OptFunctionNode)tree.getFunctionNode(i);
|
||||
Codegen codegen = new Codegen(this);
|
||||
codegen.generateCode(fn, names, classFiles);
|
||||
}
|
||||
|
@ -1235,29 +1235,29 @@ public class Codegen extends Interpreter {
|
|||
classFile.startMethod(getSourceMethodStr,
|
||||
"()Ljava/lang/Object;",
|
||||
(short)flags);
|
||||
ObjArray fns = (ObjArray) tree.getProp(Node.FUNCTION_PROP);
|
||||
if (fns == null) {
|
||||
int functionCount = tree.getFunctionCount();
|
||||
if (functionCount == 0) {
|
||||
// generate return <source-literal-string>;
|
||||
push(source);
|
||||
} else {
|
||||
// generate with N = fns.size():
|
||||
// Object[] result = new Object[1 + N];
|
||||
// generate
|
||||
// Object[] result = new Object[1 + functionCount];
|
||||
// result[0] = <source-literal-string>
|
||||
// result[1] = Class1.getSourcesTreeImpl();
|
||||
// ...
|
||||
// result[N] = ClassN.getSourcesTreeImpl();
|
||||
// result[functionCount] = ClassN.getSourcesTreeImpl();
|
||||
// return result;
|
||||
push(1 + fns.size());
|
||||
push(1 + functionCount);
|
||||
addByteCode(ByteCode.ANEWARRAY, "java/lang/Object");
|
||||
addByteCode(ByteCode.DUP); // dup array reference
|
||||
push(0);
|
||||
push(source);
|
||||
addByteCode(ByteCode.AASTORE);
|
||||
for (int i = 0; i != fns.size(); ++i) {
|
||||
for (int i = 0; i != functionCount; ++i) {
|
||||
OptFunctionNode fn;
|
||||
addByteCode(ByteCode.DUP); // dup array reference
|
||||
push(1 + i);
|
||||
|
||||
OptFunctionNode fn = (OptFunctionNode) fns.get(i);
|
||||
fn = (OptFunctionNode)tree.getFunctionNode(i);
|
||||
classFile.add(ByteCode.INVOKESTATIC,
|
||||
fn.getClassName(),
|
||||
getSourceMethodStr,
|
||||
|
@ -1324,8 +1324,9 @@ public class Codegen extends Interpreter {
|
|||
* @param directParameterCount number of parameters for direct call,
|
||||
* or -1 if not direct call
|
||||
*/
|
||||
private void generatePrologue(Context cx, Node tree, boolean inFunction,
|
||||
int directParameterCount)
|
||||
private void
|
||||
generatePrologue(Context cx, ScriptOrFnNode tree, boolean inFunction,
|
||||
int directParameterCount)
|
||||
{
|
||||
funObjLocal = reserveWordLocal(0);
|
||||
contextLocal = reserveWordLocal(1);
|
||||
|
@ -1488,10 +1489,10 @@ public class Codegen extends Interpreter {
|
|||
}
|
||||
astore(variableObjectLocal);
|
||||
|
||||
ObjArray fns = (ObjArray) tree.getProp(Node.FUNCTION_PROP);
|
||||
if (fns != null) {
|
||||
for (int i=0; i < fns.size(); i++) {
|
||||
OptFunctionNode fn = (OptFunctionNode) fns.get(i);
|
||||
int functionCount = tree.getFunctionCount();
|
||||
if (functionCount != 0) {
|
||||
for (int i=0; i < functionCount; i++) {
|
||||
OptFunctionNode fn = (OptFunctionNode)tree.getFunctionNode(i);
|
||||
if (fn.getFunctionType() == FunctionNode.FUNCTION_STATEMENT) {
|
||||
visitFunction(fn, FunctionNode.FUNCTION_STATEMENT);
|
||||
addByteCode(ByteCode.POP);
|
||||
|
|
|
@ -154,8 +154,8 @@ class OptTransformer extends NodeTransformer {
|
|||
private void collectContainedFunctions(Node node) {
|
||||
for (Node tNode=node; tNode != null; tNode = tNode.getNext()) {
|
||||
if (tNode.getType() == TokenStream.FUNCTION) {
|
||||
FunctionNode fnNode = (FunctionNode)
|
||||
tNode.getProp(Node.FUNCTION_PROP);
|
||||
FunctionNode
|
||||
fnNode = (FunctionNode)tNode.getProp(Node.FUNCTION_PROP);
|
||||
if (fnNode.getType() == FunctionNode.FUNCTION_STATEMENT) {
|
||||
String name = fnNode.getFunctionName();
|
||||
if (name.length() != 0) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче