ZeParser icon indicating copy to clipboard operation
ZeParser copied to clipboard

Parser State Leakage for `switch` and `try` Statements

Open ghost opened this issue 14 years ago • 1 comments

This example is valid; however, because the parser sets the stack.parsedSwitchDefault property for the first switch and doesn't reset it before parsing the second switch, it chokes when parsing the default: bar; clause.

switch(x){ default: foo; break; case x: break; } switch(y){ default: bar; break; case y: break; }

This example is invalid, but the parser doesn't reset the stack.tryHasCatchOrFinally property after parsing the first try...catch block. As such, the example parses with no errors.

try { foo(); } catch (e) {} try { bar(); }

I've tentatively patched this by deleting the parsedSwitchDefault and tryHasCatchOrFinally properties after each statement is parsed, but I'm not sure if this would impact the AST in any way. The unit tests pass, but I'm still not fully certain if this is safe to apply. What do you think?

ghost avatar Dec 24 '11 13:12 ghost

Meh. Probably shouldn't be doing these things at midnight. I'll try to check it out tomorrow.

pvdz avatar Feb 26 '12 22:02 pvdz