Skip to content

Commit 18f46e8

Browse files
committed
squash: add test for Reference overloads
1 parent 651bfb2 commit 18f46e8

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/aliased_buffer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class AliasedBuffer {
149149
}
150150

151151
inline Reference& operator+=(const Reference& val) {
152-
return *this->operator+=(static_cast<NativeT>(val));
152+
return this->operator+=(static_cast<NativeT>(val));
153153
}
154154

155155
template <typename T>

test/cctest/test_aliased_buffer.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,3 +221,19 @@ TEST_F(AliasBufferTest, OperatorOverloads) {
221221
EXPECT_EQ(static_cast<uint32_t>(2), ab[0] -= 2);
222222
EXPECT_EQ(static_cast<uint32_t>(-2), -ab[0]);
223223
}
224+
225+
TEST_F(AliasBufferTest, OperatorOverloadsRefs) {
226+
v8::Isolate::Scope isolate_scope(isolate_);
227+
v8::HandleScope handle_scope(isolate_);
228+
v8::Local<v8::Context> context = v8::Context::New(isolate_);
229+
v8::Context::Scope context_scope(context);
230+
AliasedBuffer<uint32_t, v8::Uint32Array> ab{isolate_, 2};
231+
using Reference = AliasedBuffer<uint32_t, v8::Uint32Array>::Reference;
232+
Reference ref = ab[0];
233+
Reference ref_value = ab[1] = 2;
234+
235+
EXPECT_EQ(static_cast<uint32_t>(2), ref = ref_value);
236+
EXPECT_EQ(static_cast<uint32_t>(4), ref += ref_value);
237+
EXPECT_EQ(static_cast<uint32_t>(2), ref -= ref_value);
238+
EXPECT_EQ(static_cast<uint32_t>(-2), -ref);
239+
}

0 commit comments

Comments
 (0)