array_buffer_unittest.cc 917 B

1234567891011121314151617181920212223242526272829303132
  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. #include "gin/array_buffer.h"
  5. #include "build/build_config.h"
  6. #include "gin/per_isolate_data.h"
  7. #include "gin/public/isolate_holder.h"
  8. #include "gin/test/v8_test.h"
  9. namespace gin {
  10. using ArrayBufferTest = V8Test;
  11. namespace {
  12. const size_t kBufferLength = 65536;
  13. }
  14. // Make sure we can allocate, access and free memory.
  15. TEST_F(ArrayBufferTest, AllocateAndFreeBuffer) {
  16. v8::Isolate* const isolate = instance_->isolate();
  17. v8::ArrayBuffer::Allocator* const allocator =
  18. PerIsolateData::From(isolate)->allocator();
  19. void* buffer = allocator->Allocate(kBufferLength);
  20. char* buffer0 = reinterpret_cast<char*>(buffer);
  21. *buffer0 = '0'; // ASCII zero
  22. CHECK_EQ('0', *buffer0);
  23. allocator->Free(buffer, kBufferLength);
  24. }
  25. } // namespace gin