v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
snapshot-source-sink.cc
Go to the documentation of this file.
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
6
7#include <vector>
8
9#include "src/base/logging.h"
12
13namespace v8 {
14namespace internal {
15
16void SnapshotByteSink::PutN(int number_of_bytes, const uint8_t v,
17 const char* description) {
18 data_.insert(data_.end(), number_of_bytes, v);
19}
20
21void SnapshotByteSink::PutUint30(uint32_t integer, const char* description) {
22 CHECK_LT(integer, 1UL << 30);
23 integer <<= 2;
24 int bytes = 1;
25 if (integer > 0xFF) bytes = 2;
26 if (integer > 0xFFFF) bytes = 3;
27 if (integer > 0xFFFFFF) bytes = 4;
28 integer |= (bytes - 1);
29 Put(static_cast<uint8_t>(integer & 0xFF), "IntPart1");
30 if (bytes > 1) Put(static_cast<uint8_t>((integer >> 8) & 0xFF), "IntPart2");
31 if (bytes > 2) Put(static_cast<uint8_t>((integer >> 16) & 0xFF), "IntPart3");
32 if (bytes > 3) Put(static_cast<uint8_t>((integer >> 24) & 0xFF), "IntPart4");
33}
34
35void SnapshotByteSink::PutRaw(const uint8_t* data, int number_of_bytes,
36 const char* description) {
37#ifdef MEMORY_SANITIZER
38 __msan_check_mem_is_initialized(data, number_of_bytes);
39#endif
40 data_.insert(data_.end(), data, data + number_of_bytes);
41}
42
44 data_.insert(data_.end(), other.data_.begin(), other.data_.end());
45}
46
47int SnapshotByteSource::GetBlob(const uint8_t** data) {
48 int size = GetUint30();
49 CHECK_LE(position_ + size, length_);
50 *data = &data_[position_];
51 Advance(size);
52 return size;
53}
54} // namespace internal
55} // namespace v8
void PutN(int number_of_bytes, const uint8_t v, const char *description)
void Append(const SnapshotByteSink &other)
void PutUint30(uint32_t integer, const char *description)
void PutRaw(const uint8_t *data, int number_of_bytes, const char *description)
void Put(uint8_t b, const char *description)
#define CHECK_LT(lhs, rhs)
#define CHECK_LE(lhs, rhs)