Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(743)

Unified Diff: third_party/WebKit/Source/wtf/ArrayBufferContents.h

Issue 1414553002: Fix out-of-memory crashes related to ArrayBuffer allocation Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase+more tweaks Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..0f0b09147723037967d42a8c19653c94a2b50656 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 fakeOutOfMemoryForNextArrayBufferAllocationForTesting()
+ {
+ 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
« no previous file with comments | « third_party/WebKit/Source/wtf/ArrayBufferBuilder.cpp ('k') | third_party/WebKit/Source/wtf/ArrayBufferContents.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698