/src/node/src/aliased_buffer-inl.h
Line | Count | Source (jump to first uncovered line) |
1 | | #ifndef SRC_ALIASED_BUFFER_INL_H_ |
2 | | #define SRC_ALIASED_BUFFER_INL_H_ |
3 | | |
4 | | #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS |
5 | | |
6 | | #include "aliased_buffer.h" |
7 | | #include "util-inl.h" |
8 | | |
9 | | namespace node { |
10 | | |
11 | | typedef size_t AliasedBufferIndex; |
12 | | |
13 | | template <typename NativeT, typename V8T> |
14 | | AliasedBufferBase<NativeT, V8T>::AliasedBufferBase( |
15 | | v8::Isolate* isolate, const size_t count, const AliasedBufferIndex* index) |
16 | 2.29M | : isolate_(isolate), count_(count), byte_offset_(0), index_(index) { |
17 | 2.29M | CHECK_GT(count, 0); |
18 | 2.29M | if (index != nullptr) { |
19 | | // Will be deserialized later. |
20 | 0 | return; |
21 | 0 | } |
22 | 2.29M | const v8::HandleScope handle_scope(isolate_); |
23 | 2.29M | const size_t size_in_bytes = |
24 | 2.29M | MultiplyWithOverflowCheck(sizeof(NativeT), count); |
25 | | |
26 | | // allocate v8 ArrayBuffer |
27 | 2.29M | v8::Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(isolate_, size_in_bytes); |
28 | 2.29M | buffer_ = static_cast<NativeT*>(ab->Data()); |
29 | | |
30 | | // allocate v8 TypedArray |
31 | 2.29M | v8::Local<V8T> js_array = V8T::New(ab, byte_offset_, count); |
32 | 2.29M | js_array_ = v8::Global<V8T>(isolate, js_array); |
33 | 2.29M | } node::AliasedBufferBase<int, v8::Int32Array>::AliasedBufferBase(v8::Isolate*, unsigned long, unsigned long const*) Line | Count | Source | 16 | 381k | : isolate_(isolate), count_(count), byte_offset_(0), index_(index) { | 17 | 381k | CHECK_GT(count, 0); | 18 | 381k | if (index != nullptr) { | 19 | | // Will be deserialized later. | 20 | 0 | return; | 21 | 0 | } | 22 | 381k | const v8::HandleScope handle_scope(isolate_); | 23 | 381k | const size_t size_in_bytes = | 24 | 381k | MultiplyWithOverflowCheck(sizeof(NativeT), count); | 25 | | | 26 | | // allocate v8 ArrayBuffer | 27 | 381k | v8::Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(isolate_, size_in_bytes); | 28 | 381k | buffer_ = static_cast<NativeT*>(ab->Data()); | 29 | | | 30 | | // allocate v8 TypedArray | 31 | 381k | v8::Local<V8T> js_array = V8T::New(ab, byte_offset_, count); | 32 | 381k | js_array_ = v8::Global<V8T>(isolate, js_array); | 33 | 381k | } |
node::AliasedBufferBase<unsigned int, v8::Uint32Array>::AliasedBufferBase(v8::Isolate*, unsigned long, unsigned long const*) Line | Count | Source | 16 | 763k | : isolate_(isolate), count_(count), byte_offset_(0), index_(index) { | 17 | 763k | CHECK_GT(count, 0); | 18 | 763k | if (index != nullptr) { | 19 | | // Will be deserialized later. | 20 | 0 | return; | 21 | 0 | } | 22 | 763k | const v8::HandleScope handle_scope(isolate_); | 23 | 763k | const size_t size_in_bytes = | 24 | 763k | MultiplyWithOverflowCheck(sizeof(NativeT), count); | 25 | | | 26 | | // allocate v8 ArrayBuffer | 27 | 763k | v8::Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(isolate_, size_in_bytes); | 28 | 763k | buffer_ = static_cast<NativeT*>(ab->Data()); | 29 | | | 30 | | // allocate v8 TypedArray | 31 | 763k | v8::Local<V8T> js_array = V8T::New(ab, byte_offset_, count); | 32 | 763k | js_array_ = v8::Global<V8T>(isolate, js_array); | 33 | 763k | } |
node::AliasedBufferBase<unsigned char, v8::Uint8Array>::AliasedBufferBase(v8::Isolate*, unsigned long, unsigned long const*) Line | Count | Source | 16 | 381k | : isolate_(isolate), count_(count), byte_offset_(0), index_(index) { | 17 | 381k | CHECK_GT(count, 0); | 18 | 381k | if (index != nullptr) { | 19 | | // Will be deserialized later. | 20 | 0 | return; | 21 | 0 | } | 22 | 381k | const v8::HandleScope handle_scope(isolate_); | 23 | 381k | const size_t size_in_bytes = | 24 | 381k | MultiplyWithOverflowCheck(sizeof(NativeT), count); | 25 | | | 26 | | // allocate v8 ArrayBuffer | 27 | 381k | v8::Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(isolate_, size_in_bytes); | 28 | 381k | buffer_ = static_cast<NativeT*>(ab->Data()); | 29 | | | 30 | | // allocate v8 TypedArray | 31 | 381k | v8::Local<V8T> js_array = V8T::New(ab, byte_offset_, count); | 32 | 381k | js_array_ = v8::Global<V8T>(isolate, js_array); | 33 | 381k | } |
node::AliasedBufferBase<double, v8::Float64Array>::AliasedBufferBase(v8::Isolate*, unsigned long, unsigned long const*) Line | Count | Source | 16 | 509k | : isolate_(isolate), count_(count), byte_offset_(0), index_(index) { | 17 | 509k | CHECK_GT(count, 0); | 18 | 509k | if (index != nullptr) { | 19 | | // Will be deserialized later. | 20 | 0 | return; | 21 | 0 | } | 22 | 509k | const v8::HandleScope handle_scope(isolate_); | 23 | 509k | const size_t size_in_bytes = | 24 | 509k | MultiplyWithOverflowCheck(sizeof(NativeT), count); | 25 | | | 26 | | // allocate v8 ArrayBuffer | 27 | 509k | v8::Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(isolate_, size_in_bytes); | 28 | 509k | buffer_ = static_cast<NativeT*>(ab->Data()); | 29 | | | 30 | | // allocate v8 TypedArray | 31 | 509k | v8::Local<V8T> js_array = V8T::New(ab, byte_offset_, count); | 32 | 509k | js_array_ = v8::Global<V8T>(isolate, js_array); | 33 | 509k | } |
node::AliasedBufferBase<long, v8::BigInt64Array>::AliasedBufferBase(v8::Isolate*, unsigned long, unsigned long const*) Line | Count | Source | 16 | 254k | : isolate_(isolate), count_(count), byte_offset_(0), index_(index) { | 17 | 254k | CHECK_GT(count, 0); | 18 | 254k | if (index != nullptr) { | 19 | | // Will be deserialized later. | 20 | 0 | return; | 21 | 0 | } | 22 | 254k | const v8::HandleScope handle_scope(isolate_); | 23 | 254k | const size_t size_in_bytes = | 24 | 254k | MultiplyWithOverflowCheck(sizeof(NativeT), count); | 25 | | | 26 | | // allocate v8 ArrayBuffer | 27 | 254k | v8::Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(isolate_, size_in_bytes); | 28 | 254k | buffer_ = static_cast<NativeT*>(ab->Data()); | 29 | | | 30 | | // allocate v8 TypedArray | 31 | 254k | v8::Local<V8T> js_array = V8T::New(ab, byte_offset_, count); | 32 | 254k | js_array_ = v8::Global<V8T>(isolate, js_array); | 33 | 254k | } |
|
34 | | |
35 | | template <typename NativeT, typename V8T> |
36 | | AliasedBufferBase<NativeT, V8T>::AliasedBufferBase( |
37 | | v8::Isolate* isolate, |
38 | | const size_t byte_offset, |
39 | | const size_t count, |
40 | | const AliasedBufferBase<uint8_t, v8::Uint8Array>& backing_buffer, |
41 | | const AliasedBufferIndex* index) |
42 | 254k | : isolate_(isolate), |
43 | 254k | count_(count), |
44 | 254k | byte_offset_(byte_offset), |
45 | 254k | index_(index) { |
46 | 254k | if (index != nullptr) { |
47 | | // Will be deserialized later. |
48 | 0 | return; |
49 | 0 | } |
50 | 254k | const v8::HandleScope handle_scope(isolate_); |
51 | 254k | v8::Local<v8::ArrayBuffer> ab = backing_buffer.GetArrayBuffer(); |
52 | | |
53 | | // validate that the byte_offset is aligned with sizeof(NativeT) |
54 | 254k | CHECK_EQ(byte_offset & (sizeof(NativeT) - 1), 0); |
55 | | // validate this fits inside the backing buffer |
56 | 254k | CHECK_LE(MultiplyWithOverflowCheck(sizeof(NativeT), count), |
57 | 254k | ab->ByteLength() - byte_offset); |
58 | | |
59 | 254k | buffer_ = reinterpret_cast<NativeT*>( |
60 | 254k | const_cast<uint8_t*>(backing_buffer.GetNativeBuffer() + byte_offset)); |
61 | | |
62 | 254k | v8::Local<V8T> js_array = V8T::New(ab, byte_offset, count); |
63 | 254k | js_array_ = v8::Global<V8T>(isolate, js_array); |
64 | 254k | } node::AliasedBufferBase<double, v8::Float64Array>::AliasedBufferBase(v8::Isolate*, unsigned long, unsigned long, node::AliasedBufferBase<unsigned char, v8::Uint8Array> const&, unsigned long const*) Line | Count | Source | 42 | 127k | : isolate_(isolate), | 43 | 127k | count_(count), | 44 | 127k | byte_offset_(byte_offset), | 45 | 127k | index_(index) { | 46 | 127k | if (index != nullptr) { | 47 | | // Will be deserialized later. | 48 | 0 | return; | 49 | 0 | } | 50 | 127k | const v8::HandleScope handle_scope(isolate_); | 51 | 127k | v8::Local<v8::ArrayBuffer> ab = backing_buffer.GetArrayBuffer(); | 52 | | | 53 | | // validate that the byte_offset is aligned with sizeof(NativeT) | 54 | 127k | CHECK_EQ(byte_offset & (sizeof(NativeT) - 1), 0); | 55 | | // validate this fits inside the backing buffer | 56 | 127k | CHECK_LE(MultiplyWithOverflowCheck(sizeof(NativeT), count), | 57 | 127k | ab->ByteLength() - byte_offset); | 58 | | | 59 | 127k | buffer_ = reinterpret_cast<NativeT*>( | 60 | 127k | const_cast<uint8_t*>(backing_buffer.GetNativeBuffer() + byte_offset)); | 61 | | | 62 | 127k | v8::Local<V8T> js_array = V8T::New(ab, byte_offset, count); | 63 | 127k | js_array_ = v8::Global<V8T>(isolate, js_array); | 64 | 127k | } |
node::AliasedBufferBase<unsigned int, v8::Uint32Array>::AliasedBufferBase(v8::Isolate*, unsigned long, unsigned long, node::AliasedBufferBase<unsigned char, v8::Uint8Array> const&, unsigned long const*) Line | Count | Source | 42 | 127k | : isolate_(isolate), | 43 | 127k | count_(count), | 44 | 127k | byte_offset_(byte_offset), | 45 | 127k | index_(index) { | 46 | 127k | if (index != nullptr) { | 47 | | // Will be deserialized later. | 48 | 0 | return; | 49 | 0 | } | 50 | 127k | const v8::HandleScope handle_scope(isolate_); | 51 | 127k | v8::Local<v8::ArrayBuffer> ab = backing_buffer.GetArrayBuffer(); | 52 | | | 53 | | // validate that the byte_offset is aligned with sizeof(NativeT) | 54 | 127k | CHECK_EQ(byte_offset & (sizeof(NativeT) - 1), 0); | 55 | | // validate this fits inside the backing buffer | 56 | 127k | CHECK_LE(MultiplyWithOverflowCheck(sizeof(NativeT), count), | 57 | 127k | ab->ByteLength() - byte_offset); | 58 | | | 59 | 127k | buffer_ = reinterpret_cast<NativeT*>( | 60 | 127k | const_cast<uint8_t*>(backing_buffer.GetNativeBuffer() + byte_offset)); | 61 | | | 62 | 127k | v8::Local<V8T> js_array = V8T::New(ab, byte_offset, count); | 63 | 127k | js_array_ = v8::Global<V8T>(isolate, js_array); | 64 | 127k | } |
|
65 | | |
66 | | template <typename NativeT, typename V8T> |
67 | | AliasedBufferBase<NativeT, V8T>::AliasedBufferBase( |
68 | | const AliasedBufferBase& that) |
69 | | : isolate_(that.isolate_), |
70 | | count_(that.count_), |
71 | | byte_offset_(that.byte_offset_), |
72 | | buffer_(that.buffer_) { |
73 | | js_array_ = v8::Global<V8T>(that.isolate_, that.GetJSArray()); |
74 | | DCHECK(is_valid()); |
75 | | } |
76 | | |
77 | | template <typename NativeT, typename V8T> |
78 | | AliasedBufferIndex AliasedBufferBase<NativeT, V8T>::Serialize( |
79 | 0 | v8::Local<v8::Context> context, v8::SnapshotCreator* creator) { |
80 | 0 | DCHECK(is_valid()); |
81 | 0 | return creator->AddData(context, GetJSArray()); |
82 | 0 | } Unexecuted instantiation: node::AliasedBufferBase<unsigned int, v8::Uint32Array>::Serialize(v8::Local<v8::Context>, v8::SnapshotCreator*) Unexecuted instantiation: node::AliasedBufferBase<unsigned char, v8::Uint8Array>::Serialize(v8::Local<v8::Context>, v8::SnapshotCreator*) Unexecuted instantiation: node::AliasedBufferBase<double, v8::Float64Array>::Serialize(v8::Local<v8::Context>, v8::SnapshotCreator*) Unexecuted instantiation: node::AliasedBufferBase<int, v8::Int32Array>::Serialize(v8::Local<v8::Context>, v8::SnapshotCreator*) Unexecuted instantiation: node::AliasedBufferBase<long, v8::BigInt64Array>::Serialize(v8::Local<v8::Context>, v8::SnapshotCreator*) |
83 | | |
84 | | template <typename NativeT, typename V8T> |
85 | | inline void AliasedBufferBase<NativeT, V8T>::Deserialize( |
86 | 0 | v8::Local<v8::Context> context) { |
87 | 0 | DCHECK_NOT_NULL(index_); |
88 | 0 | v8::Local<V8T> arr = |
89 | 0 | context->GetDataFromSnapshotOnce<V8T>(*index_).ToLocalChecked(); |
90 | | // These may not hold true for AliasedBuffers that have grown, so should |
91 | | // be removed when we expand the snapshot support. |
92 | 0 | DCHECK_EQ(count_, arr->Length()); |
93 | 0 | DCHECK_EQ(byte_offset_, arr->ByteOffset()); |
94 | 0 | uint8_t* raw = static_cast<uint8_t*>(arr->Buffer()->Data()); |
95 | 0 | buffer_ = reinterpret_cast<NativeT*>(raw + byte_offset_); |
96 | 0 | js_array_.Reset(isolate_, arr); |
97 | 0 | index_ = nullptr; |
98 | 0 | } Unexecuted instantiation: node::AliasedBufferBase<unsigned int, v8::Uint32Array>::Deserialize(v8::Local<v8::Context>) Unexecuted instantiation: node::AliasedBufferBase<unsigned char, v8::Uint8Array>::Deserialize(v8::Local<v8::Context>) Unexecuted instantiation: node::AliasedBufferBase<double, v8::Float64Array>::Deserialize(v8::Local<v8::Context>) Unexecuted instantiation: node::AliasedBufferBase<int, v8::Int32Array>::Deserialize(v8::Local<v8::Context>) Unexecuted instantiation: node::AliasedBufferBase<long, v8::BigInt64Array>::Deserialize(v8::Local<v8::Context>) |
99 | | |
100 | | template <typename NativeT, typename V8T> |
101 | | AliasedBufferBase<NativeT, V8T>& AliasedBufferBase<NativeT, V8T>::operator=( |
102 | | AliasedBufferBase<NativeT, V8T>&& that) noexcept { |
103 | | DCHECK(is_valid()); |
104 | | this->~AliasedBufferBase(); |
105 | | isolate_ = that.isolate_; |
106 | | count_ = that.count_; |
107 | | byte_offset_ = that.byte_offset_; |
108 | | buffer_ = that.buffer_; |
109 | | |
110 | | js_array_.Reset(isolate_, that.js_array_.Get(isolate_)); |
111 | | |
112 | | that.buffer_ = nullptr; |
113 | | that.js_array_.Reset(); |
114 | | return *this; |
115 | | } |
116 | | |
117 | | template <typename NativeT, typename V8T> |
118 | 2.63M | v8::Local<V8T> AliasedBufferBase<NativeT, V8T>::GetJSArray() const { |
119 | 2.63M | DCHECK(is_valid()); |
120 | 2.63M | return js_array_.Get(isolate_); |
121 | 2.63M | } node::AliasedBufferBase<unsigned int, v8::Uint32Array>::GetJSArray() const Line | Count | Source | 118 | 891k | v8::Local<V8T> AliasedBufferBase<NativeT, V8T>::GetJSArray() const { | 119 | 891k | DCHECK(is_valid()); | 120 | 891k | return js_array_.Get(isolate_); | 121 | 891k | } |
node::AliasedBufferBase<double, v8::Float64Array>::GetJSArray() const Line | Count | Source | 118 | 636k | v8::Local<V8T> AliasedBufferBase<NativeT, V8T>::GetJSArray() const { | 119 | 636k | DCHECK(is_valid()); | 120 | 636k | return js_array_.Get(isolate_); | 121 | 636k | } |
node::AliasedBufferBase<unsigned char, v8::Uint8Array>::GetJSArray() const Line | Count | Source | 118 | 509k | v8::Local<V8T> AliasedBufferBase<NativeT, V8T>::GetJSArray() const { | 119 | 509k | DCHECK(is_valid()); | 120 | 509k | return js_array_.Get(isolate_); | 121 | 509k | } |
node::AliasedBufferBase<int, v8::Int32Array>::GetJSArray() const Line | Count | Source | 118 | 340k | v8::Local<V8T> AliasedBufferBase<NativeT, V8T>::GetJSArray() const { | 119 | 340k | DCHECK(is_valid()); | 120 | 340k | return js_array_.Get(isolate_); | 121 | 340k | } |
node::AliasedBufferBase<long, v8::BigInt64Array>::GetJSArray() const Line | Count | Source | 118 | 254k | v8::Local<V8T> AliasedBufferBase<NativeT, V8T>::GetJSArray() const { | 119 | 254k | DCHECK(is_valid()); | 120 | 254k | return js_array_.Get(isolate_); | 121 | 254k | } |
|
122 | | |
123 | | template <typename NativeT, typename V8T> |
124 | 0 | void AliasedBufferBase<NativeT, V8T>::Release() { |
125 | 0 | DCHECK_NULL(index_); |
126 | 0 | js_array_.Reset(); |
127 | 0 | } |
128 | | |
129 | | template <typename NativeT, typename V8T> |
130 | 1.01M | inline void AliasedBufferBase<NativeT, V8T>::MakeWeak() { |
131 | 1.01M | DCHECK(is_valid()); |
132 | 1.01M | js_array_.SetWeak(); |
133 | 1.01M | } node::AliasedBufferBase<double, v8::Float64Array>::MakeWeak() Line | Count | Source | 130 | 254k | inline void AliasedBufferBase<NativeT, V8T>::MakeWeak() { | 131 | 254k | DCHECK(is_valid()); | 132 | 254k | js_array_.SetWeak(); | 133 | 254k | } |
node::AliasedBufferBase<long, v8::BigInt64Array>::MakeWeak() Line | Count | Source | 130 | 254k | inline void AliasedBufferBase<NativeT, V8T>::MakeWeak() { | 131 | 254k | DCHECK(is_valid()); | 132 | 254k | js_array_.SetWeak(); | 133 | 254k | } |
node::AliasedBufferBase<unsigned int, v8::Uint32Array>::MakeWeak() Line | Count | Source | 130 | 381k | inline void AliasedBufferBase<NativeT, V8T>::MakeWeak() { | 131 | 381k | DCHECK(is_valid()); | 132 | 381k | js_array_.SetWeak(); | 133 | 381k | } |
node::AliasedBufferBase<unsigned char, v8::Uint8Array>::MakeWeak() Line | Count | Source | 130 | 127k | inline void AliasedBufferBase<NativeT, V8T>::MakeWeak() { | 131 | 127k | DCHECK(is_valid()); | 132 | 127k | js_array_.SetWeak(); | 133 | 127k | } |
|
134 | | |
135 | | template <typename NativeT, typename V8T> |
136 | | v8::Local<v8::ArrayBuffer> AliasedBufferBase<NativeT, V8T>::GetArrayBuffer() |
137 | 254k | const { |
138 | 254k | return GetJSArray()->Buffer(); |
139 | 254k | } |
140 | | |
141 | | template <typename NativeT, typename V8T> |
142 | 254k | inline const NativeT* AliasedBufferBase<NativeT, V8T>::GetNativeBuffer() const { |
143 | 254k | DCHECK(is_valid()); |
144 | 254k | return buffer_; |
145 | 254k | } node::AliasedBufferBase<unsigned char, v8::Uint8Array>::GetNativeBuffer() const Line | Count | Source | 142 | 254k | inline const NativeT* AliasedBufferBase<NativeT, V8T>::GetNativeBuffer() const { | 143 | 254k | DCHECK(is_valid()); | 144 | 254k | return buffer_; | 145 | 254k | } |
Unexecuted instantiation: node::AliasedBufferBase<unsigned int, v8::Uint32Array>::GetNativeBuffer() const |
146 | | |
147 | | template <typename NativeT, typename V8T> |
148 | | inline const NativeT* AliasedBufferBase<NativeT, V8T>::operator*() const { |
149 | | return GetNativeBuffer(); |
150 | | } |
151 | | |
152 | | template <typename NativeT, typename V8T> |
153 | | inline void AliasedBufferBase<NativeT, V8T>::SetValue(const size_t index, |
154 | 6.62M | NativeT value) { |
155 | 6.62M | DCHECK_LT(index, count_); |
156 | 6.62M | DCHECK(is_valid()); |
157 | 6.62M | buffer_[index] = value; |
158 | 6.62M | } node::AliasedBufferBase<unsigned int, v8::Uint32Array>::SetValue(unsigned long, unsigned int) Line | Count | Source | 154 | 1.70M | NativeT value) { | 155 | 1.70M | DCHECK_LT(index, count_); | 156 | 1.70M | DCHECK(is_valid()); | 157 | 1.70M | buffer_[index] = value; | 158 | 1.70M | } |
node::AliasedBufferBase<int, v8::Int32Array>::SetValue(unsigned long, int) Line | Count | Source | 154 | 130k | NativeT value) { | 155 | 130k | DCHECK_LT(index, count_); | 156 | 130k | DCHECK(is_valid()); | 157 | 130k | buffer_[index] = value; | 158 | 130k | } |
node::AliasedBufferBase<double, v8::Float64Array>::SetValue(unsigned long, double) Line | Count | Source | 154 | 4.66M | NativeT value) { | 155 | 4.66M | DCHECK_LT(index, count_); | 156 | 4.66M | DCHECK(is_valid()); | 157 | 4.66M | buffer_[index] = value; | 158 | 4.66M | } |
Unexecuted instantiation: node::AliasedBufferBase<long, v8::BigInt64Array>::SetValue(unsigned long, long) node::AliasedBufferBase<unsigned char, v8::Uint8Array>::SetValue(unsigned long, unsigned char) Line | Count | Source | 154 | 127k | NativeT value) { | 155 | 127k | DCHECK_LT(index, count_); | 156 | 127k | DCHECK(is_valid()); | 157 | 127k | buffer_[index] = value; | 158 | 127k | } |
|
159 | | |
160 | | template <typename NativeT, typename V8T> |
161 | | inline const NativeT AliasedBufferBase<NativeT, V8T>::GetValue( |
162 | 2.39M | const size_t index) const { |
163 | 2.39M | DCHECK(is_valid()); |
164 | 2.39M | DCHECK_LT(index, count_); |
165 | 2.39M | return buffer_[index]; |
166 | 2.39M | } node::AliasedBufferBase<unsigned int, v8::Uint32Array>::GetValue(unsigned long) const Line | Count | Source | 162 | 1.31M | const size_t index) const { | 163 | 1.31M | DCHECK(is_valid()); | 164 | 1.31M | DCHECK_LT(index, count_); | 165 | 1.31M | return buffer_[index]; | 166 | 1.31M | } |
node::AliasedBufferBase<unsigned char, v8::Uint8Array>::GetValue(unsigned long) const Line | Count | Source | 162 | 120k | const size_t index) const { | 163 | 120k | DCHECK(is_valid()); | 164 | 120k | DCHECK_LT(index, count_); | 165 | 120k | return buffer_[index]; | 166 | 120k | } |
node::AliasedBufferBase<int, v8::Int32Array>::GetValue(unsigned long) const Line | Count | Source | 162 | 168k | const size_t index) const { | 163 | 168k | DCHECK(is_valid()); | 164 | 168k | DCHECK_LT(index, count_); | 165 | 168k | return buffer_[index]; | 166 | 168k | } |
node::AliasedBufferBase<double, v8::Float64Array>::GetValue(unsigned long) const Line | Count | Source | 162 | 790k | const size_t index) const { | 163 | 790k | DCHECK(is_valid()); | 164 | 790k | DCHECK_LT(index, count_); | 165 | 790k | return buffer_[index]; | 166 | 790k | } |
|
167 | | |
168 | | template <typename NativeT, typename V8T> |
169 | | typename AliasedBufferBase<NativeT, V8T>::Reference |
170 | 7.98M | AliasedBufferBase<NativeT, V8T>::operator[](size_t index) { |
171 | 7.98M | DCHECK(is_valid()); |
172 | 7.98M | return Reference(this, index); |
173 | 7.98M | } node::AliasedBufferBase<unsigned int, v8::Uint32Array>::operator[](unsigned long) Line | Count | Source | 170 | 2.37M | AliasedBufferBase<NativeT, V8T>::operator[](size_t index) { | 171 | 2.37M | DCHECK(is_valid()); | 172 | 2.37M | return Reference(this, index); | 173 | 2.37M | } |
node::AliasedBufferBase<int, v8::Int32Array>::operator[](unsigned long) Line | Count | Source | 170 | 130k | AliasedBufferBase<NativeT, V8T>::operator[](size_t index) { | 171 | 130k | DCHECK(is_valid()); | 172 | 130k | return Reference(this, index); | 173 | 130k | } |
node::AliasedBufferBase<double, v8::Float64Array>::operator[](unsigned long) Line | Count | Source | 170 | 5.34M | AliasedBufferBase<NativeT, V8T>::operator[](size_t index) { | 171 | 5.34M | DCHECK(is_valid()); | 172 | 5.34M | return Reference(this, index); | 173 | 5.34M | } |
node::AliasedBufferBase<unsigned char, v8::Uint8Array>::operator[](unsigned long) Line | Count | Source | 170 | 127k | AliasedBufferBase<NativeT, V8T>::operator[](size_t index) { | 171 | 127k | DCHECK(is_valid()); | 172 | 127k | return Reference(this, index); | 173 | 127k | } |
|
174 | | |
175 | | template <typename NativeT, typename V8T> |
176 | 543k | NativeT AliasedBufferBase<NativeT, V8T>::operator[](size_t index) const { |
177 | 543k | return GetValue(index); |
178 | 543k | } node::AliasedBufferBase<unsigned int, v8::Uint32Array>::operator[](unsigned long) const Line | Count | Source | 176 | 254k | NativeT AliasedBufferBase<NativeT, V8T>::operator[](size_t index) const { | 177 | 254k | return GetValue(index); | 178 | 254k | } |
node::AliasedBufferBase<unsigned char, v8::Uint8Array>::operator[](unsigned long) const Line | Count | Source | 176 | 120k | NativeT AliasedBufferBase<NativeT, V8T>::operator[](size_t index) const { | 177 | 120k | return GetValue(index); | 178 | 120k | } |
node::AliasedBufferBase<int, v8::Int32Array>::operator[](unsigned long) const Line | Count | Source | 176 | 168k | NativeT AliasedBufferBase<NativeT, V8T>::operator[](size_t index) const { | 177 | 168k | return GetValue(index); | 178 | 168k | } |
|
179 | | |
180 | | template <typename NativeT, typename V8T> |
181 | 254k | size_t AliasedBufferBase<NativeT, V8T>::Length() const { |
182 | 254k | return count_; |
183 | 254k | } |
184 | | |
185 | | template <typename NativeT, typename V8T> |
186 | 0 | void AliasedBufferBase<NativeT, V8T>::reserve(size_t new_capacity) { |
187 | 0 | DCHECK(is_valid()); |
188 | 0 | DCHECK_GE(new_capacity, count_); |
189 | 0 | DCHECK_EQ(byte_offset_, 0); |
190 | 0 | const v8::HandleScope handle_scope(isolate_); |
191 | |
|
192 | 0 | const size_t old_size_in_bytes = sizeof(NativeT) * count_; |
193 | 0 | const size_t new_size_in_bytes = |
194 | 0 | MultiplyWithOverflowCheck(sizeof(NativeT), new_capacity); |
195 | | |
196 | | // allocate v8 new ArrayBuffer |
197 | 0 | v8::Local<v8::ArrayBuffer> ab = |
198 | 0 | v8::ArrayBuffer::New(isolate_, new_size_in_bytes); |
199 | | |
200 | | // allocate new native buffer |
201 | 0 | NativeT* new_buffer = static_cast<NativeT*>(ab->Data()); |
202 | | // copy old content |
203 | 0 | memcpy(new_buffer, buffer_, old_size_in_bytes); |
204 | | |
205 | | // allocate v8 TypedArray |
206 | 0 | v8::Local<V8T> js_array = V8T::New(ab, byte_offset_, new_capacity); |
207 | | |
208 | | // move over old v8 TypedArray |
209 | 0 | js_array_ = std::move(v8::Global<V8T>(isolate_, js_array)); |
210 | |
|
211 | 0 | buffer_ = new_buffer; |
212 | 0 | count_ = new_capacity; |
213 | 0 | } |
214 | | |
215 | | template <typename NativeT, typename V8T> |
216 | | inline bool AliasedBufferBase<NativeT, V8T>::is_valid() const { |
217 | | return index_ == nullptr && !js_array_.IsEmpty(); |
218 | | } |
219 | | |
220 | | template <typename NativeT, typename V8T> |
221 | 0 | inline size_t AliasedBufferBase<NativeT, V8T>::SelfSize() const { |
222 | 0 | return sizeof(*this); |
223 | 0 | } Unexecuted instantiation: node::AliasedBufferBase<int, v8::Int32Array>::SelfSize() const Unexecuted instantiation: node::AliasedBufferBase<unsigned int, v8::Uint32Array>::SelfSize() const Unexecuted instantiation: node::AliasedBufferBase<unsigned char, v8::Uint8Array>::SelfSize() const Unexecuted instantiation: node::AliasedBufferBase<double, v8::Float64Array>::SelfSize() const Unexecuted instantiation: node::AliasedBufferBase<long, v8::BigInt64Array>::SelfSize() const |
224 | | |
225 | | #define VM(NativeT, V8T) \ |
226 | | template <> \ |
227 | | inline const char* AliasedBufferBase<NativeT, v8::V8T>::MemoryInfoName() \ |
228 | 0 | const { \ |
229 | 0 | return "Aliased" #V8T; \ |
230 | 0 | } \ Unexecuted instantiation: node::AliasedBufferBase<signed char, v8::Int8Array>::MemoryInfoName() const Unexecuted instantiation: node::AliasedBufferBase<unsigned char, v8::Uint8Array>::MemoryInfoName() const Unexecuted instantiation: node::AliasedBufferBase<short, v8::Int16Array>::MemoryInfoName() const Unexecuted instantiation: node::AliasedBufferBase<unsigned short, v8::Uint16Array>::MemoryInfoName() const Unexecuted instantiation: node::AliasedBufferBase<int, v8::Int32Array>::MemoryInfoName() const Unexecuted instantiation: node::AliasedBufferBase<unsigned int, v8::Uint32Array>::MemoryInfoName() const Unexecuted instantiation: node::AliasedBufferBase<float, v8::Float32Array>::MemoryInfoName() const Unexecuted instantiation: node::AliasedBufferBase<double, v8::Float64Array>::MemoryInfoName() const Unexecuted instantiation: node::AliasedBufferBase<long, v8::BigInt64Array>::MemoryInfoName() const |
231 | | template <> \ |
232 | | inline void AliasedBufferBase<NativeT, v8::V8T>::MemoryInfo( \ |
233 | 0 | node::MemoryTracker* tracker) const { \ |
234 | 0 | tracker->TrackField("js_array", js_array_); \ |
235 | 0 | } Unexecuted instantiation: node::AliasedBufferBase<signed char, v8::Int8Array>::MemoryInfo(node::MemoryTracker*) const Unexecuted instantiation: node::AliasedBufferBase<unsigned char, v8::Uint8Array>::MemoryInfo(node::MemoryTracker*) const Unexecuted instantiation: node::AliasedBufferBase<short, v8::Int16Array>::MemoryInfo(node::MemoryTracker*) const Unexecuted instantiation: node::AliasedBufferBase<unsigned short, v8::Uint16Array>::MemoryInfo(node::MemoryTracker*) const Unexecuted instantiation: node::AliasedBufferBase<int, v8::Int32Array>::MemoryInfo(node::MemoryTracker*) const Unexecuted instantiation: node::AliasedBufferBase<unsigned int, v8::Uint32Array>::MemoryInfo(node::MemoryTracker*) const Unexecuted instantiation: node::AliasedBufferBase<float, v8::Float32Array>::MemoryInfo(node::MemoryTracker*) const Unexecuted instantiation: node::AliasedBufferBase<double, v8::Float64Array>::MemoryInfo(node::MemoryTracker*) const Unexecuted instantiation: node::AliasedBufferBase<long, v8::BigInt64Array>::MemoryInfo(node::MemoryTracker*) const |
236 | | ALIASED_BUFFER_LIST(VM) |
237 | | #undef VM |
238 | | |
239 | | } // namespace node |
240 | | |
241 | | #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS |
242 | | |
243 | | #endif // SRC_ALIASED_BUFFER_INL_H_ |