1999-06-11 00:21:26 +00:00
|
|
|
class FunctionNode extends ExpressionNode {
|
|
|
|
|
1999-06-15 00:57:05 +00:00
|
|
|
FunctionNode(JSIdentifier aName, ControlNodeGroup aBody, ExpressionNode parameterList)
|
1999-06-11 00:21:26 +00:00
|
|
|
{
|
|
|
|
fn = new NativeFunction(aBody.getHead());
|
|
|
|
name = aName;
|
1999-06-15 00:57:05 +00:00
|
|
|
if (parameterList != null) {
|
|
|
|
if (parameterList instanceof BinaryNode)
|
|
|
|
buildParameterVector((BinaryNode)parameterList);
|
|
|
|
else
|
|
|
|
fn.parameters.addElement(parameterList);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void buildParameterVector(BinaryNode x)
|
|
|
|
{
|
|
|
|
if (x.left instanceof BinaryNode) {
|
|
|
|
buildParameterVector((BinaryNode)(x.left));
|
|
|
|
fn.parameters.addElement(x.right);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fn.parameters.addElement(x.left);
|
|
|
|
fn.parameters.addElement(x.right);
|
|
|
|
}
|
1999-06-11 00:21:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
JSValue eval(Environment theEnv)
|
|
|
|
{
|
|
|
|
theEnv.scope.putProp(theEnv, name, fn);
|
|
|
|
return fn;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSString name;
|
|
|
|
NativeFunction fn;
|
|
|
|
|
|
|
|
}
|