Status: New
Owner: ----

New issue 1856 by [email protected]: "Uncaught SyntaxError: Unexpected token if" incorrectly thrown
http://code.google.com/p/v8/issues/detail?id=1856

The v8 VM (on Chrome 15.0.874.121 m) is having some weird parsing issues related to the following function (originally generated by the ugify compactor):

var someFn = function mP(a) {
    var b = 0;
    var k = 0;
    var j = 0;
    if (b === 3 || b === 4)
        do {
            k = 3;
        } while (false);
    else if (b === 2) {
        return j;
    }
    return a;
};

When we run this function with node.js (v0.6.5) the code executes as expected. However, if we now add some more completely unrelated lines at the bottom of the function:

var someFn = function mP(a) {
    var b = 0;
    var k = 0;
    var j = 0;
    if (b === 3 || b === 4)
        do {
            k = 3;
        } while (false);
    else if (b === 2) {
        return j;
    }
    var vr1 = this.LongVariableName1;
    var vr2 = this.LongVariableName2;
    var vr3 = this.LongVariableName3;
    var vr4 = this.LongVariableName4;
    var vr5 = this.LongVariableName5;
    var vr6 = this.LongVariableName6;
    var vr7 = this.LongVariableName7;
    var vr8 = this.LongVariableName8;
    var vr9 = this.LongVariableName9;
    var vr10 = this.LongVariableName10;
    var vr11 = this.LongVariableName11;
    var vr12 = this.LongVariableName12;
    return a;
};

we get the following error:

v8-test1.js:36
    else if (b === 2) {
    ^^^^

node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
              ^
SyntaxError: Unexpected token else
    at Module._compile (module.js:427:25)
    at Object..js (module.js:450:10)
    at Module.load (module.js:351:31)
    at Function._load (module.js:310:12)
    at Array.0 (module.js:470:10)
    at EventEmitter._tickCallback (node.js:192:40)

And in chrome:

...
    else if (b === 2) {
v8-test1.html:45 Uncaught SyntaxError: Unexpected token if
        return j;
    }
...


I have attached files for Chrome and node.js where you should see the error (look in the console) in v8-test1 and no error in v8-test2.

Note that none of the other major browsers (tested in FF8, Safari, IE) have this issue.

Attachments:
        v8-test1.html  1.4 KB
        v8-test2.html  1002 bytes
        v8-test1.js  1.1 KB
        v8-test2.js  679 bytes

--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to