Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2019-03-08 18:19:33 +0300
committerAnna Henningsen <anna@addaleax.net>2019-03-13 12:14:14 +0300
commit0e3adddd0d6e5d90b5224c62ef26b561320d1cff (patch)
tree919a9a4555026d9d04395f8695c2aebd2c380424 /src/node.h
parent17ab2ed3c885d75ee13286cd31c14ea136d00918 (diff)
embedding: refactor public `ArrayBufferAllocator` API
Use a RAII approach by default, and make it possible for embedders to use the `ArrayBufferAllocator` directly as a V8 `ArrayBuffer::Allocator`, e.g. when passing to `Isolate::CreateParams` manually. PR-URL: https://github.com/nodejs/node/pull/26525 Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Diffstat (limited to 'src/node.h')
-rw-r--r--src/node.h26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/node.h b/src/node.h
index 9ccab2e0f81..3aaaf43668b 100644
--- a/src/node.h
+++ b/src/node.h
@@ -64,6 +64,8 @@
#include "v8-platform.h" // NOLINT(build/include_order)
#include "node_version.h" // NODE_MODULE_VERSION
+#include <memory>
+
#define NODE_MAKE_VERSION(major, minor, patch) \
((major) * 0x1000 + (minor) * 0x100 + (patch))
@@ -210,8 +212,30 @@ NODE_EXTERN void Init(int* argc,
int* exec_argc,
const char*** exec_argv);
-class ArrayBufferAllocator;
+class NodeArrayBufferAllocator;
+
+// An ArrayBuffer::Allocator class with some Node.js-specific tweaks. If you do
+// not have to use another allocator, using this class is recommended:
+// - It supports Buffer.allocUnsafe() and Buffer.allocUnsafeSlow() with
+// uninitialized memory.
+// - It supports transferring, rather than copying, ArrayBuffers when using
+// MessagePorts.
+class NODE_EXTERN ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
+ public:
+ // If `always_debug` is true, create an ArrayBuffer::Allocator instance
+ // that performs additional integrity checks (e.g. make sure that only memory
+ // that was allocated by the it is also freed by it).
+ // This can also be set using the --debug-arraybuffer-allocations flag.
+ static std::unique_ptr<ArrayBufferAllocator> Create(
+ bool always_debug = false);
+
+ private:
+ virtual NodeArrayBufferAllocator* GetImpl() = 0;
+
+ friend class IsolateData;
+};
+// Legacy equivalents for ArrayBufferAllocator::Create().
NODE_EXTERN ArrayBufferAllocator* CreateArrayBufferAllocator();
NODE_EXTERN void FreeArrayBufferAllocator(ArrayBufferAllocator* allocator);