Index: third_party/WebKit/Source/wtf/typed_arrays/ArrayBufferContents.h |
diff --git a/third_party/WebKit/Source/wtf/typed_arrays/ArrayBufferContents.h b/third_party/WebKit/Source/wtf/typed_arrays/ArrayBufferContents.h |
index 6c5b54af6ccaca9b1ed15abfbb3f9af9c06074a9..1e125030dff11d6ddd40c4d8b35b7441a21277ae 100644 |
--- a/third_party/WebKit/Source/wtf/typed_arrays/ArrayBufferContents.h |
+++ b/third_party/WebKit/Source/wtf/typed_arrays/ArrayBufferContents.h |
@@ -43,6 +43,8 @@ class WTF_EXPORT ArrayBufferContents { |
public: |
using AdjustAmountOfExternalAllocatedMemoryFunction = void (*)(int64_t diff); |
+ using DataDeleter = void (*)(void* data); |
+ using ScopedData = std::unique_ptr<void, DataDeleter>; |
jbroman
2017/02/28 20:01:19
A brief comment about the expected usage of this (
alokp
2017/02/28 20:56:08
Done.
|
enum InitializationPolicy { ZeroInitialize, DontInitialize }; |
@@ -56,13 +58,7 @@ class WTF_EXPORT ArrayBufferContents { |
unsigned elementByteSize, |
SharingType isShared, |
InitializationPolicy); |
- |
- // Use with care. data must be allocated with allocateMemory. |
- // ArrayBufferContents will take ownership of the data and free it (using |
- // freeMemory) upon destruction. |
- // This constructor will not call observer->StartObserving(), so it is a |
- // responsibility of the caller to make sure JS knows about external memory. |
- ArrayBufferContents(void* data, unsigned sizeInBytes, SharingType isShared); |
+ ArrayBufferContents(ScopedData, unsigned sizeInBytes, SharingType isShared); |
~ArrayBufferContents(); |
@@ -88,9 +84,9 @@ class WTF_EXPORT ArrayBufferContents { |
void shareWith(ArrayBufferContents& other); |
void copyTo(ArrayBufferContents& other); |
- static void allocateMemory(size_t, InitializationPolicy, void*&); |
- static void allocateMemoryOrNull(size_t, InitializationPolicy, void*&); |
- static void freeMemory(void*, size_t); |
+ static void* allocateMemory(size_t, InitializationPolicy); |
jbroman
2017/02/28 20:01:19
Possible bikeshed: but for most callers it might a
alokp
2017/02/28 20:56:08
Good idea. Although it would be a bit weird to not
|
+ static void* allocateMemoryOrNull(size_t, InitializationPolicy); |
+ static void freeMemory(void*); |
static void initialize( |
AdjustAmountOfExternalAllocatedMemoryFunction function) { |
DCHECK(isMainThread()); |
@@ -100,10 +96,7 @@ class WTF_EXPORT ArrayBufferContents { |
} |
private: |
- static void allocateMemoryWithFlags(size_t, |
- InitializationPolicy, |
- int, |
- void*&); |
+ static void* allocateMemoryWithFlags(size_t, InitializationPolicy, int); |
static void defaultAdjustAmountOfExternalAllocatedMemoryFunction( |
int64_t diff); |
@@ -118,11 +111,11 @@ class WTF_EXPORT ArrayBufferContents { |
void allocateNew(unsigned sizeInBytes, |
SharingType isShared, |
InitializationPolicy); |
- void adopt(void* data, unsigned sizeInBytes, SharingType isShared); |
+ void adopt(ScopedData, unsigned sizeInBytes, SharingType isShared); |
void copyMemoryFrom(const DataHolder& source); |
- const void* data() const { return m_data; } |
- void* data() { return m_data; } |
+ const void* data() const { return m_data.get(); } |
+ void* data() { return m_data.get(); } |
unsigned sizeInBytes() const { return m_sizeInBytes; } |
bool isShared() const { return m_isShared == Shared; } |
@@ -150,7 +143,7 @@ class WTF_EXPORT ArrayBufferContents { |
#endif |
} |
- void* m_data; |
+ ScopedData m_data; |
unsigned m_sizeInBytes; |
SharingType m_isShared; |
}; |