C# Class Rhino.Ast.FunctionNode

A JavaScript function declaration or expression.

Node type is Rhino.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] ) Expression
In this case the FunctionNode node will have no body but will have an expression.
Inheritance: ScriptNode
Show file Open project: hazzik/Rhino.Net Class Usage Examples

Public Methods

Method Description
AddFunction ( Rhino fnNode ) : int
AddLiveLocals ( Node node, int locals ) : void
AddParam ( AstNode param ) : void

Adds a parameter to the function parameter list.

Adds a parameter to the function parameter list. Sets the parent of the param node to this node.

AddResumptionPoint ( Node target ) : void
FunctionNode ( ) : System.Collections.Generic
FunctionNode ( int pos ) : System.Collections.Generic
FunctionNode ( int pos, Name name ) : System.Collections.Generic
GetBody ( ) : AstNode

Returns function body.

Returns function body. Normally a Block , but can be a plain AstNode if it's a function closure.

GetFunctionName ( ) : Name

Returns function name

GetFunctionType ( ) : int

Returns the function type (statement, expr, statement expr)

GetLiveLocals ( ) : int[]>.IDictionary
GetLp ( ) : int

Returns left paren position, -1 if missing

GetMemberExprNode ( ) : AstNode
GetName ( ) : string

Returns the function name as a string

GetParams ( ) : IList

Returns the function parameter list

GetResumptionPoints ( ) : IList
GetRp ( ) : int

Returns right paren position, -1 if missing

IsExpressionClosure ( ) : bool

Returns whether this is a 1.8 function closure

IsGenerator ( ) : bool
IsGetter ( ) : bool
IsGetterOrSetter ( ) : bool
IsParam ( AstNode node ) : bool

Returns true if the specified 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.

IsSetter ( ) : bool
RequiresActivation ( ) : bool

Return true if this function requires an Ecma-262 Activation object.

Return true if this function requires an Ecma-262 Activation object. The Activation object is implemented by Rhino.NativeCall , and is fairly expensive to create, so when possible, the interpreter attempts to use a plain call frame instead.

SetBody ( AstNode body ) : void

Sets function body, and sets its parent to this node.

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.

SetFunctionIsGetter ( ) : void
SetFunctionIsSetter ( ) : void
SetFunctionName ( Name name ) : void

Sets function name, and sets its parent to this node.

Sets function name, and sets its parent to this node.

SetFunctionType ( int type ) : void
SetIsExpressionClosure ( bool isExpressionClosure ) : void

Sets whether this is a 1.8 function closure

SetIsGenerator ( ) : void
SetLp ( int lp ) : void

Sets left paren position

SetMemberExprNode ( AstNode node ) : void

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.

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.

SetParams ( IList @params ) : void

Sets the function parameter list, and sets the parent for each element of the list.

Sets the function parameter list, and sets the parent for each element of the list.

SetParens ( int lp, int rp ) : void

Sets both paren positions

SetRequiresActivation ( ) : void
SetRp ( int rp ) : void

Sets right paren position

ToSource ( int depth ) : string
Visit ( NodeVisitor v ) : void

Visits this node, the function name node if supplied, the parameters, and the body.

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.

Method Details

AddFunction() public method

public AddFunction ( Rhino fnNode ) : int
fnNode Rhino
return int

AddLiveLocals() public method

public AddLiveLocals ( Node node, int locals ) : void
node Node
locals int
return void

AddParam() public method

Adds a parameter to the function parameter list.
Adds a parameter to the function parameter list. Sets the parent of the param node to this node.
/// if param is /// null ///
public AddParam ( AstNode param ) : void
param AstNode the parameter
return void

AddResumptionPoint() public method

public AddResumptionPoint ( Node target ) : void
target Node
return void

FunctionNode() public method

public FunctionNode ( ) : System.Collections.Generic
return System.Collections.Generic

FunctionNode() public method

public FunctionNode ( int pos ) : System.Collections.Generic
pos int
return System.Collections.Generic

FunctionNode() public method

public FunctionNode ( int pos, Name name ) : System.Collections.Generic
pos int
name Name
return System.Collections.Generic

GetBody() public method

Returns function body.
Returns function body. Normally a Block , but can be a plain AstNode if it's a function closure.
public GetBody ( ) : AstNode
return AstNode

GetFunctionName() public method

Returns function name
public GetFunctionName ( ) : Name
return Name

GetFunctionType() public method

Returns the function type (statement, expr, statement expr)
public GetFunctionType ( ) : int
return int

GetLiveLocals() public method

public GetLiveLocals ( ) : int[]>.IDictionary
return int[]>.IDictionary

GetLp() public method

Returns left paren position, -1 if missing
public GetLp ( ) : int
return int

GetMemberExprNode() public method

public GetMemberExprNode ( ) : AstNode
return AstNode

GetName() public method

Returns the function name as a string
public GetName ( ) : string
return string

GetParams() public method

Returns the function parameter list
public GetParams ( ) : IList
return IList

GetResumptionPoints() public method

public GetResumptionPoints ( ) : IList
return IList

GetRp() public method

Returns right paren position, -1 if missing
public GetRp ( ) : int
return int

IsExpressionClosure() public method

Returns whether this is a 1.8 function closure
public IsExpressionClosure ( ) : bool
return bool

IsGenerator() public method

public IsGenerator ( ) : bool
return bool

IsGetter() public method

public IsGetter ( ) : bool
return bool

IsGetterOrSetter() public method

public IsGetterOrSetter ( ) : bool
return bool

IsParam() public method

Returns true if the specified 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 IsParam ( AstNode node ) : bool
node AstNode
return bool

IsSetter() public method

public IsSetter ( ) : bool
return bool

RequiresActivation() public method

Return true if this function requires an Ecma-262 Activation object.
Return true if this function requires an Ecma-262 Activation object. The Activation object is implemented by Rhino.NativeCall , and is fairly expensive to create, so when possible, the interpreter attempts to use a plain call frame instead.
public RequiresActivation ( ) : bool
return bool

SetBody() public method

Sets function body, and sets its parent to this node.
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.

/// if body is /// null ///
public SetBody ( AstNode body ) : void
body AstNode /// function body. Its parent is set to this node, and its /// position is updated to be relative to this node. ///
return void

SetFunctionIsGetter() public method

public SetFunctionIsGetter ( ) : void
return void

SetFunctionIsSetter() public method

public SetFunctionIsSetter ( ) : void
return void

SetFunctionName() public method

Sets function name, and sets its parent to this node.
Sets function name, and sets its parent to this node.
public SetFunctionName ( Name name ) : void
name Name /// function name, /// null /// for anonymous functions ///
return void

SetFunctionType() public method

public SetFunctionType ( int type ) : void
type int
return void

SetIsExpressionClosure() public method

Sets whether this is a 1.8 function closure
public SetIsExpressionClosure ( bool isExpressionClosure ) : void
isExpressionClosure bool
return void

SetIsGenerator() public method

public SetIsGenerator ( ) : void
return void

SetLp() public method

Sets left paren position
public SetLp ( int lp ) : void
lp int
return void

SetMemberExprNode() public method

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.
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.

public SetMemberExprNode ( AstNode node ) : void
node AstNode
return void

SetParams() public method

Sets the function parameter list, and sets the parent for each element of the list.
Sets the function parameter list, and sets the parent for each element of the list.
public SetParams ( IList @params ) : void
@params IList
return void

SetParens() public method

Sets both paren positions
public SetParens ( int lp, int rp ) : void
lp int
rp int
return void

SetRequiresActivation() public method

public SetRequiresActivation ( ) : void
return void

SetRp() public method

Sets right paren position
public SetRp ( int rp ) : void
rp int
return void

ToSource() public method

public ToSource ( int depth ) : string
depth int
return string

Visit() public method

Visits this node, the function name node if supplied, the parameters, and the body.
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.
public Visit ( NodeVisitor v ) : void
v NodeVisitor
return void