Re: "void 0" blows up the parser

80 views
Skip to first unread message
Message has been deleted
Message has been deleted

Hannes Wallnoefer

unread,
Feb 16, 2012, 5:57:38 AM2/16/12
to mozilla-rhino
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?

Hannes

On Feb 15, 2:32 pm, mitch gorman <mgorman...@gmail.com> wrote:
> i was running the parser on some random JS files, and one of them (the
> Prototype library!) has the following construct:
>
>   clone: function(element, deep) {
>     if (!(element = $(element))) return;
>     var clone = element.cloneNode(deep);
>     clone._prototypeUID = void 0;
>     if (deep) {
>       var descendants = Element.select(clone, '*'),
>           i = descendants.length;
>       while (i--) {
>         descendants[i]._prototypeUID = void 0;
>       }
>     }
>     return Element.extend(clone);
>   }
>
> the parser was not very happy with that "void 0", at all.  it wants to
> treat the "void" as an assignment operator.  i am conflicted on the
> best way to correct this... should i add it as an operator (thereby
> causing every single Token.java "enum" declaration from HOOK, 102, on
> up through LAST_TOKEN, 162, to be modified; AstNode.java's
> operatorNames map would also need to be modified), or is there some
> other way this should be handled?
>
> thanx.
>
> m
Message has been deleted

Hannes Wallnoefer

unread,
Feb 24, 2012, 10:06:03 AM2/24/12
to mozilla-rhino
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

mitch gorman

unread,
Feb 28, 2012, 7:58:29 AM2/28/12
to mozilla-rhino
Thanks very much, Hannes!! =)

On Feb 24, 10:06 am, Hannes Wallnoefer <hann...@gmail.com> wrote:
> Fixed in git master and rhino_1_8 branches.
>
> https://github.com/mozilla/rhino/commit/8ba9619bc53a3a61e9e026ef86b6a...
Reply all
Reply to author
Forward
0 new messages