Eric Holk | b2fa95d | 2017-07-17 18:51:36 | [diff] [blame] | 1 | // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "gin/array_buffer.h" |
| 6 | #include "build/build_config.h" |
| 7 | #include "gin/per_isolate_data.h" |
| 8 | #include "gin/public/isolate_holder.h" |
| 9 | #include "gin/test/v8_test.h" |
| 10 | |
Eric Holk | b2fa95d | 2017-07-17 18:51:36 | [diff] [blame] | 11 | namespace gin { |
| 12 | |
| 13 | using ArrayBufferTest = V8Test; |
| 14 | |
| 15 | namespace { |
| 16 | const size_t kBufferLength = 65536; |
| 17 | } |
| 18 | |
Bill Budge | 2ca3514 | 2018-02-21 23:22:22 | [diff] [blame] | 19 | // Make sure we can allocate, access and free memory. |
Eric Holk | b2fa95d | 2017-07-17 18:51:36 | [diff] [blame] | 20 | TEST_F(ArrayBufferTest, AllocateAndFreeBuffer) { |
| 21 | v8::Isolate* const isolate = instance_->isolate(); |
| 22 | v8::ArrayBuffer::Allocator* const allocator = |
| 23 | PerIsolateData::From(isolate)->allocator(); |
| 24 | |
| 25 | void* buffer = allocator->Allocate(kBufferLength); |
Bill Budge | 2ca3514 | 2018-02-21 23:22:22 | [diff] [blame] | 26 | char* buffer0 = reinterpret_cast<char*>(buffer); |
| 27 | *buffer0 = '0'; // ASCII zero |
| 28 | CHECK_EQ('0', *buffer0); |
Eric Holk | b2fa95d | 2017-07-17 18:51:36 | [diff] [blame] | 29 | allocator->Free(buffer, kBufferLength); |
| 30 | } |
| 31 | |
Eric Holk | b2fa95d | 2017-07-17 18:51:36 | [diff] [blame] | 32 | } // namespace gin |