blob: b19ff7bcfb9faa4d3d463a155af42e12035b06ab [file] [log] [blame]
Eric Holkb2fa95d2017-07-17 18:51:361// 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 Holkb2fa95d2017-07-17 18:51:3611namespace gin {
12
13using ArrayBufferTest = V8Test;
14
15namespace {
16const size_t kBufferLength = 65536;
17}
18
Bill Budge2ca35142018-02-21 23:22:2219// Make sure we can allocate, access and free memory.
Eric Holkb2fa95d2017-07-17 18:51:3620TEST_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 Budge2ca35142018-02-21 23:22:2226 char* buffer0 = reinterpret_cast<char*>(buffer);
27 *buffer0 = '0'; // ASCII zero
28 CHECK_EQ('0', *buffer0);
Eric Holkb2fa95d2017-07-17 18:51:3629 allocator->Free(buffer, kBufferLength);
30}
31
Eric Holkb2fa95d2017-07-17 18:51:3632} // namespace gin