Closed Bug 22243 Opened 26 years ago Closed 26 years ago

Illegally constructed catchguards should throw an exception

Categories

(Core :: JavaScript Engine, defect, P3)

x86
All
defect

Tracking

()

VERIFIED FIXED

People

(Reporter: rginda, Assigned: shaver)

References

()

Details

(Keywords: js1.5, Whiteboard: fix awaiting review [Jan 16])

Attachments

(2 files)

try { throw "foo"; } catch (e) { foo(); } catch (e if true) bar(); } Should throw an exception because the catchall comes before the guarded catch
Whiteboard: [JS15]
Status: NEW → ASSIGNED
This used to work -- I'll take a look. How long do I have? (mccabe was involved in the original catchguard-ectomy, maybe he recalls what happened to this logic?)
The sooner the better, looking for a 1.5 final in less than two weeks.
Keywords: js1.5
Whiteboard: [JS15]
Removing [JS15] from Status Summary, putting js1.5 in new Keyword field :-)
Whiteboard: fix awaiting review [Jan 16]
How about: js> load('/tmp/catch.js'); /tmp/catch.js:5: SyntaxError: conditional catch after unconditional catch: /tmp/catch.js:5: } catch (e if true) { /tmp/catch.js:5: ...........^ js> I'm _tempted_ to make it a warning rather than an error, but not incredibly so. I'll attach the patch (against JS15_20000111_BRANCH), which includes the fix for 22245 previously mailed privately to rginda and brendan.
I applied the patch (with some effort - looks like your diff is against stuff that isn't in the tree!) and looks like it does the trick. js> try { a + b } catch (a) { } catch (b if 4) { } 8: conditional catch after unconditional catch: 8: try { a + b } catch (a) { } catch (b if 4) { } 8: ...................................^ JS accepts multiple unconditional catchguards without complaint: js> try { a + b } catch (a) { } catch (b) { } This is a similar case - it should probably be an error as well. r=mccabe.
My patch is against the branch -- were you working with the tip? I'll make the change you mention (any catch after a unconditional catch is an error), and repost.
js> try { a + b } catch (a) { } catch (b if 4) { } 2: catch after unconditional catch: 2: try { a + b } catch (a) { } catch (b if 4) { } 2: ............................^ js> mccabe, did you review against 22245 as well?
r=brendan@mozilla.org (with fix for comment nit that I whined to shaver about privately). /be
Shaver, you wanna check this into JS15_20000111_BRANCH and I'll land it? I want to land stuff today. /be
Status: ASSIGNED → RESOLVED
Closed: 26 years ago
Resolution: --- → FIXED
I landed the branch with shaver's fix to this bug. Mail from shaver reminds me: isn't 22245 INVALID due to a bogus testcase? /be
Exceptions/catchguard-003-n.js added to cover mccabe's catch (e) {} catch (e) {} case.
Marking Verified.
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: