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

Unified Diff: third_party/WebKit/Source/modules/webaudio/BaseAudioContext.cpp

Issue 2746913003: Detach buffer in decodeAudioData (Closed)
Patch Set: Address review comments 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/LayoutTests/webaudio/decodeAudioData/decode-audio-data-neuter.html ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/modules/webaudio/BaseAudioContext.cpp
diff --git a/third_party/WebKit/Source/modules/webaudio/BaseAudioContext.cpp b/third_party/WebKit/Source/modules/webaudio/BaseAudioContext.cpp
index d0acd8dbd40e27c20f1486655552d659e763b0ab..4919f18e578cefde127ec84a18f64ea3efd8d76c 100644
--- a/third_party/WebKit/Source/modules/webaudio/BaseAudioContext.cpp
+++ b/third_party/WebKit/Source/modules/webaudio/BaseAudioContext.cpp
@@ -284,9 +284,26 @@ ScriptPromise BaseAudioContext::decodeAudioData(
DCHECK_GT(rate, 0);
- m_decodeAudioResolvers.insert(resolver);
- m_audioDecoder.decodeAsync(audioData, rate, successCallback, errorCallback,
- resolver, this);
+ if (audioData->isNeutered()) {
+ // If audioData is detached (neutered) we need to reject the
+ // promise with an error.
+ DOMException* error = DOMException::create(
+ DataCloneError, "Cannot decode detached ArrayBuffer");
+ resolver->reject(error);
+ if (errorCallback) {
+ errorCallback->handleEvent(error);
+ }
+ } else {
+ // Detach the audio array buffer from the main thread and start
+ // async decoding of the data.
+ WTF::ArrayBufferContents bufferContents;
+ audioData->transfer(bufferContents);
+ DOMArrayBuffer* audio = DOMArrayBuffer::create(bufferContents);
+
+ m_decodeAudioResolvers.insert(resolver);
+ m_audioDecoder.decodeAsync(audio, rate, successCallback, errorCallback,
+ resolver, this);
+ }
return promise;
}
« no previous file with comments | « third_party/WebKit/LayoutTests/webaudio/decodeAudioData/decode-audio-data-neuter.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698