diff options
author | Daniel Bevenius <daniel.bevenius@gmail.com> | 2018-03-02 11:46:20 +0100 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2018-03-09 08:01:20 -0800 |
commit | 45277e23d5488dc11d705b850d310b4afb5085bb (patch) | |
tree | 137820084c6eb3a1046d5456bba51e4eda771127 /test/cctest | |
parent | cca12ee3216a418642518d066d8b2684634b4121 (diff) | |
download | android-node-v8-45277e23d5488dc11d705b850d310b4afb5085bb.tar.gz android-node-v8-45277e23d5488dc11d705b850d310b4afb5085bb.tar.bz2 android-node-v8-45277e23d5488dc11d705b850d310b4afb5085bb.zip |
src: add incr/decr operators for Reference
This commit adds operator overloads for increment/decrement to
AliasedBuffer::Reference.
The motivation for doing this is to hopefully make code that needs
to increment/decrement a little simpler.
PR-URL: https://github.com/nodejs/node/pull/19083
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Diffstat (limited to 'test/cctest')
-rw-r--r-- | test/cctest/test_aliased_buffer.cc | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/test/cctest/test_aliased_buffer.cc b/test/cctest/test_aliased_buffer.cc index 0eaddf7735..7afa466133 100644 --- a/test/cctest/test_aliased_buffer.cc +++ b/test/cctest/test_aliased_buffer.cc @@ -207,3 +207,33 @@ TEST_F(AliasBufferTest, SharedArrayBuffer4) { int8_t, v8::Int8Array, int32_t, v8::Int32Array>(isolate_, 1, 3, 1); } + +TEST_F(AliasBufferTest, OperatorOverloads) { + v8::Isolate::Scope isolate_scope(isolate_); + v8::HandleScope handle_scope(isolate_); + v8::Local<v8::Context> context = v8::Context::New(isolate_); + v8::Context::Scope context_scope(context); + const size_t size = 10; + AliasedBuffer<uint32_t, v8::Uint32Array> ab{isolate_, size}; + + EXPECT_EQ(static_cast<uint32_t>(1), ab[0] = 1); + EXPECT_EQ(static_cast<uint32_t>(4), ab[0] += 3); + EXPECT_EQ(static_cast<uint32_t>(2), ab[0] -= 2); + EXPECT_EQ(static_cast<uint32_t>(-2), -ab[0]); +} + +TEST_F(AliasBufferTest, OperatorOverloadsRefs) { + v8::Isolate::Scope isolate_scope(isolate_); + v8::HandleScope handle_scope(isolate_); + v8::Local<v8::Context> context = v8::Context::New(isolate_); + v8::Context::Scope context_scope(context); + AliasedBuffer<uint32_t, v8::Uint32Array> ab{isolate_, 2}; + using Reference = AliasedBuffer<uint32_t, v8::Uint32Array>::Reference; + Reference ref = ab[0]; + Reference ref_value = ab[1] = 2; + + EXPECT_EQ(static_cast<uint32_t>(2), ref = ref_value); + EXPECT_EQ(static_cast<uint32_t>(4), ref += ref_value); + EXPECT_EQ(static_cast<uint32_t>(2), ref -= ref_value); + EXPECT_EQ(static_cast<uint32_t>(-2), -ref); +} |