src: prevent copying ArrayBufferViewContents

It is error-prone to copy or heap-allocate `ArrayBufferViewContents`,
because you might accidentally cause it to exceed the lifetime of its
argument. Let's make it impossible to do so. Fortunately we were not
doing so anywhere already, so this diff is purely defensive.

Refs: https://github.com/nodejs/node/pull/44079#discussion_r934376046
PR-URL: https://github.com/nodejs/node/pull/44091
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Feng Yu <F3n67u@outlook.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
This commit is contained in:
Keyhan Vakil authored and Juan José Arboleda committed 2022-10-11 14:45:11 -05:00
1 parent 2f87ba4e03
commit 4ee8ac3b6b
1 file changed
+10
+10
View File
@@ -496,6 +496,9 @@ class ArrayBufferViewContents {
public:
ArrayBufferViewContents() = default;
ArrayBufferViewContents(const ArrayBufferViewContents&) = delete;
void operator=(const ArrayBufferViewContents&) = delete;
explicit inline ArrayBufferViewContents(v8::Local<v8::Value> value);
explicit inline ArrayBufferViewContents(v8::Local<v8::Object> value);
explicit inline ArrayBufferViewContents(v8::Local<v8::ArrayBufferView> abv);
@@ -505,6 +508,13 @@ class ArrayBufferViewContents {
inline size_t length() const { return length_; }
private:
// Declaring operator new and delete as deleted is not spec compliant.
// Therefore, declare them private instead to disable dynamic alloc.
void* operator new(size_t size);
void* operator new[](size_t size);
void operator delete(void*, size_t);
void operator delete[](void*, size_t);
T stack_storage_[kStackStorageSize];
T* data_ = nullptr;
size_t length_ = 0;