1 // Copyright 2017 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "gin/array_buffer.h"
7 #include "base/check_op.h"
8 #include "build/build_config.h"
9 #include "gin/per_isolate_data.h"
10 #include "gin/public/isolate_holder.h"
11 #include "gin/test/v8_test.h"
15 using ArrayBufferTest = V8Test;
18 const size_t kBufferLength = 65536;
21 // Make sure we can allocate, access and free memory.
22 TEST_F(ArrayBufferTest, AllocateAndFreeBuffer) {
23 v8::Isolate* const isolate = instance_->isolate();
24 v8::ArrayBuffer::Allocator* const allocator =
25 PerIsolateData::From(isolate)->allocator();
27 void* buffer = allocator->Allocate(kBufferLength);
28 char* buffer0 = reinterpret_cast<char*>(buffer);
29 *buffer0 = '0'; // ASCII zero
30 CHECK_EQ('0', *buffer0);
31 allocator->Free(buffer, kBufferLength);