Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(404)

Side by Side Diff: third_party/WebKit/Source/modules/webaudio/AudioBuffer.cpp

Issue 2707243006: [SharedArrayBuffer] Prevent SharedArrayBuffer being used in Web APIs (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google 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 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 return getChannelData(channelIndex); 196 return getChannelData(channelIndex);
197 } 197 }
198 198
199 DOMFloat32Array* AudioBuffer::getChannelData(unsigned channelIndex) { 199 DOMFloat32Array* AudioBuffer::getChannelData(unsigned channelIndex) {
200 if (channelIndex >= m_channels.size()) 200 if (channelIndex >= m_channels.size())
201 return nullptr; 201 return nullptr;
202 202
203 return m_channels[channelIndex].get(); 203 return m_channels[channelIndex].get();
204 } 204 }
205 205
206 void AudioBuffer::copyFromChannel(DOMFloat32Array* destination, 206 void AudioBuffer::copyFromChannel(
207 long channelNumber, 207 const MaybeShared<DOMFloat32Array>& destination,
208 ExceptionState& exceptionState) { 208 long channelNumber,
209 ExceptionState& exceptionState) {
209 return copyFromChannel(destination, channelNumber, 0, exceptionState); 210 return copyFromChannel(destination, channelNumber, 0, exceptionState);
210 } 211 }
211 212
212 void AudioBuffer::copyFromChannel(DOMFloat32Array* destination, 213 void AudioBuffer::copyFromChannel(
213 long channelNumber, 214 const MaybeShared<DOMFloat32Array>& destination,
214 unsigned long startInChannel, 215 long channelNumber,
215 ExceptionState& exceptionState) { 216 unsigned long startInChannel,
217 ExceptionState& exceptionState) {
216 if (channelNumber < 0 || 218 if (channelNumber < 0 ||
217 channelNumber >= static_cast<long>(m_channels.size())) { 219 channelNumber >= static_cast<long>(m_channels.size())) {
218 exceptionState.throwDOMException( 220 exceptionState.throwDOMException(
219 IndexSizeError, ExceptionMessages::indexOutsideRange( 221 IndexSizeError, ExceptionMessages::indexOutsideRange(
220 "channelNumber", channelNumber, 0L, 222 "channelNumber", channelNumber, 0L,
221 ExceptionMessages::InclusiveBound, 223 ExceptionMessages::InclusiveBound,
222 static_cast<long>(m_channels.size() - 1), 224 static_cast<long>(m_channels.size() - 1),
223 ExceptionMessages::InclusiveBound)); 225 ExceptionMessages::InclusiveBound));
224 return; 226 return;
225 } 227 }
226 228
227 DOMFloat32Array* channelData = m_channels[channelNumber].get(); 229 DOMFloat32Array* channelData = m_channels[channelNumber].get();
228 230
229 if (startInChannel >= channelData->length()) { 231 if (startInChannel >= channelData->length()) {
230 exceptionState.throwDOMException( 232 exceptionState.throwDOMException(
231 IndexSizeError, ExceptionMessages::indexOutsideRange( 233 IndexSizeError, ExceptionMessages::indexOutsideRange(
232 "startInChannel", startInChannel, 0UL, 234 "startInChannel", startInChannel, 0UL,
233 ExceptionMessages::InclusiveBound, 235 ExceptionMessages::InclusiveBound,
234 static_cast<unsigned long>(channelData->length()), 236 static_cast<unsigned long>(channelData->length()),
235 ExceptionMessages::ExclusiveBound)); 237 ExceptionMessages::ExclusiveBound));
236 238
237 return; 239 return;
238 } 240 }
239 241
242 if (destination.isShared()) {
243 exceptionState.throwTypeError(
244 "destination can not be backed by a SharedArrayBuffer.");
245 return;
246 }
247
240 unsigned count = channelData->length() - startInChannel; 248 unsigned count = channelData->length() - startInChannel;
241 count = std::min(destination->length(), count); 249 count = std::min(destination.viewNotShared()->length(), count);
242 250
243 const float* src = channelData->data(); 251 const float* src = channelData->data();
244 float* dst = destination->data(); 252 float* dst = destination.viewNotShared()->data();
245 253
246 DCHECK(src); 254 DCHECK(src);
247 DCHECK(dst); 255 DCHECK(dst);
248 256
249 memcpy(dst, src + startInChannel, count * sizeof(*src)); 257 memcpy(dst, src + startInChannel, count * sizeof(*src));
250 } 258 }
251 259
252 void AudioBuffer::copyToChannel(DOMFloat32Array* source, 260 void AudioBuffer::copyToChannel(const MaybeShared<DOMFloat32Array>& source,
253 long channelNumber, 261 long channelNumber,
254 ExceptionState& exceptionState) { 262 ExceptionState& exceptionState) {
255 return copyToChannel(source, channelNumber, 0, exceptionState); 263 return copyToChannel(source, channelNumber, 0, exceptionState);
256 } 264 }
257 265
258 void AudioBuffer::copyToChannel(DOMFloat32Array* source, 266 void AudioBuffer::copyToChannel(const MaybeShared<DOMFloat32Array>& source,
259 long channelNumber, 267 long channelNumber,
260 unsigned long startInChannel, 268 unsigned long startInChannel,
261 ExceptionState& exceptionState) { 269 ExceptionState& exceptionState) {
262 if (channelNumber < 0 || 270 if (channelNumber < 0 ||
263 channelNumber >= static_cast<long>(m_channels.size())) { 271 channelNumber >= static_cast<long>(m_channels.size())) {
264 exceptionState.throwDOMException( 272 exceptionState.throwDOMException(
265 IndexSizeError, ExceptionMessages::indexOutsideRange( 273 IndexSizeError, ExceptionMessages::indexOutsideRange(
266 "channelNumber", channelNumber, 0L, 274 "channelNumber", channelNumber, 0L,
267 ExceptionMessages::InclusiveBound, 275 ExceptionMessages::InclusiveBound,
268 static_cast<long>(m_channels.size() - 1), 276 static_cast<long>(m_channels.size() - 1),
269 ExceptionMessages::InclusiveBound)); 277 ExceptionMessages::InclusiveBound));
270 return; 278 return;
271 } 279 }
272 280
273 DOMFloat32Array* channelData = m_channels[channelNumber].get(); 281 DOMFloat32Array* channelData = m_channels[channelNumber].get();
274 282
275 if (startInChannel >= channelData->length()) { 283 if (startInChannel >= channelData->length()) {
276 exceptionState.throwDOMException( 284 exceptionState.throwDOMException(
277 IndexSizeError, ExceptionMessages::indexOutsideRange( 285 IndexSizeError, ExceptionMessages::indexOutsideRange(
278 "startInChannel", startInChannel, 0UL, 286 "startInChannel", startInChannel, 0UL,
279 ExceptionMessages::InclusiveBound, 287 ExceptionMessages::InclusiveBound,
280 static_cast<unsigned long>(channelData->length()), 288 static_cast<unsigned long>(channelData->length()),
281 ExceptionMessages::ExclusiveBound)); 289 ExceptionMessages::ExclusiveBound));
282 290
283 return; 291 return;
284 } 292 }
285 293
294 if (source.isShared()) {
295 exceptionState.throwTypeError(
296 "source can not be backed by a SharedArrayBuffer.");
297 return;
298 }
299
286 unsigned count = channelData->length() - startInChannel; 300 unsigned count = channelData->length() - startInChannel;
287 count = std::min(source->length(), count); 301 count = std::min(source.viewNotShared()->length(), count);
288 302
289 const float* src = source->data(); 303 const float* src = source.viewNotShared()->data();
290 float* dst = channelData->data(); 304 float* dst = channelData->data();
291 305
292 DCHECK(src); 306 DCHECK(src);
293 DCHECK(dst); 307 DCHECK(dst);
294 308
295 memcpy(dst + startInChannel, src, count * sizeof(*dst)); 309 memcpy(dst + startInChannel, src, count * sizeof(*dst));
296 } 310 }
297 311
298 void AudioBuffer::zero() { 312 void AudioBuffer::zero() {
299 for (unsigned i = 0; i < m_channels.size(); ++i) { 313 for (unsigned i = 0; i < m_channels.size(); ++i) {
300 if (DOMFloat32Array* array = getChannelData(i)) { 314 if (DOMFloat32Array* array = getChannelData(i)) {
301 float* data = array->data(); 315 float* data = array->data();
302 memset(data, 0, length() * sizeof(*data)); 316 memset(data, 0, length() * sizeof(*data));
303 } 317 }
304 } 318 }
305 } 319 }
306 320
307 } // namespace blink 321 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698