Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 960a209

Browse filesBrowse 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 <anna@addaleax.net> Reviewed-By: Feng Yu <F3n67u@outlook.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
1 parent 52a516a commit 960a209
Copy full SHA for 960a209

File tree

Expand file treeCollapse file tree

1 file changed

+10
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+10
-0
lines changed
Open diff view settings
Collapse file

‎src/util.h‎

Copy file name to clipboardExpand all lines: src/util.h
+10Lines changed: 10 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.