// Constructor. internal FunctionScope(ScriptObject parent, JFormalParams fparams, Object thisObject, Object[] args) : base(parent, new JSObject()) { this.thisObject = thisObject; if(fparams != null) { JExprListElem param = fparams.first; int posn = 0; while(param != null && posn < args.Length) { ((IVariableAccess)this).SetVariable (Convert.ToString(param.name), args[posn++]); param = param.next; } while(param != null) { ((IVariableAccess)this).SetVariable (Convert.ToString(param.name), null); param = param.next; } } }
// Parse a function declaration or expression. private JNode Function(bool needIdentifier) { Context save = tokenInfo.MakeCopy(); String name = null; JFormalParams fparams; JNode body; // Skip the "function" keyword. NextToken(); // Get the function name. if(token == JSToken.Identifier) { name = scanner.GetIdentifierName(); NextToken(); } else if(needIdentifier) { SyntaxError("function name expected"); } // Parse the formal parameter list. fparams = new JFormalParams(tokenInfo.MakeCopy()); Expect(JSToken.LeftParen, "`(' expected"); while(token == JSToken.Identifier) { Support.AddExprToList (fparams, scanner.GetIdentifierName(), null); NextToken(); if(token == JSToken.Comma) { NextToken(); } else if(token != JSToken.RightParen) { SyntaxError("`)' or ',' expected"); } } fparams.context = Context.BuildRange (fparams.context, tokenInfo); Expect(JSToken.RightParen, "`)' expected"); // Parse the function body. body = Block(); // Build the final function definition node. return new JFunction(Context.BuildRange(save, body.context), name, fparams, body); }
public JFunction(Context context, String name, JFormalParams fparams, JNode body) : base(context) { this.kind__ = KIND; this.name = name; this.fparams = fparams; this.body = body; }