Index: Source/wtf/ArrayBuffer.h |
diff --git a/Source/wtf/ArrayBuffer.h b/Source/wtf/ArrayBuffer.h |
index d83dd2e7b062e91cdb907ccfa14a9849bc79ea71..675ee57f47d47b6dcf400e3b3df16db8b5b28f7d 100644 |
--- a/Source/wtf/ArrayBuffer.h |
+++ b/Source/wtf/ArrayBuffer.h |
@@ -44,6 +44,16 @@ public: |
static inline PassRefPtr<ArrayBuffer> create(const void* source, unsigned byteLength); |
static inline PassRefPtr<ArrayBuffer> create(ArrayBufferContents&); |
+ // Create an ArrayBuffer for an existing piece of memory with no copying. |
+ // The ArrayBuffer does not take ownership of the passed-in memory and care |
+ // must be taken to not deallocate the data before the ArrayBuffer has been |
+ // deallocated. |
+ // |
+ // FIXME: This should be removed when pointers into the JS/Dart heap can |
+ // can be passed directly. |
+ static inline PassRefPtr<ArrayBuffer> createNoCopy(void* source, unsigned byteLength); |
+ |
+ // Only for use by Uint8ClampedArray::createUninitialized and SharedBuffer::getAsArrayBuffer. |
static inline PassRefPtr<ArrayBuffer> createOrNull(unsigned numElements, unsigned elementByteSize); |
// Only for use by XMLHttpRequest::responseArrayBuffer and Internals::serializeObject |
@@ -120,6 +130,13 @@ PassRefPtr<ArrayBuffer> ArrayBuffer::create(const void* source, unsigned byteLen |
return buffer.release(); |
} |
+PassRefPtr<ArrayBuffer> ArrayBuffer::createNoCopy(void* source, unsigned byteLength) |
+{ |
+ // FIXME: What do we pass in for a DeallocationObserver? |
+ ArrayBufferContents contents(source, byteLength, ArrayBufferContents::SharingType::NotShared); |
+ return adoptRef(new ArrayBuffer(contents)); |
+} |
+ |
PassRefPtr<ArrayBuffer> ArrayBuffer::create(ArrayBufferContents& contents) |
{ |
RELEASE_ASSERT(contents.data()); |
@@ -175,7 +192,10 @@ PassRefPtr<ArrayBuffer> ArrayBuffer::createShared(unsigned numElements, unsigned |
ArrayBuffer::ArrayBuffer(ArrayBufferContents& contents) |
: m_firstView(0), m_isNeutered(false) |
{ |
- contents.transfer(m_contents); |
+ if (contents.isShared()) |
+ contents.shareWith(m_contents); |
+ else |
+ contents.transfer(m_contents); |
} |
void* ArrayBuffer::data() |