If you have a Script object, you can use
Context.getDebuggableView(script) to convert it into a
org.mozilla.javascript.debug.DebuggableScript. You can then use
getFunctionCount() and getFunction() on it to iterate over functions
(getFunction() also returns DebuggableScript, so you can iterate over
their nested functions too, if they have any), and use isFunction()
and getFunctionName() to get function names. You won't get the
function bodies, but you can then use getLineNumbers() to get at that
-- it obviously only works if your source code is formatted in a
commonsensical way.
Lacking that, you'll have to actually run the script, then fish out
the function objects from the top-level scope and separately evaluate
toSource() on them...
Attila.
On 2008.02.15., at 11:13, [EMAIL PROTECTED] wrote:
> Hello,
>
> I'm new to rhino and have a question:
>
> I have a script source containing many functions, for example:
>
> function sum(a, b) {
> return a + b;
> }
>
> function minus(a, b) {
> return a - b;
> }
>
> function multiply(a, b) {
> return a * b;
> }
>
> and I need to parse it and get each function individually. Something
> like that:
>
> getFunctionNames() : return an ArrayList containing the function
> names;
>
> getFunctionBody(String functionName): returns the body of the function
> (i.e. the implementation).
>
> Is it possible to do with Rhino? Or I need to use something like
> javaCC to create a parser to js?
>
> Thanks in advance
>
> Carlos Augusto Grahl
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino