OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 25 matching lines...) Expand all Loading... |
36 namespace v8 { | 36 namespace v8 { |
37 namespace internal { | 37 namespace internal { |
38 | 38 |
39 bool Snapshot::Deserialize(const byte* content, int len) { | 39 bool Snapshot::Deserialize(const byte* content, int len) { |
40 Deserializer des(content, len); | 40 Deserializer des(content, len); |
41 des.GetFlags(); | 41 des.GetFlags(); |
42 return V8::Initialize(&des); | 42 return V8::Initialize(&des); |
43 } | 43 } |
44 | 44 |
45 | 45 |
| 46 bool Snapshot::Deserialize2(const byte* content, int len) { |
| 47 SnapshotByteSource source(content, len); |
| 48 Deserializer2 deserializer(&source); |
| 49 return V8::Initialize(&deserializer); |
| 50 } |
| 51 |
| 52 |
46 bool Snapshot::Initialize(const char* snapshot_file) { | 53 bool Snapshot::Initialize(const char* snapshot_file) { |
47 if (snapshot_file) { | 54 if (snapshot_file) { |
48 int len; | 55 int len; |
49 byte* str = ReadBytes(snapshot_file, &len); | 56 byte* str = ReadBytes(snapshot_file, &len); |
50 if (!str) return false; | 57 if (!str) return false; |
51 bool result = Deserialize(str, len); | 58 bool result = Deserialize(str, len); |
52 DeleteArray(str); | 59 DeleteArray(str); |
53 return result; | 60 return result; |
54 } else if (size_ > 0) { | 61 } else if (size_ > 0) { |
55 return Deserialize(data_, size_); | 62 return Deserialize(data_, size_); |
56 } | 63 } |
57 return false; | 64 return false; |
58 } | 65 } |
59 | 66 |
60 | 67 |
| 68 bool Snapshot::Initialize2(const char* snapshot_file) { |
| 69 if (snapshot_file) { |
| 70 int len; |
| 71 byte* str = ReadBytes(snapshot_file, &len); |
| 72 if (!str) return false; |
| 73 Deserialize2(str, len); |
| 74 DeleteArray(str); |
| 75 } else if (size_ > 0) { |
| 76 Deserialize2(data_, size_); |
| 77 } |
| 78 return true; |
| 79 } |
| 80 |
| 81 |
61 bool Snapshot::WriteToFile(const char* snapshot_file) { | 82 bool Snapshot::WriteToFile(const char* snapshot_file) { |
62 Serializer ser; | 83 Serializer ser; |
63 ser.Serialize(); | 84 ser.Serialize(); |
64 byte* str; | 85 byte* str; |
65 int len; | 86 int len; |
66 ser.Finalize(&str, &len); | 87 ser.Finalize(&str, &len); |
67 | 88 |
68 int written = WriteBytes(snapshot_file, str, len); | 89 int written = WriteBytes(snapshot_file, str, len); |
69 | 90 |
70 DeleteArray(str); | 91 DeleteArray(str); |
71 return written == len; | 92 return written == len; |
72 } | 93 } |
73 | 94 |
74 | 95 |
| 96 class FileByteSink : public SnapshotByteSink { |
| 97 public: |
| 98 explicit FileByteSink(const char* snapshot_file) { |
| 99 fp_ = fopen(snapshot_file, "wb"); |
| 100 if (fp_ == NULL) { |
| 101 PrintF("Unable to write to snapshot file \"%s\"\n", snapshot_file); |
| 102 exit(1); |
| 103 } |
| 104 } |
| 105 virtual ~FileByteSink() { |
| 106 if (fp_ != NULL) { |
| 107 fclose(fp_); |
| 108 } |
| 109 } |
| 110 virtual void Put(int byte, const char* description) { |
| 111 if (fp_ != NULL) { |
| 112 fputc(byte, fp_); |
| 113 } |
| 114 } |
| 115 |
| 116 private: |
| 117 FILE* fp_; |
| 118 }; |
| 119 |
| 120 |
| 121 bool Snapshot::WriteToFile2(const char* snapshot_file) { |
| 122 FileByteSink file(snapshot_file); |
| 123 Serializer2 ser(&file); |
| 124 ser.Serialize(); |
| 125 return true; |
| 126 } |
| 127 |
| 128 |
| 129 |
75 } } // namespace v8::internal | 130 } } // namespace v8::internal |
OLD | NEW |