All Javascript functions are variable arguments:

1. If you pass less than declared number of arguments, the unassigned  
ones get the undefined value:

function x(a, b)
{
    println(a);
    println(b);
}
x("foo");

will print:
foo
undefined

2. If you pass more than declared number of arguments, you can still  
access them positionally using the "arguments" variable visible within  
the function invocation scope.

function y()
{
    print(arguments[0]);
    print(arguments[1]);
}
y("foo", "bar");

will print:

foo
bar

You can evaluate uneval() on the function from a script (or calling  
toString() on it) and parse the resulting string.

Norris could probably clarify what's the expected value of getArity()  
on compiled functions. You still wouldn't have access to parameter  
names though (which you get with uneval()/toString()).

Attila.

On 2008.02.05., at 15:18, Gavin Camp (gcamp) wrote:

> Hi,
>
> I am trying to embed the Rhino JavaScript engine into a workflow  
> engine.
>
> This workflow engine will use JavaScript function definitions (amongst
> others) as part of its expression language.
> What I want to be able to do is compile JS functions declared in the
> workflow and then call them later during the workflow execution.
>
> I can compile the function using the code:
> Function compiledFunction = cx.compileFunction(scope,
> myFunctionCode.toString(), myFunctionName.getName(), 1, null);
> and I can call this function using the code:
> Object result = compiledFunction .call(cx, scope, compiledFunction,
> parameters.toArray());
>
> The problem is I can't find a way to extract the function signature  
> from
> the compiled function.  I need this so I know how many arguments to  
> call
> with and can then bind it into the workflow.  Looking though the  
> source
> there seems to be an arity function but this always seems to return 0.
>
> Is there anyway to do this?
>
> Regards,
> Gavin




_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino

Reply via email to