xref: /aosp_15_r20/external/pdfium/fxjs/cfx_v8_array_buffer_allocator.h (revision 3ac0a46f773bac49fa9476ec2b1cf3f8da5ec3a4)
1 // Copyright 2021 The PDFium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 
7 #ifndef FXJS_CFX_V8_ARRAY_BUFFER_ALLOCATOR_H_
8 #define FXJS_CFX_V8_ARRAY_BUFFER_ALLOCATOR_H_
9 
10 #include <stddef.h>
11 
12 #include <memory>
13 
14 #include "v8/include/v8-array-buffer.h"
15 
16 class CFX_V8ArrayBufferAllocator final : public v8::ArrayBuffer::Allocator {
17  public:
18   static const size_t kMaxAllowedBytes = 0x10000000;
19 
20   CFX_V8ArrayBufferAllocator();
21   CFX_V8ArrayBufferAllocator(const CFX_V8ArrayBufferAllocator&) = delete;
22   CFX_V8ArrayBufferAllocator(CFX_V8ArrayBufferAllocator&&) = delete;
23   ~CFX_V8ArrayBufferAllocator() override;
24 
25   void* Allocate(size_t length) override;
26   void* AllocateUninitialized(size_t length) override;
27   void Free(void* data, size_t length) override;
28 
29 #ifdef V8_ENABLE_SANDBOX
30  private:
31   std::unique_ptr<v8::ArrayBuffer::Allocator> wrapped_;
32 #endif  // V8_ENABLE_SANDBOX
33 };
34 
35 #endif  // FXJS_CFX_V8_ARRAY_BUFFER_ALLOCATOR_H_
36