Avi Drissman | 468e51b6 | 2022-09-13 20:47:01 | [diff] [blame] | 1 | // Copyright 2017 The Chromium Authors |
Eric Holk | b2fa95d | 2017-07-17 18:51:36 | [diff] [blame] | 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" |
Lei Zhang | 8815c18 | 2022-11-03 14:40:27 | [diff] [blame] | 6 | |
| 7 | #include"base/check_op.h" |
Eric Holk | b2fa95d | 2017-07-17 18:51:36 | [diff] [blame] | 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" |
| 12 | |
Eric Holk | b2fa95d | 2017-07-17 18:51:36 | [diff] [blame] | 13 | namespace gin{ |
| 14 | |
| 15 | usingArrayBufferTest= V8Test; |
| 16 | |
| 17 | namespace{ |
| 18 | constsize_t kBufferLength=65536; |
| 19 | } |
| 20 | |
Bill Budge | 2ca3514 | 2018-02-21 23:22:22 | [diff] [blame] | 21 | // Make sure we can allocate, access and free memory. |
Eric Holk | b2fa95d | 2017-07-17 18:51:36 | [diff] [blame] | 22 | TEST_F(ArrayBufferTest,AllocateAndFreeBuffer){ |
| 23 | v8::Isolate*const isolate= instance_->isolate(); |
| 24 | v8::ArrayBuffer::Allocator*const allocator= |
| 25 | PerIsolateData::From(isolate)->allocator(); |
| 26 | |
| 27 | void* buffer= allocator->Allocate(kBufferLength); |
Bill Budge | 2ca3514 | 2018-02-21 23:22:22 | [diff] [blame] | 28 | char* buffer0=reinterpret_cast<char*>(buffer); |
| 29 | *buffer0='0';// ASCII zero |
| 30 | CHECK_EQ('0',*buffer0); |
Eric Holk | b2fa95d | 2017-07-17 18:51:36 | [diff] [blame] | 31 | allocator->Free(buffer, kBufferLength); |
| 32 | } |
| 33 | |
Eric Holk | b2fa95d | 2017-07-17 18:51:36 | [diff] [blame] | 34 | }// namespace gin |