Skip to content

Commit 960a209

Browse files
kvakilruyadorno
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 52a516a commit 960a209

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
@@ -498,6 +498,9 @@ class ArrayBufferViewContents {
498498
public:
499499
ArrayBufferViewContents() = default;
500500

501+
ArrayBufferViewContents(const ArrayBufferViewContents&) = delete;
502+
void operator=(const ArrayBufferViewContents&) = delete;
503+
501504
explicit inline ArrayBufferViewContents(v8::Local<v8::Value> value);
502505
explicit inline ArrayBufferViewContents(v8::Local<v8::Object> value);
503506
explicit inline ArrayBufferViewContents(v8::Local<v8::ArrayBufferView> abv);
@@ -507,6 +510,13 @@ class ArrayBufferViewContents {
507510
inline size_t length() const { return length_; }
508511

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

0 commit comments

Comments
 (0)