| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2009 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 inline const void* data() const; | 53 inline const void* data() const; |
| 54 inline unsigned byteLength() const; | 54 inline unsigned byteLength() const; |
| 55 | 55 |
| 56 inline PassRefPtr<ArrayBuffer> slice(int begin, int end) const; | 56 inline PassRefPtr<ArrayBuffer> slice(int begin, int end) const; |
| 57 inline PassRefPtr<ArrayBuffer> slice(int begin) const; | 57 inline PassRefPtr<ArrayBuffer> slice(int begin) const; |
| 58 | 58 |
| 59 void addView(ArrayBufferView*); | 59 void addView(ArrayBufferView*); |
| 60 void removeView(ArrayBufferView*); | 60 void removeView(ArrayBufferView*); |
| 61 | 61 |
| 62 bool transfer(ArrayBufferContents&, Vector<RefPtr<ArrayBufferView> >& neuter
edViews); | 62 bool transfer(ArrayBufferContents&, Vector<RefPtr<ArrayBufferView> >& neuter
edViews); |
| 63 bool isNeutered() { return m_isNeutered; } | 63 bool isNeutered() { return !m_contents.data(); } |
| 64 | 64 |
| 65 bool hasDeallocationObserver() { return m_contents.hasDeallocationObserver()
; } | 65 bool hasDeallocationObserver() { return m_contents.hasDeallocationObserver()
; } |
| 66 void setDeallocationObserver(ArrayBufferDeallocationObserver* observer) { m_
contents.setDeallocationObserver(observer); } | 66 void setDeallocationObserver(ArrayBufferDeallocationObserver* observer) { m_
contents.setDeallocationObserver(observer); } |
| 67 | 67 |
| 68 ~ArrayBuffer() { } | 68 ~ArrayBuffer() { } |
| 69 | 69 |
| 70 private: | 70 private: |
| 71 static inline PassRefPtr<ArrayBuffer> create(unsigned numElements, unsigned
elementByteSize, ArrayBufferContents::InitializationPolicy); | 71 static inline PassRefPtr<ArrayBuffer> create(unsigned numElements, unsigned
elementByteSize, ArrayBufferContents::InitializationPolicy); |
| 72 | 72 |
| 73 inline ArrayBuffer(ArrayBufferContents&); | 73 inline ArrayBuffer(ArrayBufferContents&); |
| 74 inline PassRefPtr<ArrayBuffer> sliceImpl(unsigned begin, unsigned end) const
; | 74 inline PassRefPtr<ArrayBuffer> sliceImpl(unsigned begin, unsigned end) const
; |
| 75 inline unsigned clampIndex(int index) const; | 75 inline unsigned clampIndex(int index) const; |
| 76 static inline int clampValue(int x, int left, int right); | 76 static inline int clampValue(int x, int left, int right); |
| 77 | 77 |
| 78 ArrayBufferContents m_contents; | 78 ArrayBufferContents m_contents; |
| 79 ArrayBufferView* m_firstView; | 79 ArrayBufferView* m_firstView; |
| 80 bool m_isNeutered; | |
| 81 }; | 80 }; |
| 82 | 81 |
| 83 int ArrayBuffer::clampValue(int x, int left, int right) | 82 int ArrayBuffer::clampValue(int x, int left, int right) |
| 84 { | 83 { |
| 85 ASSERT(left <= right); | 84 ASSERT(left <= right); |
| 86 if (x < left) | 85 if (x < left) |
| 87 x = left; | 86 x = left; |
| 88 if (right < x) | 87 if (right < x) |
| 89 x = right; | 88 x = right; |
| 90 return x; | 89 return x; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 | 121 |
| 123 PassRefPtr<ArrayBuffer> ArrayBuffer::create(unsigned numElements, unsigned eleme
ntByteSize, ArrayBufferContents::InitializationPolicy policy) | 122 PassRefPtr<ArrayBuffer> ArrayBuffer::create(unsigned numElements, unsigned eleme
ntByteSize, ArrayBufferContents::InitializationPolicy policy) |
| 124 { | 123 { |
| 125 ArrayBufferContents contents(numElements, elementByteSize, policy); | 124 ArrayBufferContents contents(numElements, elementByteSize, policy); |
| 126 if (!contents.data()) | 125 if (!contents.data()) |
| 127 return 0; | 126 return 0; |
| 128 return adoptRef(new ArrayBuffer(contents)); | 127 return adoptRef(new ArrayBuffer(contents)); |
| 129 } | 128 } |
| 130 | 129 |
| 131 ArrayBuffer::ArrayBuffer(ArrayBufferContents& contents) | 130 ArrayBuffer::ArrayBuffer(ArrayBufferContents& contents) |
| 132 : m_firstView(0), m_isNeutered(false) | 131 : m_firstView(0) |
| 133 { | 132 { |
| 134 contents.transfer(m_contents); | 133 contents.transfer(m_contents); |
| 135 } | 134 } |
| 136 | 135 |
| 137 void* ArrayBuffer::data() | 136 void* ArrayBuffer::data() |
| 138 { | 137 { |
| 139 return m_contents.data(); | 138 return m_contents.data(); |
| 140 } | 139 } |
| 141 | 140 |
| 142 const void* ArrayBuffer::data() const | 141 const void* ArrayBuffer::data() const |
| (...skipping 28 matching lines...) Expand all Loading... |
| 171 if (index < 0) | 170 if (index < 0) |
| 172 index = currentLength + index; | 171 index = currentLength + index; |
| 173 return clampValue(index, 0, currentLength); | 172 return clampValue(index, 0, currentLength); |
| 174 } | 173 } |
| 175 | 174 |
| 176 } // namespace WTF | 175 } // namespace WTF |
| 177 | 176 |
| 178 using WTF::ArrayBuffer; | 177 using WTF::ArrayBuffer; |
| 179 | 178 |
| 180 #endif // ArrayBuffer_h | 179 #endif // ArrayBuffer_h |
| OLD | NEW |