From 3f8ee5e6b4e42fc77b4716b23ccd00840e24e250 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Fri, 9 Feb 2018 18:26:09 +0000 Subject: Move CFX_V8 testing from embeddertest to unittest. Test the lowest layer without firing up the whole library. Requires firing up v8 in the unit test main, though. Move array buffer allocator to cfx_v8 to allow building isolates. Change-Id: I9a56d503a48e0e555d3310f2997fa12137695860 Reviewed-on: https://pdfium-review.googlesource.com/26130 Commit-Queue: Tom Sepez Reviewed-by: dsinclair --- fxjs/cfx_v8.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'fxjs/cfx_v8.cpp') diff --git a/fxjs/cfx_v8.cpp b/fxjs/cfx_v8.cpp index 80b9eda47c..4738030236 100644 --- a/fxjs/cfx_v8.cpp +++ b/fxjs/cfx_v8.cpp @@ -6,6 +6,9 @@ #include "fxjs/cfx_v8.h" +#include "core/fxcrt/fx_memory.h" +#include "third_party/base/allocator/partition_allocator/partition_alloc.h" + CFX_V8::CFX_V8(v8::Isolate* isolate) : m_isolate(isolate) {} CFX_V8::~CFX_V8() = default; @@ -194,3 +197,24 @@ v8::Local CFX_V8::ToArray(v8::Local pValue) { v8::Local context = m_isolate->GetCurrentContext(); return v8::Local::Cast(pValue->ToObject(context).ToLocalChecked()); } + +void* CFX_V8ArrayBufferAllocator::Allocate(size_t length) { + if (length > kMaxAllowedBytes) + return nullptr; + void* p = AllocateUninitialized(length); + if (p) + memset(p, 0, length); + return p; +} + +void* CFX_V8ArrayBufferAllocator::AllocateUninitialized(size_t length) { + if (length > kMaxAllowedBytes) + return nullptr; + return pdfium::base::PartitionAllocGeneric( + gArrayBufferPartitionAllocator.root(), length, "CFX_V8ArrayBuffer"); +} + +void CFX_V8ArrayBufferAllocator::Free(void* data, size_t length) { + pdfium::base::PartitionFreeGeneric(gArrayBufferPartitionAllocator.root(), + data); +} -- cgit v1.2.3