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

Unified 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, 10 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/webaudio/AudioBuffer.cpp
diff --git a/third_party/WebKit/Source/modules/webaudio/AudioBuffer.cpp b/third_party/WebKit/Source/modules/webaudio/AudioBuffer.cpp
index 294a59f0536253049358697418b8dfca28c54bce..8849f4e9b4008659dd158034cf58f6f90015b7ba 100644
--- a/third_party/WebKit/Source/modules/webaudio/AudioBuffer.cpp
+++ b/third_party/WebKit/Source/modules/webaudio/AudioBuffer.cpp
@@ -203,16 +203,18 @@ DOMFloat32Array* AudioBuffer::getChannelData(unsigned channelIndex) {
return m_channels[channelIndex].get();
}
-void AudioBuffer::copyFromChannel(DOMFloat32Array* destination,
- long channelNumber,
- ExceptionState& exceptionState) {
+void AudioBuffer::copyFromChannel(
+ const MaybeShared<DOMFloat32Array>& destination,
+ long channelNumber,
+ ExceptionState& exceptionState) {
return copyFromChannel(destination, channelNumber, 0, exceptionState);
}
-void AudioBuffer::copyFromChannel(DOMFloat32Array* destination,
- long channelNumber,
- unsigned long startInChannel,
- ExceptionState& exceptionState) {
+void AudioBuffer::copyFromChannel(
+ const MaybeShared<DOMFloat32Array>& destination,
+ long channelNumber,
+ unsigned long startInChannel,
+ ExceptionState& exceptionState) {
if (channelNumber < 0 ||
channelNumber >= static_cast<long>(m_channels.size())) {
exceptionState.throwDOMException(
@@ -237,11 +239,17 @@ void AudioBuffer::copyFromChannel(DOMFloat32Array* destination,
return;
}
+ if (destination.isShared()) {
+ exceptionState.throwTypeError(
+ "destination can not be backed by a SharedArrayBuffer.");
+ return;
+ }
+
unsigned count = channelData->length() - startInChannel;
- count = std::min(destination->length(), count);
+ count = std::min(destination.viewNotShared()->length(), count);
const float* src = channelData->data();
- float* dst = destination->data();
+ float* dst = destination.viewNotShared()->data();
DCHECK(src);
DCHECK(dst);
@@ -249,13 +257,13 @@ void AudioBuffer::copyFromChannel(DOMFloat32Array* destination,
memcpy(dst, src + startInChannel, count * sizeof(*src));
}
-void AudioBuffer::copyToChannel(DOMFloat32Array* source,
+void AudioBuffer::copyToChannel(const MaybeShared<DOMFloat32Array>& source,
long channelNumber,
ExceptionState& exceptionState) {
return copyToChannel(source, channelNumber, 0, exceptionState);
}
-void AudioBuffer::copyToChannel(DOMFloat32Array* source,
+void AudioBuffer::copyToChannel(const MaybeShared<DOMFloat32Array>& source,
long channelNumber,
unsigned long startInChannel,
ExceptionState& exceptionState) {
@@ -283,10 +291,16 @@ void AudioBuffer::copyToChannel(DOMFloat32Array* source,
return;
}
+ if (source.isShared()) {
+ exceptionState.throwTypeError(
+ "source can not be backed by a SharedArrayBuffer.");
+ return;
+ }
+
unsigned count = channelData->length() - startInChannel;
- count = std::min(source->length(), count);
+ count = std::min(source.viewNotShared()->length(), count);
- const float* src = source->data();
+ const float* src = source.viewNotShared()->data();
float* dst = channelData->data();
DCHECK(src);

Powered by Google App Engine
This is Rietveld 408576698