Chromium Code Reviews| Index: third_party/WebKit/Source/wtf/ArrayBufferContents.h |
| diff --git a/third_party/WebKit/Source/wtf/ArrayBufferContents.h b/third_party/WebKit/Source/wtf/ArrayBufferContents.h |
| index d5b4fc304c7beb60549620322c4e9517f9c22962..af933fffc243dc759e37adc8d654454d34e5b84a 100644 |
| --- a/third_party/WebKit/Source/wtf/ArrayBufferContents.h |
| +++ b/third_party/WebKit/Source/wtf/ArrayBufferContents.h |
| @@ -49,15 +49,29 @@ public: |
| Shared, |
| }; |
| + enum OutOfMemoryPolicy { |
| + // CrashIfOutOfMemory_DEPRECATED should never be used inside the |
| + // scope of a script execution context, and is deprecated for all other |
| + // uses. |
| + CrashIfOutOfMemory_DEPRECATED, |
| + // When using the NullDataIfOutOfMemory policy in the scope of a |
| + // script context, a RangeError DOM exception must be thrown |
| + // if the ArrayBufferContents' data is null (allocation failed). |
| + // Spec: http://ecma-international.org/ecma-262/6.0/#sec-createbytedatablock |
| + // However, an exception must *not* be thrown if the requested buffer size |
| + // was 0 bytes, which also results in a null data pointer. |
| + NullDataIfOutOfMemory, |
| + }; |
| + |
| ArrayBufferContents(); |
| - ArrayBufferContents(unsigned numElements, unsigned elementByteSize, SharingType isShared, ArrayBufferContents::InitializationPolicy); |
| + ArrayBufferContents(unsigned numElements, unsigned elementByteSize, SharingType isShared, InitializationPolicy, OutOfMemoryPolicy); |
| // 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(void* data, unsigned sizeInBytes, SharingType, OutOfMemoryPolicy); |
| ~ArrayBufferContents(); |
| @@ -69,15 +83,20 @@ public: |
| void transfer(ArrayBufferContents& other); |
| void shareWith(ArrayBufferContents& other); |
| - void copyTo(ArrayBufferContents& other); |
| + void copyTo(ArrayBufferContents& other, OutOfMemoryPolicy); |
| - static void allocateMemory(size_t, InitializationPolicy, void*&); |
| + static void deprecatedAllocateMemoryOrCrash(size_t, InitializationPolicy, void*& data); |
| + static void allocateMemoryOrNull(size_t, InitializationPolicy, void*& data); |
| static void freeMemory(void*, size_t); |
| static void setAdjustAmoutOfExternalAllocatedMemoryFunction(AdjustAmountOfExternalAllocatedMemoryFunction function) |
| { |
| ASSERT(!s_adjustAmountOfExternalAllocatedMemoryFunction); |
| s_adjustAmountOfExternalAllocatedMemoryFunction = function; |
| } |
| + static void fakeOutOfMemoryForNextArrayBufferAllocation() |
|
binji
2015/10/16 22:12:39
I don't really know the coding standard for Blink,
Justin Novosad
2015/10/19 16:42:52
Acknowledged.
|
| + { |
| + s_fakeAllocationFailureForTestingOneTime = true; |
| + } |
| private: |
| class DataHolder : public ThreadSafeRefCounted<DataHolder> { |
| @@ -86,9 +105,9 @@ private: |
| DataHolder(); |
| ~DataHolder(); |
| - void allocateNew(unsigned sizeInBytes, SharingType isShared, InitializationPolicy); |
| + void allocateNew(unsigned sizeInBytes, SharingType, InitializationPolicy, OutOfMemoryPolicy); |
| void adopt(void* data, unsigned sizeInBytes, SharingType isShared); |
| - void copyMemoryTo(DataHolder& other); |
| + void copyMemoryTo(DataHolder& other, OutOfMemoryPolicy); |
| void* data() const { return m_data; } |
| unsigned sizeInBytes() const { return m_sizeInBytes; } |
| @@ -102,6 +121,7 @@ private: |
| RefPtr<DataHolder> m_holder; |
| static AdjustAmountOfExternalAllocatedMemoryFunction s_adjustAmountOfExternalAllocatedMemoryFunction; |
| + static bool s_fakeAllocationFailureForTestingOneTime; |
| }; |
| } // namespace WTF |