Title: [267147] trunk
Revision
267147
Author
cdu...@apple.com
Date
2020-09-16 09:00:19 -0700 (Wed, 16 Sep 2020)

Log Message

OfflineAudioContext constructor should not throw when given a bad buffer length
https://bugs.webkit.org/show_bug.cgi?id=216584

Reviewed by Youenn Fablet.

Source/WebCore:

OfflineAudioContext constructor should not throw when given a bad buffer length. We should
instead throw later on when trying to start rendering.

No new tests, rebaselined existing test.

* Modules/webaudio/BaseAudioContext.cpp:
(WebCore::BaseAudioContext::BaseAudioContext):
* Modules/webaudio/BaseAudioContext.h:
* Modules/webaudio/OfflineAudioContext.cpp:
(WebCore::OfflineAudioContext::OfflineAudioContext):
(WebCore::OfflineAudioContext::create):
(WebCore::OfflineAudioContext::startOfflineRendering):
* Modules/webaudio/OfflineAudioContext.h:
* Modules/webaudio/OfflineAudioDestinationNode.cpp:
(WebCore::OfflineAudioDestinationNode::OfflineAudioDestinationNode):
(WebCore::OfflineAudioDestinationNode::maxChannelCount const):

LayoutTests:

Rebaseline test now that more checks are passing.

* webaudio/dom-exceptions-expected.txt:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (267146 => 267147)


--- trunk/LayoutTests/ChangeLog	2020-09-16 15:55:47 UTC (rev 267146)
+++ trunk/LayoutTests/ChangeLog	2020-09-16 16:00:19 UTC (rev 267147)
@@ -1,5 +1,16 @@
 2020-09-16  Chris Dumez  <cdu...@apple.com>
 
+        OfflineAudioContext constructor should not throw when given a bad buffer length
+        https://bugs.webkit.org/show_bug.cgi?id=216584
+
+        Reviewed by Youenn Fablet.
+
+        Rebaseline test now that more checks are passing.
+
+        * webaudio/dom-exceptions-expected.txt:
+
+2020-09-16  Chris Dumez  <cdu...@apple.com>
+
         Import OscillatorNode layout tests from Blink
         https://bugs.webkit.org/show_bug.cgi?id=216569
 

Modified: trunk/LayoutTests/webaudio/dom-exceptions-expected.txt (267146 => 267147)


--- trunk/LayoutTests/webaudio/dom-exceptions-expected.txt	2020-09-16 15:55:47 UTC (rev 267146)
+++ trunk/LayoutTests/webaudio/dom-exceptions-expected.txt	2020-09-16 16:00:19 UTC (rev 267147)
@@ -16,7 +16,7 @@
 PASS Executing "biquad" 
 PASS Executing "offline-audio-context" 
 PASS Executing "invalid-offline-audio-context-parameters" 
-FAIL Executing "invalid-frame-length" promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'testContext.startRendering')"
+PASS Executing "invalid-frame-length" 
 PASS Executing "waveshaper" 
 PASS Executing "audio-buffer-source" 
 PASS Executing "oscillator" 
@@ -143,7 +143,9 @@
 PASS   new OfflineAudioContext(1, 0, 44100) threw SyntaxError: "length cannot be 0". 
 PASS < [invalid-offline-audio-context-parameters] All assertions passed. (total 5 assertions) 
 PASS > [invalid-frame-length]  
-FAIL X testContext = new OfflineAudioContext(1, -88200000000000, 44100) incorrectly threw SyntaxError: "Unable to create AudioBuffer". assert_true: expected true got false
+PASS   testContext = new OfflineAudioContext(1, -88200000000000, 44100) did not throw an exception. 
+PASS   testContext.startRendering() rejected correctly with InvalidStateError: Failed to create audio buffer. 
+PASS < [invalid-frame-length] All assertions passed. (total 2 assertions) 
 PASS > [waveshaper]  
 PASS   node.oversample = "9x" did not throw an exception. 
 PASS   node.oversample is equal to none. 
@@ -258,5 +260,5 @@
 PASS   source.noteOn is equal to undefined. 
 PASS   source.noteOff is equal to undefined. 
 PASS < [misc] All assertions passed. (total 4 assertions) 
-FAIL # AUDIT TASK RUNNER FINISHED: 2 out of 24 tasks were failed. assert_true: expected true got false
+FAIL # AUDIT TASK RUNNER FINISHED: 1 out of 24 tasks were failed. assert_true: expected true got false
 

Modified: trunk/Source/WebCore/ChangeLog (267146 => 267147)


--- trunk/Source/WebCore/ChangeLog	2020-09-16 15:55:47 UTC (rev 267146)
+++ trunk/Source/WebCore/ChangeLog	2020-09-16 16:00:19 UTC (rev 267147)
@@ -1,3 +1,27 @@
+2020-09-16  Chris Dumez  <cdu...@apple.com>
+
+        OfflineAudioContext constructor should not throw when given a bad buffer length
+        https://bugs.webkit.org/show_bug.cgi?id=216584
+
+        Reviewed by Youenn Fablet.
+
+        OfflineAudioContext constructor should not throw when given a bad buffer length. We should
+        instead throw later on when trying to start rendering.
+
+        No new tests, rebaselined existing test.
+
+        * Modules/webaudio/BaseAudioContext.cpp:
+        (WebCore::BaseAudioContext::BaseAudioContext):
+        * Modules/webaudio/BaseAudioContext.h:
+        * Modules/webaudio/OfflineAudioContext.cpp:
+        (WebCore::OfflineAudioContext::OfflineAudioContext):
+        (WebCore::OfflineAudioContext::create):
+        (WebCore::OfflineAudioContext::startOfflineRendering):
+        * Modules/webaudio/OfflineAudioContext.h:
+        * Modules/webaudio/OfflineAudioDestinationNode.cpp:
+        (WebCore::OfflineAudioDestinationNode::OfflineAudioDestinationNode):
+        (WebCore::OfflineAudioDestinationNode::maxChannelCount const):
+
 2020-09-16  Sam Weinig  <wei...@apple.com>
 
         [WebIDL] Move navigator.cookieEnabled to its own interface mixin, matching the spec

Modified: trunk/Source/WebCore/Modules/webaudio/AudioContext.cpp (267146 => 267147)


--- trunk/Source/WebCore/Modules/webaudio/AudioContext.cpp	2020-09-16 15:55:47 UTC (rev 267146)
+++ trunk/Source/WebCore/Modules/webaudio/AudioContext.cpp	2020-09-16 16:00:19 UTC (rev 267147)
@@ -99,12 +99,6 @@
 {
 }
 
-// Constructor for offline (non-realtime) rendering.
-AudioContext::AudioContext(Document& document, AudioBuffer* renderTarget)
-    : BaseAudioContext(document, renderTarget)
-{
-}
-
 double AudioContext::baseLatency()
 {
     lazyInitialize();

Modified: trunk/Source/WebCore/Modules/webaudio/AudioContext.h (267146 => 267147)


--- trunk/Source/WebCore/Modules/webaudio/AudioContext.h	2020-09-16 15:55:47 UTC (rev 267146)
+++ trunk/Source/WebCore/Modules/webaudio/AudioContext.h	2020-09-16 16:00:19 UTC (rev 267147)
@@ -59,7 +59,6 @@
 
 private:
     AudioContext(Document&, const AudioContextOptions&);
-    AudioContext(Document&, AudioBuffer* renderTarget);
 };
 
 } // WebCore

Modified: trunk/Source/WebCore/Modules/webaudio/BaseAudioContext.cpp (267146 => 267147)


--- trunk/Source/WebCore/Modules/webaudio/BaseAudioContext.cpp	2020-09-16 15:55:47 UTC (rev 267146)
+++ trunk/Source/WebCore/Modules/webaudio/BaseAudioContext.cpp	2020-09-16 16:00:19 UTC (rev 267147)
@@ -152,7 +152,7 @@
 }
 
 // Constructor for offline (non-realtime) rendering.
-BaseAudioContext::BaseAudioContext(Document& document, AudioBuffer* renderTarget)
+BaseAudioContext::BaseAudioContext(Document& document, unsigned numberOfChannels, RefPtr<AudioBuffer>&& renderTarget)
     : ActiveDOMObject(document)
 #if !RELEASE_LOG_DISABLED
     , m_logger(document.logger())
@@ -160,12 +160,12 @@
 #endif
     , m_isOfflineContext(true)
     , m_mediaSession(PlatformMediaSession::create(PlatformMediaSessionManager::sharedManager(), *this))
-    , m_renderTarget(renderTarget)
+    , m_renderTarget(WTFMove(renderTarget))
 {
     constructCommon();
 
     // Create a new destination for offline rendering.
-    m_destinationNode = OfflineAudioDestinationNode::create(*this, m_renderTarget.get());
+    m_destinationNode = OfflineAudioDestinationNode::create(*this, numberOfChannels, m_renderTarget.copyRef());
 }
 
 void BaseAudioContext::constructCommon()

Modified: trunk/Source/WebCore/Modules/webaudio/BaseAudioContext.h (267146 => 267147)


--- trunk/Source/WebCore/Modules/webaudio/BaseAudioContext.h	2020-09-16 15:55:47 UTC (rev 267146)
+++ trunk/Source/WebCore/Modules/webaudio/BaseAudioContext.h	2020-09-16 16:00:19 UTC (rev 267147)
@@ -315,7 +315,7 @@
 
 protected:
     explicit BaseAudioContext(Document&, const AudioContextOptions& = { });
-    BaseAudioContext(Document&, AudioBuffer* renderTarget);
+    BaseAudioContext(Document&, unsigned numberOfChannels, RefPtr<AudioBuffer>&& renderTarget);
     
     void clearPendingActivity();
     void makePendingActivity();

Modified: trunk/Source/WebCore/Modules/webaudio/OfflineAudioContext.cpp (267146 => 267147)


--- trunk/Source/WebCore/Modules/webaudio/OfflineAudioContext.cpp	2020-09-16 15:55:47 UTC (rev 267146)
+++ trunk/Source/WebCore/Modules/webaudio/OfflineAudioContext.cpp	2020-09-16 16:00:19 UTC (rev 267147)
@@ -38,8 +38,8 @@
 
 WTF_MAKE_ISO_ALLOCATED_IMPL(OfflineAudioContext);
 
-inline OfflineAudioContext::OfflineAudioContext(Document& document, AudioBuffer* renderTarget)
-    : BaseAudioContext(document, renderTarget)
+inline OfflineAudioContext::OfflineAudioContext(Document& document, unsigned numberOfChannels, RefPtr<AudioBuffer>&& renderTarget)
+    : BaseAudioContext(document, numberOfChannels, WTFMove(renderTarget))
 {
 }
 
@@ -54,11 +54,9 @@
         return Exception { SyntaxError, "length cannot be 0"_s };
     if (!isSupportedSampleRate(sampleRate))
         return Exception { SyntaxError, "sampleRate is not in range"_s };
+
     auto renderTarget = AudioBuffer::create(numberOfChannels, length, sampleRate);
-    if (!renderTarget)
-        return Exception { SyntaxError, "Unable to create AudioBuffer"_s };
-
-    auto audioContext = adoptRef(*new OfflineAudioContext(downcast<Document>(context), renderTarget.get()));
+    auto audioContext = adoptRef(*new OfflineAudioContext(downcast<Document>(context), numberOfChannels, WTFMove(renderTarget)));
     audioContext->suspendIfNeeded();
     return audioContext;
 }
@@ -106,6 +104,11 @@
         return;
     }
 
+    if (!renderTarget()) {
+        promise->reject(Exception { InvalidStateError, "Failed to create audio buffer"_s });
+        return;
+    }
+
     lazyInitialize();
 
     auto result = destination()->startRendering();

Modified: trunk/Source/WebCore/Modules/webaudio/OfflineAudioContext.h (267146 => 267147)


--- trunk/Source/WebCore/Modules/webaudio/OfflineAudioContext.h	2020-09-16 15:55:47 UTC (rev 267146)
+++ trunk/Source/WebCore/Modules/webaudio/OfflineAudioContext.h	2020-09-16 16:00:19 UTC (rev 267147)
@@ -72,7 +72,7 @@
     };
 
 private:
-    OfflineAudioContext(Document&, AudioBuffer* renderTarget);
+    OfflineAudioContext(Document&, unsigned numberOfChannels, RefPtr<AudioBuffer>&& renderTarget);
 
     void didFinishOfflineRendering(ExceptionOr<Ref<AudioBuffer>>&&) final;
     void didSuspendRendering(size_t frame) final;

Modified: trunk/Source/WebCore/Modules/webaudio/OfflineAudioDestinationNode.cpp (267146 => 267147)


--- trunk/Source/WebCore/Modules/webaudio/OfflineAudioDestinationNode.cpp	2020-09-16 15:55:47 UTC (rev 267146)
+++ trunk/Source/WebCore/Modules/webaudio/OfflineAudioDestinationNode.cpp	2020-09-16 16:00:19 UTC (rev 267147)
@@ -41,13 +41,14 @@
     
 const size_t OfflineAudioDestinationNode::renderQuantumSize = 128;
 
-OfflineAudioDestinationNode::OfflineAudioDestinationNode(BaseAudioContext& context, AudioBuffer* renderTarget)
+OfflineAudioDestinationNode::OfflineAudioDestinationNode(BaseAudioContext& context, unsigned numberOfChannels, RefPtr<AudioBuffer>&& renderTarget)
     : AudioDestinationNode(context)
-    , m_renderTarget(renderTarget)
-    , m_framesToProcess(renderTarget->length())
+    , m_numberOfChannels(numberOfChannels)
+    , m_renderTarget(WTFMove(renderTarget))
+    , m_framesToProcess(m_renderTarget ? m_renderTarget->length() : 0)
 {
-    m_renderBus = AudioBus::create(renderTarget->numberOfChannels(), renderQuantumSize);
-    initializeDefaultNodeOptions(renderTarget->numberOfChannels(), ChannelCountMode::Explicit, ChannelInterpretation::Speakers);
+    m_renderBus = AudioBus::create(numberOfChannels, renderQuantumSize);
+    initializeDefaultNodeOptions(numberOfChannels, ChannelCountMode::Explicit, ChannelInterpretation::Speakers);
 }
 
 OfflineAudioDestinationNode::~OfflineAudioDestinationNode()
@@ -57,7 +58,7 @@
 
 unsigned OfflineAudioDestinationNode::maxChannelCount() const
 {
-    return m_renderTarget->numberOfChannels();
+    return m_numberOfChannels;
 }
 
 void OfflineAudioDestinationNode::initialize()

Modified: trunk/Source/WebCore/Modules/webaudio/OfflineAudioDestinationNode.h (267146 => 267147)


--- trunk/Source/WebCore/Modules/webaudio/OfflineAudioDestinationNode.h	2020-09-16 15:55:47 UTC (rev 267146)
+++ trunk/Source/WebCore/Modules/webaudio/OfflineAudioDestinationNode.h	2020-09-16 16:00:19 UTC (rev 267147)
@@ -37,9 +37,9 @@
 class OfflineAudioDestinationNode final : public AudioDestinationNode {
     WTF_MAKE_ISO_ALLOCATED(OfflineAudioDestinationNode);
 public:
-    static Ref<OfflineAudioDestinationNode> create(BaseAudioContext& context, AudioBuffer* renderTarget)
+    static Ref<OfflineAudioDestinationNode> create(BaseAudioContext& context, unsigned numberOfChannels, RefPtr<AudioBuffer>&& renderTarget)
     {
-        return adoptRef(*new OfflineAudioDestinationNode(context, renderTarget));
+        return adoptRef(*new OfflineAudioDestinationNode(context, numberOfChannels, WTFMove(renderTarget)));
     }
 
     virtual ~OfflineAudioDestinationNode();
@@ -57,7 +57,7 @@
     static const size_t renderQuantumSize;
 
 private:
-    OfflineAudioDestinationNode(BaseAudioContext&, AudioBuffer* renderTarget);
+    OfflineAudioDestinationNode(BaseAudioContext&, unsigned numberOfChannels, RefPtr<AudioBuffer>&& renderTarget);
 
     enum class OfflineRenderResult { Failure, Suspended, Complete };
     OfflineRenderResult offlineRender();
@@ -67,6 +67,8 @@
 
     unsigned maxChannelCount() const final;
 
+    unsigned m_numberOfChannels;
+
     // This AudioNode renders into this AudioBuffer.
     RefPtr<AudioBuffer> m_renderTarget;
     

Modified: trunk/Source/WebCore/Modules/webaudio/WebKitAudioContext.cpp (267146 => 267147)


--- trunk/Source/WebCore/Modules/webaudio/WebKitAudioContext.cpp	2020-09-16 15:55:47 UTC (rev 267146)
+++ trunk/Source/WebCore/Modules/webaudio/WebKitAudioContext.cpp	2020-09-16 16:00:19 UTC (rev 267147)
@@ -84,8 +84,8 @@
 }
 
 // Constructor for offline (non-realtime) rendering.
-WebKitAudioContext::WebKitAudioContext(Document& document, AudioBuffer* renderTarget)
-    : BaseAudioContext(document, renderTarget)
+WebKitAudioContext::WebKitAudioContext(Document& document, Ref<AudioBuffer>&& renderTarget)
+    : BaseAudioContext(document, renderTarget->numberOfChannels(), WTFMove(renderTarget))
 {
 }
 

Modified: trunk/Source/WebCore/Modules/webaudio/WebKitAudioContext.h (267146 => 267147)


--- trunk/Source/WebCore/Modules/webaudio/WebKitAudioContext.h	2020-09-16 15:55:47 UTC (rev 267146)
+++ trunk/Source/WebCore/Modules/webaudio/WebKitAudioContext.h	2020-09-16 16:00:19 UTC (rev 267147)
@@ -75,7 +75,7 @@
 
 protected:
     explicit WebKitAudioContext(Document&);
-    WebKitAudioContext(Document&, AudioBuffer* renderTarget);
+    WebKitAudioContext(Document&, Ref<AudioBuffer>&& renderTarget);
 
 private:
     // ActiveDOMObject API.

Modified: trunk/Source/WebCore/Modules/webaudio/WebKitOfflineAudioContext.cpp (267146 => 267147)


--- trunk/Source/WebCore/Modules/webaudio/WebKitOfflineAudioContext.cpp	2020-09-16 15:55:47 UTC (rev 267146)
+++ trunk/Source/WebCore/Modules/webaudio/WebKitOfflineAudioContext.cpp	2020-09-16 16:00:19 UTC (rev 267147)
@@ -36,11 +36,13 @@
 
 WTF_MAKE_ISO_ALLOCATED_IMPL(WebKitOfflineAudioContext);
 
-inline WebKitOfflineAudioContext::WebKitOfflineAudioContext(Document& document, AudioBuffer* renderTarget)
-    : WebKitAudioContext(document, renderTarget)
+WebKitOfflineAudioContext::WebKitOfflineAudioContext(Document& document, Ref<AudioBuffer>&& renderTarget)
+    : WebKitAudioContext(document, WTFMove(renderTarget))
 {
 }
 
+WebKitOfflineAudioContext::~WebKitOfflineAudioContext() = default;
+
 ExceptionOr<Ref<WebKitOfflineAudioContext>> WebKitOfflineAudioContext::create(ScriptExecutionContext& context, unsigned numberOfChannels, size_t numberOfFrames, float sampleRate)
 {
     // FIXME: Add support for workers.
@@ -52,11 +54,16 @@
     if (!renderTarget)
         return Exception { SyntaxError };
 
-    auto audioContext = adoptRef(*new WebKitOfflineAudioContext(downcast<Document>(context), renderTarget.get()));
+    auto audioContext = adoptRef(*new WebKitOfflineAudioContext(downcast<Document>(context), renderTarget.releaseNonNull()));
     audioContext->suspendIfNeeded();
     return audioContext;
 }
 
+const char* WebKitOfflineAudioContext::activeDOMObjectName() const
+{
+    return "WebKitOfflineAudioContext";
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(WEB_AUDIO)

Modified: trunk/Source/WebCore/Modules/webaudio/WebKitOfflineAudioContext.h (267146 => 267147)


--- trunk/Source/WebCore/Modules/webaudio/WebKitOfflineAudioContext.h	2020-09-16 15:55:47 UTC (rev 267146)
+++ trunk/Source/WebCore/Modules/webaudio/WebKitOfflineAudioContext.h	2020-09-16 16:00:19 UTC (rev 267147)
@@ -32,9 +32,13 @@
     WTF_MAKE_ISO_ALLOCATED(WebKitOfflineAudioContext);
 public:
     static ExceptionOr<Ref<WebKitOfflineAudioContext>> create(ScriptExecutionContext&, unsigned numberOfChannels, size_t numberOfFrames, float sampleRate);
+    ~WebKitOfflineAudioContext();
 
 private:
-    WebKitOfflineAudioContext(Document&, AudioBuffer* renderTarget);
+    WebKitOfflineAudioContext(Document&, Ref<AudioBuffer>&& renderTarget);
+
+    // ActiveDOMObject API.
+    const char* activeDOMObjectName() const final;
 };
 
 } // namespace WebCore
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to