summaryrefslogtreecommitdiffstats
path: root/src/snapshot-common.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/snapshot-common.cc')
-rw-r--r--src/snapshot-common.cc52
1 files changed, 37 insertions, 15 deletions
diff --git a/src/snapshot-common.cc b/src/snapshot-common.cc
index 9c66a503..c01baad7 100644
--- a/src/snapshot-common.cc
+++ b/src/snapshot-common.cc
@@ -32,14 +32,15 @@
#include "api.h"
#include "serialize.h"
#include "snapshot.h"
+#include "platform.h"
namespace v8 {
namespace internal {
bool Snapshot::Deserialize(const byte* content, int len) {
- Deserializer des(content, len);
- des.GetFlags();
- return V8::Initialize(&des);
+ SnapshotByteSource source(content, len);
+ Deserializer deserializer(&source);
+ return V8::Initialize(&deserializer);
}
@@ -48,28 +49,49 @@ bool Snapshot::Initialize(const char* snapshot_file) {
int len;
byte* str = ReadBytes(snapshot_file, &len);
if (!str) return false;
- bool result = Deserialize(str, len);
+ Deserialize(str, len);
DeleteArray(str);
- return result;
+ return true;
} else if (size_ > 0) {
- return Deserialize(data_, size_);
+ Deserialize(data_, size_);
+ return true;
}
return false;
}
-bool Snapshot::WriteToFile(const char* snapshot_file) {
- Serializer ser;
- ser.Serialize();
- byte* str;
- int len;
- ser.Finalize(&str, &len);
+class FileByteSink : public SnapshotByteSink {
+ public:
+ explicit FileByteSink(const char* snapshot_file) {
+ fp_ = OS::FOpen(snapshot_file, "wb");
+ if (fp_ == NULL) {
+ PrintF("Unable to write to snapshot file \"%s\"\n", snapshot_file);
+ exit(1);
+ }
+ }
+ virtual ~FileByteSink() {
+ if (fp_ != NULL) {
+ fclose(fp_);
+ }
+ }
+ virtual void Put(int byte, const char* description) {
+ if (fp_ != NULL) {
+ fputc(byte, fp_);
+ }
+ }
- int written = WriteBytes(snapshot_file, str, len);
+ private:
+ FILE* fp_;
+};
- DeleteArray(str);
- return written == len;
+
+bool Snapshot::WriteToFile(const char* snapshot_file) {
+ FileByteSink file(snapshot_file);
+ Serializer ser(&file);
+ ser.Serialize();
+ return true;
}
+
} } // namespace v8::internal