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
FunctionDeclaration
JavaScript 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.PositionComparatorNode.NodeIterator| Modifier and Type | Field and Description |
|---|---|
static int |
ARROW_FUNCTION |
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, topinlineComment, length, parent, positionARROW_FUNCTION_PROP, ATTRIBUTE_FLAG, BOTH, CASEARRAY_PROP, CATCH_SCOPE_PROP, CONTROL_BLOCK_PROP, DECR_FLAG, DESCENDANTS_FLAG, DESTRUCTURING_ARRAY_LENGTH, DESTRUCTURING_NAMES, DESTRUCTURING_PARAMS, DIRECTCALL_PROP, END_DROPS_OFF, END_RETURNS, END_RETURNS_VALUE, END_UNREACHED, END_YIELDS, EXPRESSION_CLOSURE_PROP, first, FIRST_PROP, 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, NUMBER_OF_SPREAD, OBJECT_IDS_PROP, OBJECT_LITERAL_DESTRUCTURING, OPTIONAL_CHAINING, PARENTHESIZED_PROP, POST_FLAG, PROPERTY_FLAG, propListHead, REGEXP_PROP, RIGHT, SKIP_INDEXES_PROP, SPECIALCALL_EVAL, SPECIALCALL_PROP, SPECIALCALL_WITH, SUPER_PROPERTY_ACCESS, TARGETBLOCK_PROP, TEMPLATE_LITERAL_PROP, TRAILING_COMMA, 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.
|
List<Object> |
getDefaultParams() |
List<Node[]> |
getDestructuringRvalues() |
Name |
getFunctionName()
Returns function name
|
int |
getFunctionType()
Returns the function type (statement, expr, statement expr)
|
Map<Node,int[]> |
getLiveLocals() |
int |
getLp()
Returns left paren position, -1 if missing
|
AstNode |
getMemberExprNode() |
String |
getName()
Returns the function name as a string
|
List<AstNode> |
getParams()
Returns the function parameter list
|
List<Node> |
getResumptionPoints() |
int |
getRp()
Returns right paren position, -1 if missing
|
boolean |
hasRestParameter() |
boolean |
isES6Generator() |
boolean |
isExpressionClosure()
Returns whether this is a 1.8 function closure
|
boolean |
isGenerator() |
boolean |
isGetterMethod() |
boolean |
isMethod() |
boolean |
isNormalMethod() |
boolean |
isParam(AstNode node)
Returns true if the specified
AstNode node is a parameter of this Function node. |
boolean |
isSetterMethod() |
boolean |
isShorthand() |
void |
putDefaultParams(Object left,
Object right) |
void |
putDestructuringRvalues(Node left,
Node right) |
boolean |
requiresActivation()
Return true if this function requires an Ecma-262 Activation object.
|
boolean |
requiresArgumentObject() |
void |
setBody(AstNode body)
Sets function body, and sets its parent to this node.
|
void |
setFunctionIsGetterMethod() |
void |
setFunctionIsNormalMethod() |
void |
setFunctionIsSetterMethod() |
void |
setFunctionName(Name name)
Sets function name, and sets its parent to this node.
|
void |
setFunctionType(int type) |
void |
setHasRestParameter(boolean hasRestParameter) |
void |
setIsES6Generator() |
void |
setIsExpressionClosure(boolean isExpressionClosure)
Sets whether this is a 1.8 function closure
|
void |
setIsGenerator() |
void |
setIsShorthand() |
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(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 |
setRequiresArgumentObject() |
void |
setRp(int rp)
Sets right paren position
|
String |
toSource(int depth)
Jumps are only used directly during code generation, and do not support this interface.
|
void |
visit(NodeVisitor v)
Visits this node, the function name node if supplied, the parameters, and the body.
|
addRegExp, addTemplateLiteral, flattenSymbolTable, getBaseLineno, getCompilerData, getEndLineno, getFunctionCount, getFunctionNode, getFunctions, getIndexForNameNode, getNextTempName, getParamAndVarConst, getParamAndVarCount, getParamAndVarNames, getParamCount, getParamOrVarName, getRawSource, getRawSourceEnd, getRawSourceStart, getRegexpCount, getRegexpFlags, getRegexpString, getSourceName, getSymbols, getTemplateLiteralCount, getTemplateLiteralStrings, isInStrictMode, isMethodDefinition, setBaseLineno, setCompilerData, setEndLineno, setInStrictMode, setMethodDefinition, setRawSource, setRawSourceBounds, setRawSourceEnd, setRawSourceStart, setSourceName, setSymbolsaddChildScope, clearParentScope, getChildScopes, getDefiningScope, getParentScope, getStatements, getSymbol, getSymbolTable, getTop, joinScopes, putSymbol, replaceWith, setParentScope, setSymbolTable, setTop, splitScopegetContinue, getDefault, getFinally, getJumpStatement, getLoop, setContinue, setDefault, setFinally, setJumpStatement, setLoopaddChild, assertNotNull, codeBug, compareTo, debugPrint, depth, getAbsolutePosition, getAstRoot, getEnclosingFunction, getEnclosingScope, getInlineComment, getLength, getLineno, getParent, getPosition, hasSideEffects, makeIndent, operatorToString, printList, setBounds, setInlineComment, setLength, setParent, setPosition, setRelative, shortName, toSourceaddChildAfter, addChildBefore, addChildrenToBack, addChildrenToFront, addChildToBack, addChildToFront, getBigInt, getChildBefore, getColumn, 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, setBigInt, setDouble, setJsDocNode, setLineColumnNumber, setScope, setString, setType, toString, toStringTreeclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitforEach, spliteratorpublic 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 static final int ARROW_FUNCTION
public FunctionNode()
public FunctionNode(int pos)
public FunctionNode(int pos,
Name name)
public List<Object> getDefaultParams()
getDefaultParams in class ScriptNodepublic List<Node[]> getDestructuringRvalues()
getDestructuringRvalues in class ScriptNodepublic void putDestructuringRvalues(Node left, Node right)
putDestructuringRvalues in class ScriptNodepublic Name getFunctionName()
null for anonymous functionspublic void setFunctionName(Name name)
name - function name, null for anonymous functionspublic String getName()
"" if anonymouspublic List<AstNode> getParams()
public void setParams(List<AstNode> params)
params - the function parameter list, or null if no paramspublic void addParam(AstNode param)
param - the parameterIllegalArgumentException - if param is nullpublic 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.IllegalArgumentException - if body is nullpublic 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 requiresArgumentObject()
public void setRequiresArgumentObject()
public boolean isGenerator()
public void setIsGenerator()
public boolean isES6Generator()
public void setIsES6Generator()
public boolean hasRestParameter()
hasRestParameter in class ScriptNodepublic void setHasRestParameter(boolean hasRestParameter)
public boolean isShorthand()
isShorthand in class ScriptNodepublic void setIsShorthand()
public void addResumptionPoint(Node target)
public void addLiveLocals(Node node, int[] locals)
public int addFunction(FunctionNode fnNode)
ScriptNodeFunctionNode to the functions table for codegen. Does not set the parent of
the node.addFunction in class ScriptNodepublic int getFunctionType()
public void setFunctionType(int type)
public boolean isMethod()
public boolean isGetterMethod()
public boolean isSetterMethod()
public boolean isNormalMethod()
public void setFunctionIsGetterMethod()
public void setFunctionIsSetterMethod()
public void setFunctionIsNormalMethod()
public void setMemberExprNode(AstNode node)
This extension is only available by setting the CompilerEnv option "isAllowMemberExprAsFunctionName" in the Parser.
public AstNode getMemberExprNode()
public String toSource(int depth)
Jumppublic void visit(NodeVisitor v)
visit in class ScriptNodev - the object to call with this node and its childrenCopyright © 2025 HtmlUnit. All rights reserved.