Bug 156769 - AudioBufferSourceNode.buffer should be nullable
Summary: AudioBufferSourceNode.buffer should be nullable
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Bindings (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL: https://webaudio.github.io/web-audio-...
Keywords:
Depends on:
Blocks:
 
Reported: 2016-04-19 16:30 PDT by Chris Dumez
Modified: 2016-04-19 18:29 PDT (History)
3 users (show)

See Also:


Attachments
Patch (20.60 KB, patch)
2016-04-19 16:42 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (21.50 KB, patch)
2016-04-19 17:06 PDT, Chris Dumez
darin: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Dumez 2016-04-19 16:30:21 PDT
Get rid of custom bindings for AudioBufferSourceNode.buffer's setter. They are not needed.
Comment 1 Chris Dumez 2016-04-19 16:42:52 PDT
Created attachment 276775 [details]
Patch
Comment 2 Chris Dumez 2016-04-19 16:44:57 PDT
Comment on attachment 276775 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=276775&action=review

> Source/WebCore/bindings/js/JSAudioBufferSourceNodeCustom.cpp:-45
> -    if (!buffer) {

This was emulating [StrictTypeChecking] but also wrongly throwing a TypeError when setting to null. We now use [StrictTypeChecking] in the IDL and mark the attribute as nullable to get the correct behavior.

> Source/WebCore/bindings/js/JSAudioBufferSourceNodeCustom.cpp:-51
> -        state.vm().throwException(&state, createTypeError(&state, "AudioBuffer unsupported number of channels"));

We now use [SetterRaisesExceptionWithMessage] in the IDL and moved the exception code/message setting to the implementation.
Comment 3 Chris Dumez 2016-04-19 16:49:37 PDT
Comment on attachment 276775 [details]
Patch

Will clean up a little bit further.
Comment 4 Chris Dumez 2016-04-19 17:06:16 PDT
Created attachment 276778 [details]
Patch
Comment 5 Darin Adler 2016-04-19 17:10:18 PDT
Comment on attachment 276778 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=276778&action=review

> Source/WebCore/Modules/webaudio/AudioBufferSourceNode.cpp:424
> -        if (numberOfChannels > AudioContext::maxNumberOfChannels())
> -            return false;
> +        ASSERT(numberOfChannels <= AudioContext::maxNumberOfChannels());

The test seems to cover this, but I was wondering where the guarantee of this comes from.

> Source/WebCore/Modules/webaudio/AudioContext.h:208
>      static unsigned maxNumberOfChannels() { return MaxNumberOfChannels;}

Missing space before the "}" here.
Comment 6 Chris Dumez 2016-04-19 17:17:31 PDT
Comment on attachment 276778 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=276778&action=review

>> Source/WebCore/Modules/webaudio/AudioBufferSourceNode.cpp:424
>> +        ASSERT(numberOfChannels <= AudioContext::maxNumberOfChannels());
> 
> The test seems to cover this, but I was wondering where the guarantee of this comes from.

There are 2 factories for AudioBuffer, the first one explicitly checks the number of channels:
RefPtr<AudioBuffer> AudioBuffer::create(unsigned numberOfChannels, size_t numberOfFrames, float sampleRate)
{
    if (sampleRate < 22050 || sampleRate > 96000 || numberOfChannels > AudioContext::maxNumberOfChannels() || !numberOfFrames)
        return nullptr;

The second one looks like so:
RefPtr<AudioBuffer> AudioBuffer::createFromAudioFileData(const void* data, size_t dataSize, bool mixToMono, float sampleRate).

It creates an AudioBus then creates an AudioBuffer from that AudioBus. AudioFileReader::createBus() can set channelSize to 1 (mono) or 2 (stereo).
Comment 7 Chris Dumez 2016-04-19 18:29:55 PDT
Committed r199751: <http://trac.webkit.org/changeset/199751>