Fixed in git master and rhino_1_8 branches.
https://github.com/mozilla/rhino/commit/8ba9619bc53a3a61e9e026ef86b6ad698a850d38
Hannes
On Feb 16, 4:29 pm, mitch gorman <
mgorman...@gmail.com> wrote:
> On Feb 16, 5:57 am, Hannes Wallnoefer <
hann...@gmail.com> wrote:
>
> > I can't reproduce this - the function you posted is parsed and
> > compiled properly with all versions of rhino I've tried. How are you
> > invoking the parser, and what version of Rhino are you using?
>
> first of all, thanks for the quick response.
>
> actually, i was somewhat imprecise in my phrasing of the issue
> (although the correct location of the problem *was* visible in the
> stack trace). it's not the parser per se that is blowing up. the
> error occurs when i attempted to do a toSource() on the root node of
> the IR tree i get *back* from the parser. so i guess it's more of a
> representational problem, rather than a parsing problem.
>
> i'm using v1.7R3. i've got a parseJavascript() method that's pretty
> much identical to Glenn Boysko's fromhttp://
groups.google.com/group/mozilla.dev.tech.js-engine.rhino/msg/3...,
> except i used "AstRoot" in place of "ScriptOrFnNode". that's called
> out of main() in my test program like so:
>
> public static void main(String[] args) {
> try {
> File f = new File(args[0]);
> AstRoot root = parseJavascript(f);
> String changes = root.myVisit();
> log.debug("\n\nOutputting:\n" + root.toString());
> log.debug("\n\nOutputting:\n" + root.toStringTree(root));
> log.debug("\n\nOutputting:\n" + root.toSource());
> } catch (Exception e) {
> log.error(e, e);
> }
> }
>
> the output from that is:
>
> 16 Feb 2012 10:11:51.918 0 [main] DEBUG Test:main (Test.java):61:
>
> Outputting:
> SCRIPT [source name: C:\Users\mgorman\Documents\workspace-
> sts-2.8.1.RELEASE\src\fancyapps\source\google2.js] [encoded source
> length: 0] [base line: 1] [end line: 52] 1
> 16 Feb 2012 10:11:51.920 2 [main] DEBUG Test:main (Test.java):62:
>
> Outputting:
> SCRIPT [source name: C:\Users\mgorman\Documents\workspace-
> sts-2.8.1.RELEASE\src\fancyapps\source\google2.js] [encoded source
> length: 0] [base line: 1] [end line: 52] 1
> EXPR_RESULT 2
>
> 16 Feb 2012 10:11:51.925 7 [main] ERROR Test:main (Test.java):78:
> java.lang.IllegalArgumentException: Invalid operator: 126
> java.lang.IllegalArgumentException: Invalid operator: 126
> at org.mozilla.javascript.ast.AstNode.operatorToString(AstNode.java:
> 364)
> at
> org.mozilla.javascript.ast.UnaryExpression.toSource(UnaryExpression.java:
> 165)
> at org.mozilla.javascript.ast.AstNode.printList(AstNode.java:486)
> at org.mozilla.javascript.ast.FunctionCall.toSource(FunctionCall.java:
> 178)
> at org.mozilla.javascript.ast.AstNode.toSource(AstNode.java:330)
> at
> org.mozilla.javascript.ast.InfixExpression.toSource(InfixExpression.java:
> 200)
> at
> org.mozilla.javascript.ast.ExpressionStatement.toSource(ExpressionStatement.java:
> 141)
> at org.mozilla.javascript.ast.Block.toSource(Block.java:83)
> at org.mozilla.javascript.ast.FunctionNode.toSource(FunctionNode.java:
> 433)
> at
> org.mozilla.javascript.ast.ObjectProperty.toSource(ObjectProperty.java:
> 137)
> at org.mozilla.javascript.ast.AstNode.printList(AstNode.java:486)
> at
> org.mozilla.javascript.ast.ObjectLiteral.toSource(ObjectLiteral.java:
> 150)
> at org.mozilla.javascript.ast.AstNode.printList(AstNode.java:486)
> at org.mozilla.javascript.ast.FunctionCall.toSource(FunctionCall.java:
> 178)
> at
> org.mozilla.javascript.ast.ExpressionStatement.toSource(ExpressionStatement.java:
> 141)
> at org.mozilla.javascript.ast.Scope.toSource(Scope.java:275)
> at org.mozilla.javascript.ast.TryStatement.toSource(TryStatement.java:
> 173)
> at org.mozilla.javascript.ast.Block.toSource(Block.java:83)
> at org.mozilla.javascript.ast.FunctionNode.toSource(FunctionNode.java:
> 433)
> at
> org.mozilla.javascript.ast.ParenthesizedExpression.toSource(ParenthesizedExpression.java:
> 98)
> at org.mozilla.javascript.ast.FunctionCall.toSource(FunctionCall.java:
> 175)
> at
> org.mozilla.javascript.ast.ExpressionStatement.toSource(ExpressionStatement.java:
> 141)
> at org.mozilla.javascript.ast.AstRoot.toSource(AstRoot.java:150)
> at org.mozilla.javascript.ast.AstNode.toSource(AstNode.java:330)
> at org.mozilla.javascript.Test.main(Test.java:63)
>
> ...and "operator 126", of course, maps to Token.VOID.
>
> (i *have* tweaked a couple rhino source files, to customize the code
> for my specific application, but i believe all the line numbers shown
> above should be pointing to the same lines as in the unmodified
> source. my changes are pretty much at the bottoms of the affected
> files.)
>
> (tangentially, i also find it interesting that toString() and
> toStringTree() each take about a millisecond to execute, but
> toSource() has already taken about 5 milliseconds by the time it blows
> up, meaning it'd take even longer if it had run to completion.
> certainly not an outrageously long time to execute, but by comparison
> to the *other* two methods...)
>
> m