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 |
11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
12 * | 12 * |
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #ifndef ArrayBufferView_h | 26 #ifndef ArrayBufferView_h |
27 #define ArrayBufferView_h | 27 #define ArrayBufferView_h |
28 | 28 |
29 #include "wtf/ArrayBuffer.h" | 29 #include "wtf/ArrayBuffer.h" |
30 | 30 |
31 #include <algorithm> | 31 #include <algorithm> |
32 #include <limits.h> | 32 #include <limits.h> |
33 #include "wtf/PassRefPtr.h" | 33 #include "wtf/PassRefPtr.h" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 }; | 138 }; |
139 | 139 |
140 bool ArrayBufferView::setImpl(ArrayBufferView* array, unsigned byteOffset) | 140 bool ArrayBufferView::setImpl(ArrayBufferView* array, unsigned byteOffset) |
141 { | 141 { |
142 if (byteOffset > byteLength() | 142 if (byteOffset > byteLength() |
143 || byteOffset + array->byteLength() > byteLength() | 143 || byteOffset + array->byteLength() > byteLength() |
144 || byteOffset + array->byteLength() < byteOffset) { | 144 || byteOffset + array->byteLength() < byteOffset) { |
145 // Out of range offset or overflow | 145 // Out of range offset or overflow |
146 return false; | 146 return false; |
147 } | 147 } |
148 | 148 |
149 char* base = static_cast<char*>(baseAddress()); | 149 char* base = static_cast<char*>(baseAddress()); |
150 memmove(base + byteOffset, array->baseAddress(), array->byteLength()); | 150 memmove(base + byteOffset, array->baseAddress(), array->byteLength()); |
151 return true; | 151 return true; |
152 } | 152 } |
153 | 153 |
154 bool ArrayBufferView::setRangeImpl(const char* data, size_t dataByteLength, unsi
gned byteOffset) | 154 bool ArrayBufferView::setRangeImpl(const char* data, size_t dataByteLength, unsi
gned byteOffset) |
155 { | 155 { |
156 if (byteOffset > byteLength() | 156 if (byteOffset > byteLength() |
157 || byteOffset + dataByteLength > byteLength() | 157 || byteOffset + dataByteLength > byteLength() |
158 || byteOffset + dataByteLength < byteOffset) { | 158 || byteOffset + dataByteLength < byteOffset) { |
159 // Out of range offset or overflow | 159 // Out of range offset or overflow |
160 return false; | 160 return false; |
161 } | 161 } |
162 | 162 |
163 char* base = static_cast<char*>(baseAddress()); | 163 char* base = static_cast<char*>(baseAddress()); |
164 memmove(base + byteOffset, data, dataByteLength); | 164 memmove(base + byteOffset, data, dataByteLength); |
165 return true; | 165 return true; |
166 } | 166 } |
167 | 167 |
168 bool ArrayBufferView::zeroRangeImpl(unsigned byteOffset, size_t rangeByteLength) | 168 bool ArrayBufferView::zeroRangeImpl(unsigned byteOffset, size_t rangeByteLength) |
169 { | 169 { |
170 if (byteOffset > byteLength() | 170 if (byteOffset > byteLength() |
171 || byteOffset + rangeByteLength > byteLength() | 171 || byteOffset + rangeByteLength > byteLength() |
172 || byteOffset + rangeByteLength < byteOffset) { | 172 || byteOffset + rangeByteLength < byteOffset) { |
173 // Out of range offset or overflow | 173 // Out of range offset or overflow |
174 return false; | 174 return false; |
175 } | 175 } |
176 | 176 |
177 char* base = static_cast<char*>(baseAddress()); | 177 char* base = static_cast<char*>(baseAddress()); |
178 memset(base + byteOffset, 0, rangeByteLength); | 178 memset(base + byteOffset, 0, rangeByteLength); |
179 return true; | 179 return true; |
180 } | 180 } |
181 | 181 |
182 void ArrayBufferView::calculateOffsetAndLength(int start, int end, unsigned arra
ySize, | 182 void ArrayBufferView::calculateOffsetAndLength(int start, int end, unsigned arra
ySize, |
183 unsigned* offset, unsigned* lengt
h) | 183 unsigned* offset, unsigned* lengt
h) |
184 { | 184 { |
185 if (start < 0) | 185 if (start < 0) |
186 start += arraySize; | 186 start += arraySize; |
187 if (start < 0) | 187 if (start < 0) |
188 start = 0; | 188 start = 0; |
189 if (end < 0) | 189 if (end < 0) |
190 end += arraySize; | 190 end += arraySize; |
191 if (end < 0) | 191 if (end < 0) |
192 end = 0; | 192 end = 0; |
193 if (static_cast<unsigned>(end) > arraySize) | 193 if (static_cast<unsigned>(end) > arraySize) |
194 end = arraySize; | 194 end = arraySize; |
195 if (end < start) | 195 if (end < start) |
196 end = start; | 196 end = start; |
197 *offset = static_cast<unsigned>(start); | 197 *offset = static_cast<unsigned>(start); |
198 *length = static_cast<unsigned>(end - start); | 198 *length = static_cast<unsigned>(end - start); |
199 } | 199 } |
200 | 200 |
201 } // namespace WTF | 201 } // namespace WTF |
202 | 202 |
203 using WTF::ArrayBufferView; | 203 using WTF::ArrayBufferView; |
204 | 204 |
205 #endif // ArrayBufferView_h | 205 #endif // ArrayBufferView_h |
OLD | NEW |