Title: [123996] trunk
Revision
123996
Author
[email protected]
Date
2012-07-29 22:28:45 -0700 (Sun, 29 Jul 2012)

Log Message

getChannelData should raise exception when index is more than numberOfChannels.
https://bugs.webkit.org/show_bug.cgi?id=92223

Patch by Li Yin <[email protected]> on 2012-07-29
Reviewed by Kentaro Hara.

Source/WebCore:

Spec: https://dvcs.w3.org/hg/audio/raw-file/tip/webaudio/specification.html#AudioBuffer-section
In getChannelData function, the index value MUST be less than numberOfChannels
or an exception will be thrown.

Test: webaudio/audiobuffer.html

* Modules/webaudio/AudioBuffer.cpp:
(WebCore::AudioBuffer::getChannelData):
(WebCore):
* Modules/webaudio/AudioBuffer.h:
(WebCore):
(AudioBuffer):
* Modules/webaudio/AudioBuffer.idl: raise exception when index is not less than numberOfChannels.

LayoutTests:

Spec: https://dvcs.w3.org/hg/audio/raw-file/tip/webaudio/specification.html#AudioBuffer-section
Add test to cover basic attributes of AudioBuffer.

* webaudio/audiobuffer-expected.txt: Added.
* webaudio/audiobuffer.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (123995 => 123996)


--- trunk/LayoutTests/ChangeLog	2012-07-30 05:22:58 UTC (rev 123995)
+++ trunk/LayoutTests/ChangeLog	2012-07-30 05:28:45 UTC (rev 123996)
@@ -1,3 +1,16 @@
+2012-07-29  Li Yin  <[email protected]>
+
+        getChannelData should raise exception when index is more than numberOfChannels.
+        https://bugs.webkit.org/show_bug.cgi?id=92223
+
+        Reviewed by Kentaro Hara.
+
+        Spec: https://dvcs.w3.org/hg/audio/raw-file/tip/webaudio/specification.html#AudioBuffer-section
+        Add test to cover basic attributes of AudioBuffer.
+
+        * webaudio/audiobuffer-expected.txt: Added.
+        * webaudio/audiobuffer.html: Added.
+
 2012-07-29  Sukolsak Sakshuwong  <[email protected]>
 
         forward-delete in the last cell of a table moves the caret after the table

Added: trunk/LayoutTests/webaudio/audiobuffer-expected.txt (0 => 123996)


--- trunk/LayoutTests/webaudio/audiobuffer-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/webaudio/audiobuffer-expected.txt	2012-07-30 05:28:45 UTC (rev 123996)
@@ -0,0 +1,18 @@
+Basic tests for AudioBuffer.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS sampleRate has been set correctly.
+PASS length has been set correctly.
+PASS duration has been set correctly.
+PASS numberOfChannels has been set correctly.
+PASS getChannelData(0) returns a Float32Array object.
+PASS getChannelData(1) returns a Float32Array object.
+PASS getChannelData(2) returns a Float32Array object.
+PASS getChannelData(3) returns a Float32Array object.
+PASS Exception has been thrown correctly when index is not less than numberOfChannels.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/webaudio/audiobuffer.html (0 => 123996)


--- trunk/LayoutTests/webaudio/audiobuffer.html	                        (rev 0)
+++ trunk/LayoutTests/webaudio/audiobuffer.html	2012-07-30 05:28:45 UTC (rev 123996)
@@ -0,0 +1,55 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<script>
+description("Basic tests for AudioBuffer.");
+
+var sampleRate = 44100.0
+var lengthInSeconds = 2;
+var numberOfChannels = 4;
+
+var context = new webkitAudioContext();
+var buffer = context.createBuffer(numberOfChannels, sampleRate * lengthInSeconds, sampleRate);
+
+if (buffer.sampleRate === sampleRate)
+    testPassed("sampleRate has been set correctly.");
+else
+    testFailed("sampleRate should be set correctly.");
+
+if (buffer.length === sampleRate * lengthInSeconds)
+    testPassed("length has been set correctly.");
+else
+    testFailed("length should be set correctly");
+
+if (buffer.duration === lengthInSeconds)
+    testPassed("duration has been set correctly.");
+else
+    testFailed("duration should be set correctly.");
+
+if (buffer.numberOfChannels === numberOfChannels)
+    testPassed("numberOfChannels has been set correctly.");
+else
+    testFailed("numberOfChannels should be set correctly.");
+
+for (var index = 0; index < buffer.numberOfChannels; ++index) {
+    if (buffer.getChannelData(index) instanceof window.Float32Array)
+        testPassed("getChannelData(" + index + ") returns a Float32Array object.");
+    else
+        testFailed("getChannelData(" + index + ") should return a Float32Array object.");
+}
+
+try {
+    buffer.getChannelData(buffer.numberOfChannels);
+    testFailed("Exception should be thrown when index is not less than numberOfChannels.");
+} catch(e) {
+    testPassed("Exception has been thrown correctly when index is not less than numberOfChannels.");
+}
+
+</script>
+
+<script src=""
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (123995 => 123996)


--- trunk/Source/WebCore/ChangeLog	2012-07-30 05:22:58 UTC (rev 123995)
+++ trunk/Source/WebCore/ChangeLog	2012-07-30 05:28:45 UTC (rev 123996)
@@ -1,3 +1,24 @@
+2012-07-29  Li Yin  <[email protected]>
+
+        getChannelData should raise exception when index is more than numberOfChannels.
+        https://bugs.webkit.org/show_bug.cgi?id=92223
+
+        Reviewed by Kentaro Hara.
+
+        Spec: https://dvcs.w3.org/hg/audio/raw-file/tip/webaudio/specification.html#AudioBuffer-section
+        In getChannelData function, the index value MUST be less than numberOfChannels
+        or an exception will be thrown.
+
+        Test: webaudio/audiobuffer.html
+
+        * Modules/webaudio/AudioBuffer.cpp:
+        (WebCore::AudioBuffer::getChannelData):
+        (WebCore):
+        * Modules/webaudio/AudioBuffer.h:
+        (WebCore):
+        (AudioBuffer):
+        * Modules/webaudio/AudioBuffer.idl: raise exception when index is not less than numberOfChannels.
+
 2012-07-29  Sukolsak Sakshuwong  <[email protected]>
 
         forward-delete in the last cell of a table moves the caret after the table

Modified: trunk/Source/WebCore/Modules/webaudio/AudioBuffer.cpp (123995 => 123996)


--- trunk/Source/WebCore/Modules/webaudio/AudioBuffer.cpp	2012-07-30 05:22:58 UTC (rev 123995)
+++ trunk/Source/WebCore/Modules/webaudio/AudioBuffer.cpp	2012-07-30 05:28:45 UTC (rev 123996)
@@ -90,6 +90,16 @@
     m_channels.clear();
 }
 
+Float32Array* AudioBuffer::getChannelData(unsigned channelIndex, ExceptionCode& ec)
+{
+    if (channelIndex >= m_channels.size()) {
+        ec = SYNTAX_ERR;
+        return 0;
+    }
+
+    return m_channels[channelIndex].get();
+}
+
 Float32Array* AudioBuffer::getChannelData(unsigned channelIndex)
 {
     if (channelIndex >= m_channels.size())

Modified: trunk/Source/WebCore/Modules/webaudio/AudioBuffer.h (123995 => 123996)


--- trunk/Source/WebCore/Modules/webaudio/AudioBuffer.h	2012-07-30 05:22:58 UTC (rev 123995)
+++ trunk/Source/WebCore/Modules/webaudio/AudioBuffer.h	2012-07-30 05:28:45 UTC (rev 123996)
@@ -38,7 +38,9 @@
 namespace WebCore {
 
 class AudioBus;
-    
+
+typedef int ExceptionCode;
+
 class AudioBuffer : public RefCounted<AudioBuffer> {
 public:   
     static PassRefPtr<AudioBuffer> create(unsigned numberOfChannels, size_t numberOfFrames, float sampleRate);
@@ -53,6 +55,7 @@
 
     // Channel data access
     unsigned numberOfChannels() const { return m_channels.size(); }
+    Float32Array* getChannelData(unsigned channelIndex, ExceptionCode&);
     Float32Array* getChannelData(unsigned channelIndex);
     void zero();
 

Modified: trunk/Source/WebCore/Modules/webaudio/AudioBuffer.idl (123995 => 123996)


--- trunk/Source/WebCore/Modules/webaudio/AudioBuffer.idl	2012-07-30 05:22:58 UTC (rev 123995)
+++ trunk/Source/WebCore/Modules/webaudio/AudioBuffer.idl	2012-07-30 05:28:45 UTC (rev 123996)
@@ -38,6 +38,7 @@
 
         // Channel access
         readonly attribute unsigned long numberOfChannels;
-        Float32Array getChannelData(in unsigned long channelIndex);
+        Float32Array getChannelData(in unsigned long channelIndex)
+            raises(DOMException);
     };
 }
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to