test: remove obsolete harmony flags
[platform/upstream/nodejs.git] / deps / v8 / src / snapshot-source-sink.cc
1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5
6 #include "src/snapshot-source-sink.h"
7
8 #include "src/base/logging.h"
9 #include "src/handles-inl.h"
10 #include "src/serialize.h"  // for SerializerDeserializer::nop() in AtEOF()
11
12
13 namespace v8 {
14 namespace internal {
15
16 int32_t SnapshotByteSource::GetUnalignedInt() {
17   DCHECK(position_ < length_);  // Require at least one byte left.
18   int32_t answer = data_[position_];
19   answer |= data_[position_ + 1] << 8;
20   answer |= data_[position_ + 2] << 16;
21   answer |= data_[position_ + 3] << 24;
22   return answer;
23 }
24
25
26 void SnapshotByteSource::CopyRaw(byte* to, int number_of_bytes) {
27   MemCopy(to, data_ + position_, number_of_bytes);
28   position_ += number_of_bytes;
29 }
30
31
32 void SnapshotByteSink::PutInt(uintptr_t integer, const char* description) {
33   DCHECK(integer < 1 << 30);
34   integer <<= 2;
35   int bytes = 1;
36   if (integer > 0xff) bytes = 2;
37   if (integer > 0xffff) bytes = 3;
38   if (integer > 0xffffff) bytes = 4;
39   integer |= (bytes - 1);
40   Put(static_cast<int>(integer & 0xff), "IntPart1");
41   if (bytes > 1) Put(static_cast<int>((integer >> 8) & 0xff), "IntPart2");
42   if (bytes > 2) Put(static_cast<int>((integer >> 16) & 0xff), "IntPart3");
43   if (bytes > 3) Put(static_cast<int>((integer >> 24) & 0xff), "IntPart4");
44 }
45
46
47 void SnapshotByteSink::PutRaw(const byte* data, int number_of_bytes,
48                               const char* description) {
49   data_.AddAll(Vector<byte>(const_cast<byte*>(data), number_of_bytes));
50 }
51
52
53 bool SnapshotByteSource::AtEOF() {
54   if (0u + length_ - position_ > 2 * sizeof(uint32_t)) return false;
55   for (int x = position_; x < length_; x++) {
56     if (data_[x] != SerializerDeserializer::nop()) return false;
57   }
58   return true;
59 }
60
61
62 bool SnapshotByteSource::GetBlob(const byte** data, int* number_of_bytes) {
63   int size = GetInt();
64   *number_of_bytes = size;
65
66   if (position_ + size <= length_) {
67     *data = &data_[position_];
68     Advance(size);
69     return true;
70   } else {
71     Advance(length_ - position_);  // proceed until end.
72     return false;
73   }
74 }
75
76 }  // namespace v8::internal
77 }  // namespace v8