public class FunctionNode extends ScriptNode
Node type is Token.FUNCTION
.
FunctionDeclaration : function Identifier ( FormalParameterListopt ) { FunctionBody } FunctionExpression : function Identifieropt ( FormalParameterListopt ) { FunctionBody } FormalParameterList : Identifier FormalParameterList , Identifier FunctionBody : SourceElements Program : SourceElements SourceElements : SourceElement SourceElements SourceElement SourceElement : Statement FunctionDeclarationJavaScript 1.8 introduces "function closures" of the form
function ([params] ) ExpressionIn this case the FunctionNode node will have no body but will have an expression.
Modifier and Type | Class and Description |
---|---|
static class |
FunctionNode.Form |
AstNode.DebugPrintVisitor, AstNode.PositionComparator
Node.NodeIterator
Modifier and Type | Field and Description |
---|---|
static int |
FUNCTION_EXPRESSION |
static int |
FUNCTION_EXPRESSION_STATEMENT |
static int |
FUNCTION_STATEMENT
There are three types of functions that can be defined.
|
parentScope, symbolTable, top
ATTRIBUTE_FLAG, BOTH, CASEARRAY_PROP, CATCH_SCOPE_PROP, CONTROL_BLOCK_PROP, DECR_FLAG, DESCENDANTS_FLAG, DESTRUCTURING_ARRAY_LENGTH, DESTRUCTURING_NAMES, DESTRUCTURING_PARAMS, DESTRUCTURING_SHORTHAND, DIRECTCALL_PROP, END_DROPS_OFF, END_RETURNS, END_RETURNS_VALUE, END_UNREACHED, END_YIELDS, EXPRESSION_CLOSURE_PROP, first, FUNCTION_PROP, GENERATOR_END_PROP, INCRDECR_PROP, ISNUMBER_PROP, JSDOC_PROP, LABEL_ID_PROP, last, LAST_PROP, LEFT, lineno, LOCAL_BLOCK_PROP, LOCAL_PROP, MEMBER_TYPE_PROP, NAME_PROP, next, NON_SPECIALCALL, OBJECT_IDS_PROP, PARENTHESIZED_PROP, POST_FLAG, PROPERTY_FLAG, propListHead, REGEXP_PROP, RIGHT, SKIP_INDEXES_PROP, SPECIALCALL_EVAL, SPECIALCALL_PROP, SPECIALCALL_WITH, TARGETBLOCK_PROP, type, VARIABLE_PROP
Constructor and Description |
---|
FunctionNode() |
FunctionNode(int pos) |
FunctionNode(int pos,
Name name) |
Modifier and Type | Method and Description |
---|---|
int |
addFunction(FunctionNode fnNode)
Adds a
FunctionNode to the functions table for codegen. |
void |
addLiveLocals(Node node,
int[] locals) |
void |
addParam(AstNode param)
Adds a parameter to the function parameter list.
|
void |
addResumptionPoint(Node target) |
AstNode |
getBody()
Returns function body.
|
Name |
getFunctionName()
Returns function name
|
int |
getFunctionType()
Returns the function type (statement, expr, statement expr)
|
java.util.Map<Node,int[]> |
getLiveLocals() |
int |
getLp()
Returns left paren position, -1 if missing
|
AstNode |
getMemberExprNode() |
java.lang.String |
getName()
Returns the function name as a string
|
java.util.List<AstNode> |
getParams()
Returns the function parameter list
|
java.util.List<Node> |
getResumptionPoints() |
int |
getRp()
Returns right paren position, -1 if missing
|
boolean |
isExpressionClosure()
Returns whether this is a 1.8 function closure
|
boolean |
isGenerator() |
boolean |
isGetter() |
boolean |
isGetterOrSetter() |
boolean |
isParam(AstNode node)
Returns true if the specified
AstNode node is a parameter
of this Function node. |
boolean |
isSetter() |
boolean |
requiresActivation()
Return true if this function requires an Ecma-262 Activation object.
|
void |
setBody(AstNode body)
Sets function body, and sets its parent to this node.
|
void |
setFunctionIsGetter() |
void |
setFunctionIsSetter() |
void |
setFunctionName(Name name)
Sets function name, and sets its parent to this node.
|
void |
setFunctionType(int type) |
void |
setIsExpressionClosure(boolean isExpressionClosure)
Sets whether this is a 1.8 function closure
|
void |
setIsGenerator() |
void |
setLp(int lp)
Sets left paren position
|
void |
setMemberExprNode(AstNode node)
Rhino supports a nonstandard Ecma extension that allows you to
say, for instance, function a.b.c(arg1, arg) {...}, and it will
be rewritten at codegen time to: a.b.c = function(arg1, arg2) {...}
|
void |
setParams(java.util.List<AstNode> params)
Sets the function parameter list, and sets the parent for
each element of the list.
|
void |
setParens(int lp,
int rp)
Sets both paren positions
|
void |
setRequiresActivation() |
void |
setRp(int rp)
Sets right paren position
|
java.lang.String |
toSource(int depth)
Emits source code for this node.
|
void |
visit(NodeVisitor v)
Visits this node, the function name node if supplied,
the parameters, and the body.
|
addRegExp, flattenSymbolTable, getBaseLineno, getCompilerData, getEncodedSource, getEncodedSourceEnd, getEncodedSourceStart, getEndLineno, getFunctionCount, getFunctionNode, getFunctions, getIndexForNameNode, getNextTempName, getParamAndVarConst, getParamAndVarCount, getParamAndVarNames, getParamCount, getParamOrVarName, getRegexpCount, getRegexpFlags, getRegexpString, getSourceName, getSymbols, setBaseLineno, setCompilerData, setEncodedSource, setEncodedSourceBounds, setEncodedSourceEnd, setEncodedSourceStart, setEndLineno, setSourceName, setSymbols
addChildScope, clearParentScope, getChildScopes, getDefiningScope, getParentScope, getStatements, getSymbol, getSymbolTable, getTop, joinScopes, putSymbol, replaceWith, setParentScope, setSymbolTable, setTop, splitScope
getContinue, getDefault, getFinally, getJumpStatement, getLoop, setContinue, setDefault, setFinally, setJumpStatement, setLoop
addChild, assertNotNull, codeBug, compareTo, debugPrint, depth, getAbsolutePosition, getAstRoot, getEnclosingFunction, getEnclosingScope, getLength, getLineno, getParent, getPosition, hasSideEffects, makeIndent, operatorToString, printList, setBounds, setLength, setParent, setPosition, setRelative, shortName, toSource
addChildAfter, addChildBefore, addChildrenToBack, addChildrenToFront, addChildToBack, addChildToFront, getChildBefore, getDouble, getExistingIntProp, getFirstChild, getIntProp, getJsDoc, getJsDocNode, getLastChild, getLastSibling, getNext, getProp, getScope, getString, getType, hasChildren, hasConsistentReturnUsage, iterator, labelId, labelId, newNumber, newString, newString, newTarget, putIntProp, putProp, removeChild, removeChildren, removeProp, replaceChild, replaceChildAfter, resetTargets, setDouble, setJsDocNode, setLineno, setScope, setString, setType, toString, toStringTree
public static final int FUNCTION_STATEMENT
The second is a function expression, which is a function appearing in an expression except for the third type, which is...
The third type is a function expression where the expression is the top-level expression in an expression statement.
The three types of functions have different treatment and must be distinguished.
public static final int FUNCTION_EXPRESSION
public static final int FUNCTION_EXPRESSION_STATEMENT
public FunctionNode()
public FunctionNode(int pos)
public FunctionNode(int pos, Name name)
public Name getFunctionName()
null
for anonymous functionspublic void setFunctionName(Name name)
name
- function name, null
for anonymous functionspublic java.lang.String getName()
""
if anonymouspublic java.util.List<AstNode> getParams()
public void setParams(java.util.List<AstNode> params)
params
- the function parameter list, or null
if no paramspublic void addParam(AstNode param)
param
- the parameterjava.lang.IllegalArgumentException
- if param is null
public boolean isParam(AstNode node)
AstNode
node is a parameter
of this Function node. This provides a way during AST traversal
to disambiguate the function name node from the parameter nodes.public AstNode getBody()
null
only if the AST is malformed.public void setBody(AstNode body)
body
- function body. Its parent is set to this node, and its
position is updated to be relative to this node.java.lang.IllegalArgumentException
- if body is null
public int getLp()
public void setLp(int lp)
public int getRp()
public void setRp(int rp)
public void setParens(int lp, int rp)
public boolean isExpressionClosure()
public void setIsExpressionClosure(boolean isExpressionClosure)
public boolean requiresActivation()
NativeCall
, and is fairly expensive
to create, so when possible, the interpreter attempts to use a plain
call frame instead.public void setRequiresActivation()
public boolean isGenerator()
public void setIsGenerator()
public void addResumptionPoint(Node target)
public java.util.List<Node> getResumptionPoints()
public java.util.Map<Node,int[]> getLiveLocals()
public void addLiveLocals(Node node, int[] locals)
public int addFunction(FunctionNode fnNode)
ScriptNode
FunctionNode
to the functions table for codegen.
Does not set the parent of the node.addFunction
in class ScriptNode
public int getFunctionType()
public void setFunctionType(int type)
public boolean isGetterOrSetter()
public boolean isGetter()
public boolean isSetter()
public void setFunctionIsGetter()
public void setFunctionIsSetter()
public void setMemberExprNode(AstNode node)
This extension is only available by setting the CompilerEnv option "isAllowMemberExprAsFunctionName" in the Parser.
public AstNode getMemberExprNode()
public java.lang.String toSource(int depth)
AstNode
Note: if the parser was in error-recovery mode, some AST nodes may have
null
children that are expected to be non-null
when no errors are present. In this situation, the behavior of the
toSource
method is undefined: toSource
implementations may assume that the AST node is error-free, since it is
intended to be invoked only at runtime after a successful parse.
public void visit(NodeVisitor v)
visit
in class ScriptNode
v
- the object to call with this node and its children