Skip to content

Commit 4ee8ac3

Browse files
kvakiljuanarbol
authored andcommitted
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: #44079 (comment) PR-URL: #44091 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Feng Yu <[email protected]> Reviewed-By: Tobias Nießen <[email protected]>
1 parent 2f87ba4 commit 4ee8ac3

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/util.h

+10
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,9 @@ class ArrayBufferViewContents {
496496
public:
497497
ArrayBufferViewContents() = default;
498498

499+
ArrayBufferViewContents(const ArrayBufferViewContents&) = delete;
500+
void operator=(const ArrayBufferViewContents&) = delete;
501+
499502
explicit inline ArrayBufferViewContents(v8::Local<v8::Value> value);
500503
explicit inline ArrayBufferViewContents(v8::Local<v8::Object> value);
501504
explicit inline ArrayBufferViewContents(v8::Local<v8::ArrayBufferView> abv);
@@ -505,6 +508,13 @@ class ArrayBufferViewContents {
505508
inline size_t length() const { return length_; }
506509

507510
private:
511+
// Declaring operator new and delete as deleted is not spec compliant.
512+
// Therefore, declare them private instead to disable dynamic alloc.
513+
void* operator new(size_t size);
514+
void* operator new[](size_t size);
515+
void operator delete(void*, size_t);
516+
void operator delete[](void*, size_t);
517+
508518
T stack_storage_[kStackStorageSize];
509519
T* data_ = nullptr;
510520
size_t length_ = 0;

0 commit comments

Comments
 (0)