wrap OpenFile and ReadCompleteFile in a nice RAII interface

RESOLVED FIXED in mozilla17

Status

()

Core
JavaScript Engine
RESOLVED FIXED
5 years ago
5 years ago

People

(Reporter: Benjamin, Assigned: Benjamin)

Tracking

unspecified
mozilla17
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

(Assignee)

Description

5 years ago
(Bug 779038 followup)

This patch provides a class that automatically handles the closing (or not closing of stdin) of FILE* jsapi creates.
(Assignee)

Comment 1

5 years ago
Created attachment 647749 [details] [diff] [review]
add FileWrapper
Assignee: general → bpeterson
Attachment #647749 - Flags: review?(jimb)

Comment 2

5 years ago
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+
(Assignee)

Comment 3

5 years ago
I
- zapped ok
- renamed FileWrapper -> AutoFile
- OpenFile -> AutoFile::open

https://hg.mozilla.org/integration/mozilla-inbound/rev/162b401d8774

Comment 4

5 years ago
Yeah, that's the stuff.

Comment 5

5 years ago
https://hg.mozilla.org/mozilla-central/rev/162b401d8774
Status: NEW → RESOLVED
Last Resolved: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla17
You need to log in before you can comment on or make changes to this bug.