⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 267639 in webkit


Ignore:
Timestamp:
Sep 26, 2020, 3:13:56 PM (6 years ago)
Author:
Chris Dumez
Message:

Constructing an AudioNode for a closed context should not throw an exception
https://bugs.webkit.org/show_bug.cgi?id=216994

Reviewed by Darin Adler.

Source/WebCore:

Constructing an AudioNode for a closed context should not throw an exception. This
behavior is not as per specification and does not match the behavior of Chrome &
Firefox either.

Test: webaudio/construct-node-with-closed-context.html

  • Modules/webaudio/AnalyserNode.cpp:

(WebCore::AnalyserNode::create):

  • Modules/webaudio/AudioBufferSourceNode.cpp:

(WebCore::AudioBufferSourceNode::create):

  • Modules/webaudio/BaseAudioContext.cpp:

(WebCore::BaseAudioContext::lazyInitialize):
(WebCore::BaseAudioContext::sampleRate const):

  • Modules/webaudio/BaseAudioContext.h:
  • Modules/webaudio/BiquadFilterNode.cpp:

(WebCore::BiquadFilterNode::create):

  • Modules/webaudio/ChannelMergerNode.cpp:

(WebCore::ChannelMergerNode::create):

  • Modules/webaudio/ChannelSplitterNode.cpp:

(WebCore::ChannelSplitterNode::create):

  • Modules/webaudio/ConstantSourceNode.cpp:

(WebCore::ConstantSourceNode::create):

  • Modules/webaudio/ConvolverNode.cpp:

(WebCore::ConvolverNode::create):

  • Modules/webaudio/DelayNode.cpp:

(WebCore::DelayNode::create):

  • Modules/webaudio/DynamicsCompressorNode.cpp:

(WebCore::DynamicsCompressorNode::create):

  • Modules/webaudio/GainNode.cpp:

(WebCore::GainNode::create):

  • Modules/webaudio/IIRFilterNode.cpp:

(WebCore::IIRFilterNode::create):

  • Modules/webaudio/MediaElementAudioSourceNode.cpp:

(WebCore::MediaElementAudioSourceNode::create):

  • Modules/webaudio/MediaStreamAudioDestinationNode.cpp:

(WebCore::MediaStreamAudioDestinationNode::create):

  • Modules/webaudio/MediaStreamAudioSourceNode.cpp:

(WebCore::MediaStreamAudioSourceNode::create):

  • Modules/webaudio/OscillatorNode.cpp:

(WebCore::OscillatorNode::create):

  • Modules/webaudio/PannerNode.cpp:

(WebCore::PannerNode::create):

  • Modules/webaudio/PeriodicWave.cpp:

(WebCore::PeriodicWave::create):

  • Modules/webaudio/StereoPannerNode.cpp:

(WebCore::StereoPannerNode::create):

  • Modules/webaudio/WaveShaperNode.cpp:

(WebCore::WaveShaperNode::create):

LayoutTests:

  • http/wpt/webaudio/audiocontext-stopped-expected.txt: Removed.
  • http/wpt/webaudio/audiocontext-stopped.html: Removed.

Drop outdated test. It is replaced with the new test I am introducing.

  • webaudio/MediaStreamAudioDestination/create-in-destroyed-context-expected.txt:

Rebaseline Blink-imported test that is now passing.

  • webaudio/construct-node-with-closed-context-expected.txt: Added.
  • webaudio/construct-node-with-closed-context.html: Added.

Add layout test coverage.

Location:
trunk
Files:
2 added
2 deleted
24 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r267637 r267639  
     12020-09-26  Chris Dumez  <cdumez@apple.com>
     2
     3        Constructing an AudioNode for a closed context should not throw an exception
     4        https://bugs.webkit.org/show_bug.cgi?id=216994
     5
     6        Reviewed by Darin Adler.
     7
     8        * http/wpt/webaudio/audiocontext-stopped-expected.txt: Removed.
     9        * http/wpt/webaudio/audiocontext-stopped.html: Removed.
     10        Drop outdated test. It is replaced with the new test I am introducing.
     11
     12        * webaudio/MediaStreamAudioDestination/create-in-destroyed-context-expected.txt:
     13        Rebaseline Blink-imported test that is now passing.
     14
     15        * webaudio/construct-node-with-closed-context-expected.txt: Added.
     16        * webaudio/construct-node-with-closed-context.html: Added.
     17        Add layout test coverage.
     18
    1192020-09-26  Zalan Bujtas  <zalan@apple.com>
    220
  • trunk/LayoutTests/webaudio/MediaStreamAudioDestination/create-in-destroyed-context-expected.txt

    r267307 r267639  
    11
    2 FAIL MediaStreamAudioDestinationNode creation in closed iframe throws error assert_throws_dom: function "() => {
    3     let stream = iframe_ac.createMediaStreamDestination();
    4   }" threw object "InvalidStateError: The object is in an invalid state." that is not a DOMException NotAllowedError: property "code" is equal to 11, expected 0
     2PASS MediaStreamAudioDestinationNode creation in closed iframe throws error
    53
  • trunk/Source/WebCore/ChangeLog

    r267638 r267639  
     12020-09-26  Chris Dumez  <cdumez@apple.com>
     2
     3        Constructing an AudioNode for a closed context should not throw an exception
     4        https://bugs.webkit.org/show_bug.cgi?id=216994
     5
     6        Reviewed by Darin Adler.
     7
     8        Constructing an AudioNode for a closed context should not throw an exception. This
     9        behavior is not as per specification and does not match the behavior of Chrome &
     10        Firefox either.
     11
     12        Test: webaudio/construct-node-with-closed-context.html
     13
     14        * Modules/webaudio/AnalyserNode.cpp:
     15        (WebCore::AnalyserNode::create):
     16        * Modules/webaudio/AudioBufferSourceNode.cpp:
     17        (WebCore::AudioBufferSourceNode::create):
     18        * Modules/webaudio/BaseAudioContext.cpp:
     19        (WebCore::BaseAudioContext::lazyInitialize):
     20        (WebCore::BaseAudioContext::sampleRate const):
     21        * Modules/webaudio/BaseAudioContext.h:
     22        * Modules/webaudio/BiquadFilterNode.cpp:
     23        (WebCore::BiquadFilterNode::create):
     24        * Modules/webaudio/ChannelMergerNode.cpp:
     25        (WebCore::ChannelMergerNode::create):
     26        * Modules/webaudio/ChannelSplitterNode.cpp:
     27        (WebCore::ChannelSplitterNode::create):
     28        * Modules/webaudio/ConstantSourceNode.cpp:
     29        (WebCore::ConstantSourceNode::create):
     30        * Modules/webaudio/ConvolverNode.cpp:
     31        (WebCore::ConvolverNode::create):
     32        * Modules/webaudio/DelayNode.cpp:
     33        (WebCore::DelayNode::create):
     34        * Modules/webaudio/DynamicsCompressorNode.cpp:
     35        (WebCore::DynamicsCompressorNode::create):
     36        * Modules/webaudio/GainNode.cpp:
     37        (WebCore::GainNode::create):
     38        * Modules/webaudio/IIRFilterNode.cpp:
     39        (WebCore::IIRFilterNode::create):
     40        * Modules/webaudio/MediaElementAudioSourceNode.cpp:
     41        (WebCore::MediaElementAudioSourceNode::create):
     42        * Modules/webaudio/MediaStreamAudioDestinationNode.cpp:
     43        (WebCore::MediaStreamAudioDestinationNode::create):
     44        * Modules/webaudio/MediaStreamAudioSourceNode.cpp:
     45        (WebCore::MediaStreamAudioSourceNode::create):
     46        * Modules/webaudio/OscillatorNode.cpp:
     47        (WebCore::OscillatorNode::create):
     48        * Modules/webaudio/PannerNode.cpp:
     49        (WebCore::PannerNode::create):
     50        * Modules/webaudio/PeriodicWave.cpp:
     51        (WebCore::PeriodicWave::create):
     52        * Modules/webaudio/StereoPannerNode.cpp:
     53        (WebCore::StereoPannerNode::create):
     54        * Modules/webaudio/WaveShaperNode.cpp:
     55        (WebCore::WaveShaperNode::create):
     56
    1572020-09-26  Chris Dumez  <cdumez@apple.com>
    258
  • trunk/Source/WebCore/Modules/webaudio/AnalyserNode.cpp

    r267609 r267639  
    3939ExceptionOr<Ref<AnalyserNode>> AnalyserNode::create(BaseAudioContext& context, const AnalyserOptions& options)
    4040{
    41     if (context.isStopped())
    42         return Exception { InvalidStateError };
    43    
    4441    auto analyser = adoptRef(*new AnalyserNode(context));
    4542   
  • trunk/Source/WebCore/Modules/webaudio/AudioBufferSourceNode.cpp

    r267609 r267639  
    6868ExceptionOr<Ref<AudioBufferSourceNode>> AudioBufferSourceNode::create(BaseAudioContext& context, AudioBufferSourceOptions&& options)
    6969{
    70     if (context.isStopped())
    71         return Exception { InvalidStateError };
    72 
    7370    auto node = adoptRef(*new AudioBufferSourceNode(context));
    7471
  • trunk/Source/WebCore/Modules/webaudio/BaseAudioContext.cpp

    r267609 r267639  
    3636#include "AudioBufferOptions.h"
    3737#include "AudioBufferSourceNode.h"
     38#include "AudioDestination.h"
    3839#include "AudioListener.h"
    3940#include "AudioNodeInput.h"
     
    208209void BaseAudioContext::lazyInitialize()
    209210{
    210     ASSERT(!m_isStopScheduled);
     211    if (isStopped())
     212        return;
    211213
    212214    if (m_isInitialized)
     
    373375    auto* document = downcast<Document>(m_scriptExecutionContext);
    374376    return document ? document->identifier() : DocumentIdentifier { };
     377}
     378
     379float BaseAudioContext::sampleRate() const
     380{
     381    return m_destinationNode ? m_destinationNode->sampleRate() : AudioDestination::hardwareSampleRate();
    375382}
    376383
     
    467474   
    468475    ASSERT(isMainThread());
    469 
    470     if (m_isStopScheduled)
    471         return Exception { InvalidStateError };
    472 
    473     lazyInitialize();
    474476
    475477    // W3C Editor's Draft 06 June 2017
  • trunk/Source/WebCore/Modules/webaudio/BaseAudioContext.h

    r267591 r267639  
    122122    size_t currentSampleFrame() const { return m_destinationNode ? m_destinationNode->currentSampleFrame() : 0; }
    123123    double currentTime() const { return m_destinationNode ? m_destinationNode->currentTime() : 0.; }
    124     float sampleRate() const { return m_destinationNode ? m_destinationNode->sampleRate() : 0.f; }
     124    float sampleRate() const;
    125125    unsigned long activeSourceCount() const { return static_cast<unsigned long>(m_activeSourceCount); }
    126126
  • trunk/Source/WebCore/Modules/webaudio/BiquadFilterNode.cpp

    r267609 r267639  
    3636ExceptionOr<Ref<BiquadFilterNode>> BiquadFilterNode::create(BaseAudioContext& context, const BiquadFilterOptions& options)
    3737{
    38     if (context.isStopped())
    39         return Exception { InvalidStateError };
    40 
    4138    auto node = adoptRef(*new BiquadFilterNode(context));
    4239
  • trunk/Source/WebCore/Modules/webaudio/ChannelMergerNode.cpp

    r267609 r267639  
    4444ExceptionOr<Ref<ChannelMergerNode>> ChannelMergerNode::create(BaseAudioContext& context, const ChannelMergerOptions& options)
    4545{
    46     if (context.isStopped())
    47         return Exception { InvalidStateError };
    48    
    4946    if (options.numberOfInputs > AudioContext::maxNumberOfChannels() || !options.numberOfInputs)
    5047        return Exception { IndexSizeError, "Number of inputs is not in the allowed range."_s };
  • trunk/Source/WebCore/Modules/webaudio/ChannelSplitterNode.cpp

    r267609 r267639  
    4040ExceptionOr<Ref<ChannelSplitterNode>> ChannelSplitterNode::create(BaseAudioContext& context, const ChannelSplitterOptions& options)
    4141{
    42     if (context.isStopped())
    43         return Exception { InvalidStateError };
    44    
    4542    if (options.numberOfOutputs > AudioContext::maxNumberOfChannels() || !options.numberOfOutputs)
    4643        return Exception { IndexSizeError, "Number of outputs is not in the allowed range"_s };
  • trunk/Source/WebCore/Modules/webaudio/ConstantSourceNode.cpp

    r267609 r267639  
    4242ExceptionOr<Ref<ConstantSourceNode>> ConstantSourceNode::create(BaseAudioContext& context, const ConstantSourceOptions& options)
    4343{
    44     if (context.isStopped())
    45         return Exception { InvalidStateError };
    46    
    4744    auto node = adoptRef(*new ConstantSourceNode(context, options.offset));
    4845   
  • trunk/Source/WebCore/Modules/webaudio/ConvolverNode.cpp

    r267609 r267639  
    5858ExceptionOr<Ref<ConvolverNode>> ConvolverNode::create(BaseAudioContext& context, ConvolverOptions&& options)
    5959{
    60     if (context.isStopped())
    61         return Exception { InvalidStateError };
    62 
    6360    auto node = adoptRef(*new ConvolverNode(context));
    6461
  • trunk/Source/WebCore/Modules/webaudio/DelayNode.cpp

    r267609 r267639  
    5050ExceptionOr<Ref<DelayNode>> DelayNode::create(BaseAudioContext& context, const DelayOptions& options)
    5151{
    52     if (context.isStopped())
    53         return Exception { InvalidStateError };
    54 
    5552    if (options.maxDelayTime <= 0 || options.maxDelayTime >= maximumAllowedDelayTime)
    5653        return Exception { NotSupportedError };
  • trunk/Source/WebCore/Modules/webaudio/DynamicsCompressorNode.cpp

    r267609 r267639  
    4848ExceptionOr<Ref<DynamicsCompressorNode>> DynamicsCompressorNode::create(BaseAudioContext& context, const DynamicsCompressorOptions& options)
    4949{
    50     if (context.isStopped())
    51         return Exception { InvalidStateError };
    52 
    5350    auto node = adoptRef(*new DynamicsCompressorNode(context, options));
    5451
  • trunk/Source/WebCore/Modules/webaudio/GainNode.cpp

    r267609 r267639  
    4141ExceptionOr<Ref<GainNode>> GainNode::create(BaseAudioContext& context, const GainOptions& options)
    4242{
    43     if (context.isStopped())
    44         return Exception { InvalidStateError };
    45 
    4643    auto gainNode = adoptRef(*new GainNode(context));
    4744
  • trunk/Source/WebCore/Modules/webaudio/IIRFilterNode.cpp

    r267609 r267639  
    8585ExceptionOr<Ref<IIRFilterNode>> IIRFilterNode::create(ScriptExecutionContext& scriptExecutionContext, BaseAudioContext& context, IIRFilterOptions&& options)
    8686{
    87     if (context.isStopped())
    88         return Exception { InvalidStateError };
    89 
    9087    if (!options.feedforward.size() || options.feedforward.size() > IIRFilter::maxOrder)
    9188        return Exception { NotSupportedError, "feedforward array must have a length between 1 and 20"_s };
  • trunk/Source/WebCore/Modules/webaudio/MediaElementAudioSourceNode.cpp

    r267609 r267639  
    4949{
    5050    RELEASE_ASSERT(options.mediaElement);
    51 
    52     if (context.isStopped())
    53         return Exception { InvalidStateError };
    5451
    5552    if (options.mediaElement->audioSourceNode())
  • trunk/Source/WebCore/Modules/webaudio/MediaStreamAudioDestinationNode.cpp

    r267609 r267639  
    4242ExceptionOr<Ref<MediaStreamAudioDestinationNode>> MediaStreamAudioDestinationNode::create(BaseAudioContext& context, const AudioNodeOptions& options)
    4343{
    44     if (context.isStopped())
    45         return Exception { InvalidStateError };
     44    // This behavior is not part of the specification. This is done for consistency with Blink.
     45    if (context.isStopped() || !context.scriptExecutionContext())
     46        return Exception { NotAllowedError, "Cannot create a MediaStreamAudioDestinationNode in a detached frame"_s };
    4647
    4748    auto node = adoptRef(*new MediaStreamAudioDestinationNode(context));
  • trunk/Source/WebCore/Modules/webaudio/MediaStreamAudioSourceNode.cpp

    r267609 r267639  
    4343{
    4444    RELEASE_ASSERT(options.mediaStream);
    45 
    46     if (context.isStopped())
    47         return Exception { InvalidStateError };
    4845
    4946    auto audioTracks = options.mediaStream->getAudioTracks();
  • trunk/Source/WebCore/Modules/webaudio/OscillatorNode.cpp

    r267609 r267639  
    6363ExceptionOr<Ref<OscillatorNode>> OscillatorNode::create(BaseAudioContext& context, const OscillatorOptions& options)
    6464{
    65     if (context.isStopped())
    66         return Exception { InvalidStateError };
    67 
    6865    if (options.type == OscillatorType::Custom && !options.periodicWave)
    6966        return Exception { InvalidStateError, "Must provide periodicWave when using custom type."_s };
  • trunk/Source/WebCore/Modules/webaudio/PannerNode.cpp

    r267609 r267639  
    5858ExceptionOr<Ref<PannerNode>> PannerNode::create(BaseAudioContext& context, const PannerOptions& options)
    5959{
    60     if (context.isStopped())
    61         return Exception { InvalidStateError };
    62 
    6360    auto panner = adoptRef(*new PannerNode(context, options));
    6461
  • trunk/Source/WebCore/Modules/webaudio/PeriodicWave.cpp

    r267609 r267639  
    6262ExceptionOr<Ref<PeriodicWave>> PeriodicWave::create(BaseAudioContext& context, PeriodicWaveOptions&& options)
    6363{
    64     if (context.isStopped())
    65         return Exception { InvalidStateError };
    66 
    6764    Vector<float> real;
    6865    Vector<float> imag;
  • trunk/Source/WebCore/Modules/webaudio/StereoPannerNode.cpp

    r267609 r267639  
    4242ExceptionOr<Ref<StereoPannerNode>> StereoPannerNode::create(BaseAudioContext& context, const StereoPannerOptions& options)
    4343{
    44     if (context.isStopped())
    45         return Exception { InvalidStateError };
    46    
    4744    auto stereo = adoptRef(*new StereoPannerNode(context, options.pan));
    4845   
  • trunk/Source/WebCore/Modules/webaudio/WaveShaperNode.cpp

    r267609 r267639  
    4040ExceptionOr<Ref<WaveShaperNode>> WaveShaperNode::create(BaseAudioContext& context, const WaveShaperOptions& options)
    4141{
    42     if (context.isStopped())
    43         return Exception { InvalidStateError };
    44 
    4542    RefPtr<Float32Array> curve;
    4643    if (options.curve) {
Note: See TracChangeset for help on using the changeset viewer.