Skip to content

Commit

Permalink
respnoding to PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Kaufman committed Sep 13, 2017
1 parent d06a833 commit c6508f7
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/aliased_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,17 @@ class AliasedBuffer {
byte_offset_(byte_offset),
free_buffer_(false) {
const v8::HandleScope handle_scope(isolate_);

v8::Local<v8::ArrayBuffer> ab = backing_buffer.GetArrayBuffer();

// validate that the byte_offset is aligned with sizeof(NativeT)
CHECK_EQ(byte_offset & (sizeof(NativeT) - 1), 0);
// validate this fits inside the backing buffer
CHECK_LE(sizeof(NativeT) * count,
backing_buffer.GetArrayBuffer()->ByteLength() - byte_offset);
CHECK_LE(sizeof(NativeT) * count, ab->ByteLength() - byte_offset);

buffer_ = reinterpret_cast<NativeT*>(
const_cast<uint8_t*>(backing_buffer.GetNativeBuffer() + byte_offset));

v8::Local<v8::ArrayBuffer> ab = backing_buffer.GetArrayBuffer();
v8::Local<V8T> js_array = V8T::New(ab, byte_offset, count);
js_array_ = v8::Global<V8T>(isolate, js_array);
}
Expand Down Expand Up @@ -159,19 +160,19 @@ class AliasedBuffer {
* Set position index to given value.
*/
inline void SetValue(const size_t index, NativeT value) {
#if defined(DEBUG) && DEBUG
CHECK_LT(index, count_);
#endif
#if defined(DEBUG) && DEBUG
CHECK_LT(index, count_);
#endif
buffer_[index] = value;
}

/**
* Get value at position index
*/
inline const NativeT GetValue(const size_t index) const {
#if defined(DEBUG) && DEBUG
CHECK_LT(index, count_);
#endif
#if defined(DEBUG) && DEBUG
CHECK_LT(index, count_);
#endif
return buffer_[index];
}

Expand Down

0 comments on commit c6508f7

Please sign in to comment.