Index: third_party/WebKit/Source/wtf/ArrayBuffer.h |
diff --git a/third_party/WebKit/Source/wtf/ArrayBuffer.h b/third_party/WebKit/Source/wtf/ArrayBuffer.h |
index 38e2a00d1a160e104fc39be3bbc1dffbc7aab01f..4962b4d30ea00ace600b49257e8506d9fd626d07 100644 |
--- a/third_party/WebKit/Source/wtf/ArrayBuffer.h |
+++ b/third_party/WebKit/Source/wtf/ArrayBuffer.h |
@@ -34,24 +34,25 @@ |
namespace WTF { |
-class ArrayBuffer; |
class ArrayBufferView; |
class WTF_EXPORT ArrayBuffer : public RefCounted<ArrayBuffer> { |
public: |
- static inline PassRefPtr<ArrayBuffer> create(unsigned numElements, unsigned elementByteSize); |
- static inline PassRefPtr<ArrayBuffer> create(ArrayBuffer*); |
- static inline PassRefPtr<ArrayBuffer> create(const void* source, unsigned byteLength); |
static inline PassRefPtr<ArrayBuffer> create(ArrayBufferContents&); |
+ static inline PassRefPtr<ArrayBuffer> createOrNull(ArrayBuffer*); |
+ static inline PassRefPtr<ArrayBuffer> createOrNull(const void* source, unsigned byteLength); |
static inline PassRefPtr<ArrayBuffer> createOrNull(unsigned numElements, unsigned elementByteSize); |
+ static inline PassRefPtr<ArrayBuffer> deprecatedCreateOrCrash(const void* source, unsigned byteLength); |
+ static inline PassRefPtr<ArrayBuffer> deprecatedCreateOrCrash(unsigned numElements, unsigned elementByteSize); |
+ |
// Only for use by XMLHttpRequest::responseArrayBuffer and Internals::serializeObject |
// (through DOMArrayBuffer::createUninitialized). |
- static inline PassRefPtr<ArrayBuffer> createUninitialized(unsigned numElements, unsigned elementByteSize); |
+ static inline PassRefPtr<ArrayBuffer> createUninitializedOrNull(unsigned numElements, unsigned elementByteSize); |
- static inline PassRefPtr<ArrayBuffer> createShared(unsigned numElements, unsigned elementByteSize); |
- static inline PassRefPtr<ArrayBuffer> createShared(const void* source, unsigned byteLength); |
+ static inline PassRefPtr<ArrayBuffer> createSharedOrNull(unsigned numElements, unsigned elementByteSize); |
+ static inline PassRefPtr<ArrayBuffer> createSharedOrNull(const void* source, unsigned byteLength); |
inline void* data(); |
inline const void* data() const; |
@@ -59,8 +60,8 @@ public: |
// Creates a new ArrayBuffer object with copy of bytes in this object |
// ranging from |begin| upto but not including |end|. |
- inline PassRefPtr<ArrayBuffer> slice(int begin, int end) const; |
- inline PassRefPtr<ArrayBuffer> slice(int begin) const; |
+ inline PassRefPtr<ArrayBuffer> sliceOrNull(int begin, int end) const; |
+ inline PassRefPtr<ArrayBuffer> sliceOrNull(int begin) const; |
void addView(ArrayBufferView*); |
void removeView(ArrayBufferView*); |
@@ -76,11 +77,10 @@ protected: |
inline explicit ArrayBuffer(ArrayBufferContents&); |
private: |
- static inline PassRefPtr<ArrayBuffer> create(unsigned numElements, unsigned elementByteSize, ArrayBufferContents::InitializationPolicy); |
- static inline PassRefPtr<ArrayBuffer> createOrNull(unsigned numElements, unsigned elementByteSize, ArrayBufferContents::InitializationPolicy); |
- static inline PassRefPtr<ArrayBuffer> createShared(unsigned numElements, unsigned elementByteSize, ArrayBufferContents::InitializationPolicy); |
+ static inline PassRefPtr<ArrayBuffer> create(unsigned numElements, unsigned elementByteSize, ArrayBufferContents::InitializationPolicy, ArrayBufferContents::OutOfMemoryPolicy); |
+ static inline PassRefPtr<ArrayBuffer> createSharedOrNull(unsigned numElements, unsigned elementByteSize, ArrayBufferContents::InitializationPolicy); |
- inline PassRefPtr<ArrayBuffer> sliceImpl(unsigned begin, unsigned end) const; |
+ inline PassRefPtr<ArrayBuffer> sliceOrNullImpl(unsigned begin, unsigned end) const; |
inline unsigned clampIndex(int index) const; |
static inline int clampValue(int x, int left, int right); |
@@ -99,76 +99,81 @@ int ArrayBuffer::clampValue(int x, int left, int right) |
return x; |
} |
-PassRefPtr<ArrayBuffer> ArrayBuffer::create(unsigned numElements, unsigned elementByteSize) |
+PassRefPtr<ArrayBuffer> ArrayBuffer::createOrNull(unsigned numElements, unsigned elementByteSize) |
+{ |
+ return create(numElements, elementByteSize, ArrayBufferContents::ZeroInitialize, ArrayBufferContents::NullDataIfOutOfMemory); |
+} |
+ |
+PassRefPtr<ArrayBuffer> ArrayBuffer::deprecatedCreateOrCrash(unsigned numElements, unsigned elementByteSize) |
{ |
- return create(numElements, elementByteSize, ArrayBufferContents::ZeroInitialize); |
+ return create(numElements, elementByteSize, ArrayBufferContents::ZeroInitialize, ArrayBufferContents::CrashIfOutOfMemory_DEPRECATED); |
} |
-PassRefPtr<ArrayBuffer> ArrayBuffer::create(ArrayBuffer* other) |
+PassRefPtr<ArrayBuffer> ArrayBuffer::createOrNull(ArrayBuffer* other) |
{ |
// TODO(binji): support creating a SharedArrayBuffer by copying another ArrayBuffer? |
ASSERT(!other->isShared()); |
- return ArrayBuffer::create(other->data(), other->byteLength()); |
+ return ArrayBuffer::createOrNull(other->data(), other->byteLength()); |
} |
-PassRefPtr<ArrayBuffer> ArrayBuffer::create(const void* source, unsigned byteLength) |
+PassRefPtr<ArrayBuffer> ArrayBuffer::createOrNull(const void* source, unsigned byteLength) |
{ |
- ArrayBufferContents contents(byteLength, 1, ArrayBufferContents::NotShared, ArrayBufferContents::ZeroInitialize); |
- RELEASE_ASSERT(contents.data()); |
+ ArrayBufferContents contents(byteLength, 1, ArrayBufferContents::NotShared, ArrayBufferContents::ZeroInitialize, ArrayBufferContents::NullDataIfOutOfMemory); |
+ if (!contents.data()) |
+ return nullptr; |
RefPtr<ArrayBuffer> buffer = adoptRef(new ArrayBuffer(contents)); |
memcpy(buffer->data(), source, byteLength); |
return buffer.release(); |
} |
-PassRefPtr<ArrayBuffer> ArrayBuffer::create(ArrayBufferContents& contents) |
-{ |
- RELEASE_ASSERT(contents.data()); |
- return adoptRef(new ArrayBuffer(contents)); |
-} |
- |
-PassRefPtr<ArrayBuffer> ArrayBuffer::createOrNull(unsigned numElements, unsigned elementByteSize) |
+PassRefPtr<ArrayBuffer> ArrayBuffer::deprecatedCreateOrCrash(const void* source, unsigned byteLength) |
{ |
- return createOrNull(numElements, elementByteSize, ArrayBufferContents::ZeroInitialize); |
+ ArrayBufferContents contents(byteLength, 1, ArrayBufferContents::NotShared, ArrayBufferContents::ZeroInitialize, ArrayBufferContents::CrashIfOutOfMemory_DEPRECATED); |
+ ASSERT(contents.data()); |
+ RefPtr<ArrayBuffer> buffer = adoptRef(new ArrayBuffer(contents)); |
+ memcpy(buffer->data(), source, byteLength); |
+ return buffer.release(); |
} |
-PassRefPtr<ArrayBuffer> ArrayBuffer::createUninitialized(unsigned numElements, unsigned elementByteSize) |
+PassRefPtr<ArrayBuffer> ArrayBuffer::create(ArrayBufferContents& contents) |
{ |
- return create(numElements, elementByteSize, ArrayBufferContents::DontInitialize); |
+ RELEASE_ASSERT(contents.data()); |
+ return adoptRef(new ArrayBuffer(contents)); |
} |
-PassRefPtr<ArrayBuffer> ArrayBuffer::create(unsigned numElements, unsigned elementByteSize, ArrayBufferContents::InitializationPolicy policy) |
+PassRefPtr<ArrayBuffer> ArrayBuffer::createUninitializedOrNull(unsigned numElements, unsigned elementByteSize) |
{ |
- ArrayBufferContents contents(numElements, elementByteSize, ArrayBufferContents::NotShared, policy); |
- RELEASE_ASSERT(contents.data()); |
- return adoptRef(new ArrayBuffer(contents)); |
+ return create(numElements, elementByteSize, ArrayBufferContents::DontInitialize, ArrayBufferContents::NullDataIfOutOfMemory); |
} |
-PassRefPtr<ArrayBuffer> ArrayBuffer::createOrNull(unsigned numElements, unsigned elementByteSize, ArrayBufferContents::InitializationPolicy policy) |
+PassRefPtr<ArrayBuffer> ArrayBuffer::create(unsigned numElements, unsigned elementByteSize, ArrayBufferContents::InitializationPolicy initPolicy, ArrayBufferContents::OutOfMemoryPolicy oomPolicy) |
{ |
- ArrayBufferContents contents(numElements, elementByteSize, ArrayBufferContents::NotShared, policy); |
+ ArrayBufferContents contents(numElements, elementByteSize, ArrayBufferContents::NotShared, initPolicy, oomPolicy); |
if (!contents.data()) |
return nullptr; |
return adoptRef(new ArrayBuffer(contents)); |
} |
-PassRefPtr<ArrayBuffer> ArrayBuffer::createShared(unsigned numElements, unsigned elementByteSize) |
+PassRefPtr<ArrayBuffer> ArrayBuffer::createSharedOrNull(unsigned numElements, unsigned elementByteSize) |
{ |
- return createShared(numElements, elementByteSize, ArrayBufferContents::ZeroInitialize); |
+ return createSharedOrNull(numElements, elementByteSize, ArrayBufferContents::ZeroInitialize); |
} |
-PassRefPtr<ArrayBuffer> ArrayBuffer::createShared(const void* source, unsigned byteLength) |
+PassRefPtr<ArrayBuffer> ArrayBuffer::createSharedOrNull(const void* source, unsigned byteLength) |
{ |
- ArrayBufferContents contents(byteLength, 1, ArrayBufferContents::Shared, ArrayBufferContents::ZeroInitialize); |
- RELEASE_ASSERT(contents.data()); |
+ ArrayBufferContents contents(byteLength, 1, ArrayBufferContents::Shared, ArrayBufferContents::ZeroInitialize, ArrayBufferContents::NullDataIfOutOfMemory); |
+ if (!contents.data()) |
+ return nullptr; |
RefPtr<ArrayBuffer> buffer = adoptRef(new ArrayBuffer(contents)); |
memcpy(buffer->data(), source, byteLength); |
return buffer.release(); |
} |
-PassRefPtr<ArrayBuffer> ArrayBuffer::createShared(unsigned numElements, unsigned elementByteSize, ArrayBufferContents::InitializationPolicy policy) |
+PassRefPtr<ArrayBuffer> ArrayBuffer::createSharedOrNull(unsigned numElements, unsigned elementByteSize, ArrayBufferContents::InitializationPolicy policy) |
{ |
- ArrayBufferContents contents(numElements, elementByteSize, ArrayBufferContents::Shared, policy); |
- RELEASE_ASSERT(contents.data()); |
+ ArrayBufferContents contents(numElements, elementByteSize, ArrayBufferContents::Shared, policy, ArrayBufferContents::NullDataIfOutOfMemory); |
+ if (!contents.data()) |
+ return nullptr; |
return adoptRef(new ArrayBuffer(contents)); |
} |
@@ -196,20 +201,20 @@ unsigned ArrayBuffer::byteLength() const |
return m_contents.sizeInBytes(); |
} |
-PassRefPtr<ArrayBuffer> ArrayBuffer::slice(int begin, int end) const |
+PassRefPtr<ArrayBuffer> ArrayBuffer::sliceOrNull(int begin, int end) const |
{ |
- return sliceImpl(clampIndex(begin), clampIndex(end)); |
+ return sliceOrNullImpl(clampIndex(begin), clampIndex(end)); |
} |
-PassRefPtr<ArrayBuffer> ArrayBuffer::slice(int begin) const |
+PassRefPtr<ArrayBuffer> ArrayBuffer::sliceOrNull(int begin) const |
{ |
- return sliceImpl(clampIndex(begin), byteLength()); |
+ return sliceOrNullImpl(clampIndex(begin), byteLength()); |
} |
-PassRefPtr<ArrayBuffer> ArrayBuffer::sliceImpl(unsigned begin, unsigned end) const |
+PassRefPtr<ArrayBuffer> ArrayBuffer::sliceOrNullImpl(unsigned begin, unsigned end) const |
{ |
unsigned size = begin <= end ? end - begin : 0; |
- return ArrayBuffer::create(static_cast<const char*>(data()) + begin, size); |
+ return ArrayBuffer::createOrNull(static_cast<const char*>(data()) + begin, size); |
} |
unsigned ArrayBuffer::clampIndex(int index) const |