Closed Bug 510360 Opened 16 years ago Closed 15 years ago

early return in json.cpp might skip necessary postamble

Categories

(Core :: JavaScript Engine, defect)

x86
Linux
defect
Not set
normal

Tracking

()

RESOLVED FIXED
Tracking Status
status1.9.2 --- beta4-fixed

People

(Reporter: luke, Assigned: luke)

Details

(Whiteboard: fixed-in-tracemonkey)

Attachments

(1 file)

In the big loop in the function 'JO' in json.cpp, it appears that most of the code funnels through a postamble after the loop that closes an iterator. However, there are a few early returns in the loop that skip this close. I'm not well versed in json or iterators, so perhaps there is a reason these early exits are fine. If the reason isn't obvious, perhaps it could be added as a comment.
The GC will take care of the iterator, no js_CloseIterator required. It helps to promptly free memory, so worth doing, but control flow is a bit fussy already in JO. To make it fussier but consistent, all those early return JS_FALSE; statements should be breaks after if (!ok) tests, where ok = the condition after the ! in the existing condition, e.g. ok = scx->replacer->getProperty(cx, key, &newKey); if (!ok) break; /be
Alternatively, for simpler code, get rid of the ok setting and if (!ok) break; jazz, and the if (!ok) return JS_FALSE; after the conditional js_CloseIterator, and just return early on error. /be
This patch normalizes the control flow so the iterators are always closed. Shorter code too.
Assignee: general → lw
Status: NEW → ASSIGNED
Attachment #394668 - Flags: review?
You have a patch on this bug that is flagged for 'review?' and not assigned to any reviewer. If you want the patch to be reviewed please assign a reviewer. Thanks
Attachment #394668 - Flags: review? → review+
Whiteboard: fixed-in-tracemonkey
Status: ASSIGNED → RESOLVED
Closed: 15 years ago
Flags: wanted1.9.2+
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: