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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 ArrayBufferContents contents(byte_length, 1, ArrayBufferContents::kNotShared, | 138 ArrayBufferContents contents(byte_length, 1, ArrayBufferContents::kNotShared, |
139 ArrayBufferContents::kDontInitialize); | 139 ArrayBufferContents::kDontInitialize); |
140 if (UNLIKELY(!contents.Data())) | 140 if (UNLIKELY(!contents.Data())) |
141 OOM_CRASH(); | 141 OOM_CRASH(); |
142 RefPtr<ArrayBuffer> buffer = AdoptRef(new ArrayBuffer(contents)); | 142 RefPtr<ArrayBuffer> buffer = AdoptRef(new ArrayBuffer(contents)); |
143 memcpy(buffer->Data(), source, byte_length); | 143 memcpy(buffer->Data(), source, byte_length); |
144 return buffer.Release(); | 144 return buffer.Release(); |
145 } | 145 } |
146 | 146 |
147 PassRefPtr<ArrayBuffer> ArrayBuffer::Create(ArrayBufferContents& contents) { | 147 PassRefPtr<ArrayBuffer> ArrayBuffer::Create(ArrayBufferContents& contents) { |
148 RELEASE_ASSERT(contents.DataMaybeShared()); | 148 CHECK(contents.DataMaybeShared()); |
149 return AdoptRef(new ArrayBuffer(contents)); | 149 return AdoptRef(new ArrayBuffer(contents)); |
150 } | 150 } |
151 | 151 |
152 PassRefPtr<ArrayBuffer> ArrayBuffer::CreateOrNull(unsigned num_elements, | 152 PassRefPtr<ArrayBuffer> ArrayBuffer::CreateOrNull(unsigned num_elements, |
153 unsigned element_byte_size) { | 153 unsigned element_byte_size) { |
154 return CreateOrNull(num_elements, element_byte_size, | 154 return CreateOrNull(num_elements, element_byte_size, |
155 ArrayBufferContents::kZeroInitialize); | 155 ArrayBufferContents::kZeroInitialize); |
156 } | 156 } |
157 | 157 |
158 PassRefPtr<ArrayBuffer> ArrayBuffer::CreateUninitializedOrNull( | 158 PassRefPtr<ArrayBuffer> ArrayBuffer::CreateUninitializedOrNull( |
159 unsigned num_elements, | 159 unsigned num_elements, |
160 unsigned element_byte_size) { | 160 unsigned element_byte_size) { |
161 return CreateOrNull(num_elements, element_byte_size, | 161 return CreateOrNull(num_elements, element_byte_size, |
162 ArrayBufferContents::kDontInitialize); | 162 ArrayBufferContents::kDontInitialize); |
163 } | 163 } |
164 | 164 |
165 PassRefPtr<ArrayBuffer> ArrayBuffer::Create( | 165 PassRefPtr<ArrayBuffer> ArrayBuffer::Create( |
166 unsigned num_elements, | 166 unsigned num_elements, |
167 unsigned element_byte_size, | 167 unsigned element_byte_size, |
168 ArrayBufferContents::InitializationPolicy policy) { | 168 ArrayBufferContents::InitializationPolicy policy) { |
169 ArrayBufferContents contents(num_elements, element_byte_size, | 169 ArrayBufferContents contents(num_elements, element_byte_size, |
170 ArrayBufferContents::kNotShared, policy); | 170 ArrayBufferContents::kNotShared, policy); |
171 RELEASE_ASSERT(contents.Data()); | 171 CHECK(contents.Data()); |
172 return AdoptRef(new ArrayBuffer(contents)); | 172 return AdoptRef(new ArrayBuffer(contents)); |
173 } | 173 } |
174 | 174 |
175 PassRefPtr<ArrayBuffer> ArrayBuffer::CreateOrNull( | 175 PassRefPtr<ArrayBuffer> ArrayBuffer::CreateOrNull( |
176 unsigned num_elements, | 176 unsigned num_elements, |
177 unsigned element_byte_size, | 177 unsigned element_byte_size, |
178 ArrayBufferContents::InitializationPolicy policy) { | 178 ArrayBufferContents::InitializationPolicy policy) { |
179 ArrayBufferContents contents(num_elements, element_byte_size, | 179 ArrayBufferContents contents(num_elements, element_byte_size, |
180 ArrayBufferContents::kNotShared, policy); | 180 ArrayBufferContents::kNotShared, policy); |
181 if (!contents.Data()) | 181 if (!contents.Data()) |
182 return nullptr; | 182 return nullptr; |
183 return AdoptRef(new ArrayBuffer(contents)); | 183 return AdoptRef(new ArrayBuffer(contents)); |
184 } | 184 } |
185 | 185 |
186 PassRefPtr<ArrayBuffer> ArrayBuffer::CreateShared(unsigned num_elements, | 186 PassRefPtr<ArrayBuffer> ArrayBuffer::CreateShared(unsigned num_elements, |
187 unsigned element_byte_size) { | 187 unsigned element_byte_size) { |
188 return CreateShared(num_elements, element_byte_size, | 188 return CreateShared(num_elements, element_byte_size, |
189 ArrayBufferContents::kZeroInitialize); | 189 ArrayBufferContents::kZeroInitialize); |
190 } | 190 } |
191 | 191 |
192 PassRefPtr<ArrayBuffer> ArrayBuffer::CreateShared(const void* source, | 192 PassRefPtr<ArrayBuffer> ArrayBuffer::CreateShared(const void* source, |
193 unsigned byte_length) { | 193 unsigned byte_length) { |
194 ArrayBufferContents contents(byte_length, 1, ArrayBufferContents::kShared, | 194 ArrayBufferContents contents(byte_length, 1, ArrayBufferContents::kShared, |
195 ArrayBufferContents::kDontInitialize); | 195 ArrayBufferContents::kDontInitialize); |
196 RELEASE_ASSERT(contents.DataShared()); | 196 CHECK(contents.DataShared()); |
197 RefPtr<ArrayBuffer> buffer = AdoptRef(new ArrayBuffer(contents)); | 197 RefPtr<ArrayBuffer> buffer = AdoptRef(new ArrayBuffer(contents)); |
198 memcpy(buffer->DataShared(), source, byte_length); | 198 memcpy(buffer->DataShared(), source, byte_length); |
199 return buffer.Release(); | 199 return buffer.Release(); |
200 } | 200 } |
201 | 201 |
202 PassRefPtr<ArrayBuffer> ArrayBuffer::CreateShared( | 202 PassRefPtr<ArrayBuffer> ArrayBuffer::CreateShared( |
203 unsigned num_elements, | 203 unsigned num_elements, |
204 unsigned element_byte_size, | 204 unsigned element_byte_size, |
205 ArrayBufferContents::InitializationPolicy policy) { | 205 ArrayBufferContents::InitializationPolicy policy) { |
206 ArrayBufferContents contents(num_elements, element_byte_size, | 206 ArrayBufferContents contents(num_elements, element_byte_size, |
207 ArrayBufferContents::kShared, policy); | 207 ArrayBufferContents::kShared, policy); |
208 RELEASE_ASSERT(contents.DataShared()); | 208 CHECK(contents.DataShared()); |
209 return AdoptRef(new ArrayBuffer(contents)); | 209 return AdoptRef(new ArrayBuffer(contents)); |
210 } | 210 } |
211 | 211 |
212 ArrayBuffer::ArrayBuffer(ArrayBufferContents& contents) | 212 ArrayBuffer::ArrayBuffer(ArrayBufferContents& contents) |
213 : first_view_(0), is_neutered_(false) { | 213 : first_view_(0), is_neutered_(false) { |
214 if (contents.IsShared()) | 214 if (contents.IsShared()) |
215 contents.ShareWith(contents_); | 215 contents.ShareWith(contents_); |
216 else | 216 else |
217 contents.Transfer(contents_); | 217 contents.Transfer(contents_); |
218 } | 218 } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 if (index < 0) | 264 if (index < 0) |
265 index = current_length + index; | 265 index = current_length + index; |
266 return ClampValue(index, 0, current_length); | 266 return ClampValue(index, 0, current_length); |
267 } | 267 } |
268 | 268 |
269 } // namespace WTF | 269 } // namespace WTF |
270 | 270 |
271 using WTF::ArrayBuffer; | 271 using WTF::ArrayBuffer; |
272 | 272 |
273 #endif // ArrayBuffer_h | 273 #endif // ArrayBuffer_h |
OLD | NEW |