Closed Bug 779347 Opened 13 years ago Closed 13 years ago

wrap OpenFile and ReadCompleteFile in a nice RAII interface

Categories

(Core :: JavaScript Engine, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla17

People

(Reporter: Benjamin, Assigned: Benjamin)

Details

Attachments

(1 file)

(Bug 779038 followup) This patch provides a class that automatically handles the closing (or not closing of stdin) of FILE* jsapi creates.
Attached patch add FileWrapperSplinter Review
Assignee: general → bpeterson
Attachment #647749 - Flags: review?(jimb)
Comment on attachment 647749 [details] [diff] [review] add FileWrapper Review of attachment 647749 [details] [diff] [review]: ----------------------------------------------------------------- Hurrah! Some comments; see what you think. ::: js/src/jsapi.cpp @@ +5057,5 @@ > > return true; > } > > +class FileWrapper It's my impression that classes intended mostly to guarantee cleanup from some local scope get names beginning with "Auto". @@ +5085,5 @@ > * Open a source file for reading. Supports "-" and NULL to mean stdin. The > * return value must be fclosed unless it is stdin. > */ > +static bool > +OpenFile(JSContext *cx, const char *filename, FileWrapper &fw) I think OpenFile would work nicely as a member function of FileWrapper. @@ +5669,5 @@ > + { > + FileWrapper fw; > + if (!OpenFile(cx, filename, fw)) > + return NULL; > + bool ok = fw.readAll(cx, buffer); There's no need for 'ok' any more, since the fclose is gone.
Attachment #647749 - Flags: review?(jimb) → review+
I - zapped ok - renamed FileWrapper -> AutoFile - OpenFile -> AutoFile::open https://hg.mozilla.org/integration/mozilla-inbound/rev/162b401d8774
Yeah, that's the stuff.
Status: NEW → RESOLVED
Closed: 13 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla17
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: