blob: 217a0f6894f23af3cb50933d5836ac4246897971 [file] [log] [blame]
--- jsshell.h
+++ jsshell.h
@@ -45,30 +49,30 @@ class AutoCloseFile
bool success = true;
if (f_ && f_ != stdin && f_ != stdout && f_ != stderr)
success = !fclose(f_);
f_ = nullptr;
return success;
}
};
-// Reference counted file.
-struct RCFile {
+struct File final : public RefCounted<File> {
FILE* fp;
- uint32_t numRefs;
- RCFile() : fp(nullptr), numRefs(0) {}
- RCFile(FILE* fp) : fp(fp), numRefs(0) {}
+ File() : fp(nullptr) {}
+ File(FILE* fp) : fp(fp) {}
+ ~File() {
+ this->close();
+ }
- void acquire() { numRefs++; }
-
- // Starts out with a ref count of zero.
- static RCFile* create(JSContext* cx, const char* filename, const char* mode);
+ static already_AddRefed<File>
+ create(JSContext* cx, const char* filename, const char* mode);
void close();
bool isOpen() const { return fp; }
- bool release();
};
+using RCFile = RefPtr<File>;
+
} /* namespace shell */
} /* namespace js */
#endif