summaryrefslogtreecommitdiff
path: root/deps/v8/test/cctest/test-api-array-buffer.cc
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/test/cctest/test-api-array-buffer.cc')
-rw-r--r--deps/v8/test/cctest/test-api-array-buffer.cc29
1 files changed, 18 insertions, 11 deletions
diff --git a/deps/v8/test/cctest/test-api-array-buffer.cc b/deps/v8/test/cctest/test-api-array-buffer.cc
index ee614fc63c..248a6bc04b 100644
--- a/deps/v8/test/cctest/test-api-array-buffer.cc
+++ b/deps/v8/test/cctest/test-api-array-buffer.cc
@@ -336,8 +336,10 @@ THREADED_TEST(SkipArrayBufferBackingStoreDuringGC) {
v8::Isolate* isolate = env->GetIsolate();
v8::HandleScope handle_scope(isolate);
+ void* buffer = CcTest::array_buffer_allocator()->Allocate(100);
// Make sure the pointer looks like a heap object
- uint8_t* store_ptr = reinterpret_cast<uint8_t*>(i::kHeapObjectTag);
+ uintptr_t address = reinterpret_cast<uintptr_t>(buffer) | i::kHeapObjectTag;
+ void* store_ptr = reinterpret_cast<void*>(address);
auto backing_store = v8::ArrayBuffer::NewBackingStore(
store_ptr, 8, [](void*, size_t, void*) {}, nullptr);
@@ -353,6 +355,8 @@ THREADED_TEST(SkipArrayBufferBackingStoreDuringGC) {
// Should not move the pointer
CHECK_EQ(ab->GetBackingStore()->Data(), store_ptr);
+
+ CcTest::array_buffer_allocator()->Free(buffer, 100);
}
THREADED_TEST(SkipArrayBufferDuringScavenge) {
@@ -429,7 +433,7 @@ static void BackingStoreCustomDeleter(void* data, size_t length,
CHECK_EQ(backing_store_custom_length, length);
CHECK_EQ(backing_store_custom_deleter_data,
reinterpret_cast<intptr_t>(deleter_data));
- free(data);
+ CcTest::array_buffer_allocator()->Free(data, length);
backing_store_custom_called = true;
}
@@ -437,7 +441,7 @@ TEST(ArrayBuffer_NewBackingStore_CustomDeleter) {
{
// Create and destroy a backing store.
backing_store_custom_called = false;
- backing_store_custom_data = malloc(100);
+ backing_store_custom_data = CcTest::array_buffer_allocator()->Allocate(100);
backing_store_custom_length = 100;
v8::ArrayBuffer::NewBackingStore(
backing_store_custom_data, backing_store_custom_length,
@@ -451,7 +455,7 @@ TEST(SharedArrayBuffer_NewBackingStore_CustomDeleter) {
{
// Create and destroy a backing store.
backing_store_custom_called = false;
- backing_store_custom_data = malloc(100);
+ backing_store_custom_data = CcTest::array_buffer_allocator()->Allocate(100);
backing_store_custom_length = 100;
v8::SharedArrayBuffer::NewBackingStore(
backing_store_custom_data, backing_store_custom_length,
@@ -465,9 +469,10 @@ TEST(ArrayBuffer_NewBackingStore_EmptyDeleter) {
LocalContext env;
v8::Isolate* isolate = env->GetIsolate();
v8::HandleScope handle_scope(isolate);
- char static_buffer[100];
+ size_t size = 100;
+ void* buffer = CcTest::array_buffer_allocator()->Allocate(size);
std::unique_ptr<v8::BackingStore> backing_store =
- v8::ArrayBuffer::NewBackingStore(static_buffer, sizeof(static_buffer),
+ v8::ArrayBuffer::NewBackingStore(buffer, size,
v8::BackingStore::EmptyDeleter, nullptr);
uint64_t external_memory_before =
isolate->AdjustAmountOfExternalAllocatedMemory(0);
@@ -477,17 +482,18 @@ TEST(ArrayBuffer_NewBackingStore_EmptyDeleter) {
// The ArrayBuffer constructor does not increase the external memory counter.
// The counter may decrease however if the allocation triggers GC.
CHECK_GE(external_memory_before, external_memory_after);
+ CcTest::array_buffer_allocator()->Free(buffer, size);
}
TEST(SharedArrayBuffer_NewBackingStore_EmptyDeleter) {
LocalContext env;
v8::Isolate* isolate = env->GetIsolate();
v8::HandleScope handle_scope(isolate);
- char static_buffer[100];
+ size_t size = 100;
+ void* buffer = CcTest::array_buffer_allocator()->Allocate(size);
std::unique_ptr<v8::BackingStore> backing_store =
v8::SharedArrayBuffer::NewBackingStore(
- static_buffer, sizeof(static_buffer), v8::BackingStore::EmptyDeleter,
- nullptr);
+ buffer, size, v8::BackingStore::EmptyDeleter, nullptr);
uint64_t external_memory_before =
isolate->AdjustAmountOfExternalAllocatedMemory(0);
v8::SharedArrayBuffer::New(isolate, std::move(backing_store));
@@ -496,6 +502,7 @@ TEST(SharedArrayBuffer_NewBackingStore_EmptyDeleter) {
// The SharedArrayBuffer constructor does not increase the external memory
// counter. The counter may decrease however if the allocation triggers GC.
CHECK_GE(external_memory_before, external_memory_after);
+ CcTest::array_buffer_allocator()->Free(buffer, size);
}
THREADED_TEST(BackingStore_NotShared) {
@@ -506,7 +513,7 @@ THREADED_TEST(BackingStore_NotShared) {
CHECK(!ab->GetBackingStore()->IsShared());
CHECK(!v8::ArrayBuffer::NewBackingStore(isolate, 8)->IsShared());
backing_store_custom_called = false;
- backing_store_custom_data = malloc(100);
+ backing_store_custom_data = CcTest::array_buffer_allocator()->Allocate(100);
backing_store_custom_length = 100;
CHECK(!v8::ArrayBuffer::NewBackingStore(
backing_store_custom_data, backing_store_custom_length,
@@ -523,7 +530,7 @@ THREADED_TEST(BackingStore_Shared) {
CHECK(ab->GetBackingStore()->IsShared());
CHECK(v8::SharedArrayBuffer::NewBackingStore(isolate, 8)->IsShared());
backing_store_custom_called = false;
- backing_store_custom_data = malloc(100);
+ backing_store_custom_data = CcTest::array_buffer_allocator()->Allocate(100);
backing_store_custom_length = 100;
CHECK(v8::SharedArrayBuffer::NewBackingStore(
backing_store_custom_data, backing_store_custom_length,