* 表达式子节点生存域
*/
public FunctionLiteral(Node node, ScriptOrFnNode root, Scope scope) {
super(root.getFunctionNode(node.getIntProp(Node.FUNCTION_PROP, -1))
.getLineno());
FunctionNode fnNode = root.getFunctionNode(node.getIntProp(
Node.FUNCTION_PROP, -1));
fnScope = new Scope(scope);
if (fnNode.getFunctionName().length() > 0) {
name = scope.addIdentifier(fnNode.getFunctionName());
}
node = fnNode.getFirstChild().getFirstChild();
if (node.getType() == Token.EXPR_VOID) {
Node firstChild = node.getFirstChild();
if (firstChild.getType() == Token.SETNAME
&& firstChild.getLastChild().getType() == Token.THISFN) {
node = node.getNext();
}
}
while (node != null) {
IStatement statement = Utils.createStatement(node, fnNode, fnScope);
statements.add(statement);
node = statement.getNext();
}
int size = statements.size() - 1;
if (statements.size() >= 0) {
IStatement statement = statements.get(size);
if (statement instanceof ControlStatement
&& ((ControlStatement) statement).getType() == Token.RETURN) {
statements.remove(size);
}
}
new NodeTransformer().transform(fnNode);
String[] symbols = fnNode.getParamAndVarNames();
for (int i = 0; i < symbols.length; i++) {
String symbol = symbols[i];
fnScope.registerLocalIdentifier(symbol);
if (i < fnNode.getParamCount()) {
Identifier identifier = fnScope.addIdentifier(symbol);
identifier.inc((fnNode.getParamCount() - i) * 10000000);
params.add(identifier);
}
}
}