Class FunctionNode
- java.lang.Object
- 
- org.mozilla.javascript.Node
- 
- org.mozilla.javascript.ast.AstNode
- 
- org.mozilla.javascript.ast.Jump
- 
- org.mozilla.javascript.ast.Scope
- 
- org.mozilla.javascript.ast.ScriptNode
- 
- org.mozilla.javascript.ast.FunctionNode
 
 
 
 
 
 
- 
 public class FunctionNode extends ScriptNode A JavaScript function declaration or expression.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 formfunction ([params] ) Expression In this case the FunctionNode node will have no body but will have an expression.
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classFunctionNode.Form- 
Nested classes/interfaces inherited from class org.mozilla.javascript.ast.AstNodeAstNode.DebugPrintVisitor, AstNode.PositionComparator
 - 
Nested classes/interfaces inherited from class org.mozilla.javascript.NodeNode.NodeIterator
 
- 
 - 
Field SummaryFields Modifier and Type Field Description static intARROW_FUNCTIONstatic intFUNCTION_EXPRESSIONstatic intFUNCTION_EXPRESSION_STATEMENTstatic intFUNCTION_STATEMENTThere are three types of functions that can be defined.- 
Fields inherited from class org.mozilla.javascript.ast.ScopeparentScope, symbolTable, top
 - 
Fields inherited from class org.mozilla.javascript.ast.AstNodeinlineComment, length, parent, position
 - 
Fields inherited from class org.mozilla.javascript.NodeARROW_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, 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, SHORTHAND_PROPERTY_NAME, SKIP_INDEXES_PROP, SPECIALCALL_EVAL, SPECIALCALL_PROP, SPECIALCALL_WITH, TARGETBLOCK_PROP, TEMPLATE_LITERAL_PROP, TRAILING_COMMA, type, VARIABLE_PROP
 
- 
 - 
Constructor SummaryConstructors Constructor Description FunctionNode()FunctionNode(int pos)FunctionNode(int pos, Name name)
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description intaddFunction(FunctionNode fnNode)Adds aFunctionNodeto the functions table for codegen.voidaddLiveLocals(Node node, int[] locals)voidaddParam(AstNode param)Adds a parameter to the function parameter list.voidaddResumptionPoint(Node target)AstNodegetBody()Returns function body.NamegetFunctionName()Returns function nameintgetFunctionType()Returns the function type (statement, expr, statement expr)java.util.Map<Node,int[]>getLiveLocals()intgetLp()Returns left paren position, -1 if missingAstNodegetMemberExprNode()java.lang.StringgetName()Returns the function name as a stringjava.util.List<AstNode>getParams()Returns the function parameter listjava.util.List<Node>getResumptionPoints()intgetRp()Returns right paren position, -1 if missingbooleanhasRestParameter()booleanisES6Generator()booleanisExpressionClosure()Returns whether this is a 1.8 function closurebooleanisGenerator()booleanisGetterMethod()booleanisMethod()booleanisNormalMethod()booleanisParam(AstNode node)Returns true if the specifiedAstNodenode is a parameter of this Function node.booleanisSetterMethod()booleanrequiresActivation()Return true if this function requires an Ecma-262 Activation object.voidsetBody(AstNode body)Sets function body, and sets its parent to this node.voidsetFunctionIsGetterMethod()voidsetFunctionIsNormalMethod()voidsetFunctionIsSetterMethod()voidsetFunctionName(Name name)Sets function name, and sets its parent to this node.voidsetFunctionType(int type)voidsetHasRestParameter(boolean hasRestParameter)voidsetIsES6Generator()voidsetIsExpressionClosure(boolean isExpressionClosure)Sets whether this is a 1.8 function closurevoidsetIsGenerator()voidsetLp(int lp)Sets left paren positionvoidsetMemberExprNode(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) {...} If we detect an expression other than a simple Name in the position where a function name was expected, we record that expression here.voidsetParams(java.util.List<AstNode> params)Sets the function parameter list, and sets the parent for each element of the list.voidsetParens(int lp, int rp)Sets both paren positionsvoidsetRequiresActivation()voidsetRp(int rp)Sets right paren positionjava.lang.StringtoSource(int depth)Emits source code for this node.voidvisit(NodeVisitor v)Visits this node, the function name node if supplied, the parameters, and the body.- 
Methods inherited from class org.mozilla.javascript.ast.ScriptNodeaddRegExp, addTemplateLiteral, flattenSymbolTable, getBaseLineno, getCompilerData, getEncodedSource, getEncodedSourceEnd, getEncodedSourceStart, getEndLineno, getFunctionCount, getFunctionNode, getFunctions, getIndexForNameNode, getNextTempName, getParamAndVarConst, getParamAndVarCount, getParamAndVarNames, getParamCount, getParamOrVarName, getRegexpCount, getRegexpFlags, getRegexpString, getSourceName, getSymbols, getTemplateLiteralCount, getTemplateLiteralStrings, isInStrictMode, setBaseLineno, setCompilerData, setEncodedSource, setEncodedSourceBounds, setEncodedSourceEnd, setEncodedSourceStart, setEndLineno, setInStrictMode, setSourceName, setSymbols
 - 
Methods inherited from class org.mozilla.javascript.ast.ScopeaddChildScope, clearParentScope, getChildScopes, getDefiningScope, getParentScope, getStatements, getSymbol, getSymbolTable, getTop, joinScopes, putSymbol, replaceWith, setParentScope, setSymbolTable, setTop, splitScope
 - 
Methods inherited from class org.mozilla.javascript.ast.JumpgetContinue, getDefault, getFinally, getJumpStatement, getLoop, setContinue, setDefault, setFinally, setJumpStatement, setLoop
 - 
Methods inherited from class org.mozilla.javascript.ast.AstNodeaddChild, 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, toSource
 - 
Methods inherited from class org.mozilla.javascript.NodeaddChildAfter, addChildBefore, addChildrenToBack, addChildrenToFront, addChildToBack, addChildToFront, getBigInt, 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, setBigInt, setDouble, setJsDocNode, setLineno, setScope, setString, setType, toString, toStringTree
 
- 
 
- 
- 
- 
Field Detail- 
FUNCTION_STATEMENTpublic static final int FUNCTION_STATEMENT There are three types of functions that can be defined. The first is a function statement. This is a function appearing as a top-level statement (i.e., not nested inside some other statement) in either a script or a function.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. - See Also:
- Constant Field Values
 
 - 
FUNCTION_EXPRESSIONpublic static final int FUNCTION_EXPRESSION - See Also:
- Constant Field Values
 
 - 
FUNCTION_EXPRESSION_STATEMENTpublic static final int FUNCTION_EXPRESSION_STATEMENT - See Also:
- Constant Field Values
 
 - 
ARROW_FUNCTIONpublic static final int ARROW_FUNCTION - See Also:
- Constant Field Values
 
 
- 
 - 
Constructor Detail- 
FunctionNodepublic FunctionNode() 
 - 
FunctionNodepublic FunctionNode(int pos) 
 - 
FunctionNodepublic FunctionNode(int pos, Name name)
 
- 
 - 
Method Detail- 
getFunctionNamepublic Name getFunctionName() Returns function name- Returns:
- function name, nullfor anonymous functions
 
 - 
setFunctionNamepublic void setFunctionName(Name name) Sets function name, and sets its parent to this node.- Parameters:
- name- function name,- nullfor anonymous functions
 
 - 
getNamepublic java.lang.String getName() Returns the function name as a string- Returns:
- the function name, ""if anonymous
 
 - 
getParamspublic java.util.List<AstNode> getParams() Returns the function parameter list- Returns:
- the function parameter list. Returns an immutable empty list if there are no parameters.
 
 - 
setParamspublic void setParams(java.util.List<AstNode> params) Sets the function parameter list, and sets the parent for each element of the list.- Parameters:
- params- the function parameter list, or- nullif no params
 
 - 
addParampublic void addParam(AstNode param) Adds a parameter to the function parameter list. Sets the parent of the param node to this node.- Parameters:
- param- the parameter
- Throws:
- java.lang.IllegalArgumentException- if param is- null
 
 - 
isParampublic boolean isParam(AstNode node) Returns true if the specifiedAstNodenode is a parameter of this Function node. This provides a way during AST traversal to disambiguate the function name node from the parameter nodes.
 - 
getBodypublic AstNode getBody() - Returns:
- the body. Can be nullonly if the AST is malformed.
 
 - 
setBodypublic void setBody(AstNode body) Sets function body, and sets its parent to this node. Also sets the encoded source bounds based on the body bounds. Assumes the function node absolute position has already been set, and the body node's absolute position and length are set.- Parameters:
- body- function body. Its parent is set to this node, and its position is updated to be relative to this node.
- Throws:
- java.lang.IllegalArgumentException- if body is- null
 
 - 
getLppublic int getLp() Returns left paren position, -1 if missing
 - 
setLppublic void setLp(int lp) Sets left paren position
 - 
getRppublic int getRp() Returns right paren position, -1 if missing
 - 
setRppublic void setRp(int rp) Sets right paren position
 - 
setParenspublic void setParens(int lp, int rp)Sets both paren positions
 - 
isExpressionClosurepublic boolean isExpressionClosure() Returns whether this is a 1.8 function closure
 - 
setIsExpressionClosurepublic void setIsExpressionClosure(boolean isExpressionClosure) Sets whether this is a 1.8 function closure
 - 
requiresActivationpublic boolean requiresActivation() Return true if this function requires an Ecma-262 Activation object. The Activation object is implemented byNativeCall, and is fairly expensive to create, so when possible, the interpreter attempts to use a plain call frame instead.- Returns:
- true if this function needs activation. It could be needed if there is a lexical closure, or in a number of other situations.
 
 - 
setRequiresActivationpublic void setRequiresActivation() 
 - 
isGeneratorpublic boolean isGenerator() 
 - 
setIsGeneratorpublic void setIsGenerator() 
 - 
isES6Generatorpublic boolean isES6Generator() 
 - 
setIsES6Generatorpublic void setIsES6Generator() 
 - 
hasRestParameterpublic boolean hasRestParameter() - Overrides:
- hasRestParameterin class- ScriptNode
 
 - 
setHasRestParameterpublic void setHasRestParameter(boolean hasRestParameter) 
 - 
addResumptionPointpublic void addResumptionPoint(Node target) 
 - 
getResumptionPointspublic java.util.List<Node> getResumptionPoints() 
 - 
getLiveLocalspublic java.util.Map<Node,int[]> getLiveLocals() 
 - 
addLiveLocalspublic void addLiveLocals(Node node, int[] locals) 
 - 
addFunctionpublic int addFunction(FunctionNode fnNode) Description copied from class:ScriptNodeAdds aFunctionNodeto the functions table for codegen. Does not set the parent of the node.- Overrides:
- addFunctionin class- ScriptNode
- Returns:
- the index of the function within its parent
 
 - 
getFunctionTypepublic int getFunctionType() Returns the function type (statement, expr, statement expr)
 - 
setFunctionTypepublic void setFunctionType(int type) 
 - 
isMethodpublic boolean isMethod() 
 - 
isGetterMethodpublic boolean isGetterMethod() 
 - 
isSetterMethodpublic boolean isSetterMethod() 
 - 
isNormalMethodpublic boolean isNormalMethod() 
 - 
setFunctionIsGetterMethodpublic void setFunctionIsGetterMethod() 
 - 
setFunctionIsSetterMethodpublic void setFunctionIsSetterMethod() 
 - 
setFunctionIsNormalMethodpublic void setFunctionIsNormalMethod() 
 - 
setMemberExprNodepublic 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) {...} If we detect an expression other than a simple Name in the position where a function name was expected, we record that expression here.This extension is only available by setting the CompilerEnv option "isAllowMemberExprAsFunctionName" in the Parser. 
 - 
getMemberExprNodepublic AstNode getMemberExprNode() 
 - 
toSourcepublic java.lang.String toSource(int depth) Description copied from class:AstNodeEmits source code for this node. Callee is responsible for calling this function recursively on children, incrementing indent as appropriate.Note: if the parser was in error-recovery mode, some AST nodes may have nullchildren that are expected to be non-nullwhen no errors are present. In this situation, the behavior of thetoSourcemethod is undefined:toSourceimplementations may assume that the AST node is error-free, since it is intended to be invoked only at runtime after a successful parse.
 - 
visitpublic void visit(NodeVisitor v) Visits this node, the function name node if supplied, the parameters, and the body. If there is a member-expr node, it is visited last.- Overrides:
- visitin class- ScriptNode
- Parameters:
- v- the object to call with this node and its children
 
 
- 
 
-