Index: Source/wtf/ArrayBuffer.h |
diff --git a/Source/wtf/ArrayBuffer.h b/Source/wtf/ArrayBuffer.h |
index e58f53151817c33a0c7323b2ce89f9d14fcd7416..d13bcb18adf81c3a1106b374ca64d510bbf2c113 100644 |
--- a/Source/wtf/ArrayBuffer.h |
+++ b/Source/wtf/ArrayBuffer.h |
@@ -51,6 +51,9 @@ public: |
// (through DOMArrayBuffer::createUninitialized). |
static inline PassRefPtr<ArrayBuffer> createUninitialized(unsigned numElements, unsigned elementByteSize); |
+ static inline PassRefPtr<ArrayBuffer> createShared(unsigned numElements, unsigned elementByteSize); |
+ static inline PassRefPtr<ArrayBuffer> createShared(const void* source, unsigned byteLength); |
+ |
inline void* data(); |
inline const void* data() const; |
inline unsigned byteLength() const; |
@@ -64,7 +67,8 @@ public: |
void removeView(ArrayBufferView*); |
bool transfer(ArrayBufferContents&); |
- bool isNeutered() { return m_isNeutered; } |
+ bool isNeutered() const { return m_isNeutered; } |
+ bool isShared() const { return m_contents.isShared(); } |
void setDeallocationObserver(ArrayBufferDeallocationObserver& observer) |
{ |
@@ -83,6 +87,7 @@ protected: |
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); |
inline PassRefPtr<ArrayBuffer> sliceImpl(unsigned begin, unsigned end) const; |
inline unsigned clampIndex(int index) const; |
@@ -110,12 +115,14 @@ PassRefPtr<ArrayBuffer> ArrayBuffer::create(unsigned numElements, unsigned eleme |
PassRefPtr<ArrayBuffer> ArrayBuffer::create(ArrayBuffer* other) |
{ |
+ // TODO(binji): support creating a SharedArrayBuffer by copying another ArrayBuffer? |
+ ASSERT(!other->isShared()); |
return ArrayBuffer::create(other->data(), other->byteLength()); |
} |
PassRefPtr<ArrayBuffer> ArrayBuffer::create(const void* source, unsigned byteLength) |
{ |
- ArrayBufferContents contents(byteLength, 1, ArrayBufferContents::ZeroInitialize); |
+ ArrayBufferContents contents(byteLength, 1, ArrayBufferContents::NotShared, ArrayBufferContents::ZeroInitialize); |
RELEASE_ASSERT(contents.data()); |
RefPtr<ArrayBuffer> buffer = adoptRef(new ArrayBuffer(contents)); |
memcpy(buffer->data(), source, byteLength); |
@@ -139,19 +146,40 @@ PassRefPtr<ArrayBuffer> ArrayBuffer::createUninitialized(unsigned numElements, u |
PassRefPtr<ArrayBuffer> ArrayBuffer::create(unsigned numElements, unsigned elementByteSize, ArrayBufferContents::InitializationPolicy policy) |
{ |
- ArrayBufferContents contents(numElements, elementByteSize, policy); |
+ ArrayBufferContents contents(numElements, elementByteSize, ArrayBufferContents::NotShared, policy); |
RELEASE_ASSERT(contents.data()); |
return adoptRef(new ArrayBuffer(contents)); |
} |
PassRefPtr<ArrayBuffer> ArrayBuffer::createOrNull(unsigned numElements, unsigned elementByteSize, ArrayBufferContents::InitializationPolicy policy) |
{ |
- ArrayBufferContents contents(numElements, elementByteSize, policy); |
+ ArrayBufferContents contents(numElements, elementByteSize, ArrayBufferContents::NotShared, policy); |
if (!contents.data()) |
return nullptr; |
return adoptRef(new ArrayBuffer(contents)); |
} |
+PassRefPtr<ArrayBuffer> ArrayBuffer::createShared(unsigned numElements, unsigned elementByteSize) |
+{ |
+ return createShared(numElements, elementByteSize, ArrayBufferContents::ZeroInitialize); |
+} |
+ |
+PassRefPtr<ArrayBuffer> ArrayBuffer::createShared(const void* source, unsigned byteLength) |
+{ |
+ ArrayBufferContents contents(byteLength, 1, ArrayBufferContents::Shared, ArrayBufferContents::ZeroInitialize); |
+ RELEASE_ASSERT(contents.data()); |
haraken
2015/06/11 05:59:29
Any reason to make this a RELEASE assert?
haraken
2015/06/11 05:59:29
Shall we add ASSERT(contents.isShared())?
|
+ 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) |
+{ |
+ ArrayBufferContents contents(numElements, elementByteSize, ArrayBufferContents::Shared, policy); |
+ RELEASE_ASSERT(contents.data()); |
haraken
2015/06/11 05:59:29
Ditto.
|
+ return adoptRef(new ArrayBuffer(contents)); |
+} |
+ |
ArrayBuffer::ArrayBuffer(ArrayBufferContents& contents) |
: m_firstView(0), m_isNeutered(false) |
{ |
@@ -185,6 +213,9 @@ PassRefPtr<ArrayBuffer> ArrayBuffer::slice(int begin) const |
PassRefPtr<ArrayBuffer> ArrayBuffer::sliceImpl(unsigned begin, unsigned end) const |
{ |
+ // TODO(binji): Isn't supported by SharedArrayBuffer, but maybe we don't need to assert? |
+ // If we do support this, make sure to call createShared instead of create below. |
haraken
2015/06/11 05:59:29
I'm just curious but do we need to make the sliced
|
+ ASSERT(!isShared()); |
unsigned size = begin <= end ? end - begin : 0; |
return ArrayBuffer::create(static_cast<const char*>(data()) + begin, size); |
} |