Title: [200198] trunk
Revision
200198
Author
[email protected]
Date
2016-04-28 10:36:33 -0700 (Thu, 28 Apr 2016)

Log Message

Drop [UsePointersEvenForNonNullableObjectArguments] from MediaSource interfaces
https://bugs.webkit.org/show_bug.cgi?id=156904

Reviewed by Darin Adler.

Source/WebCore:

MediaSource::addSourceBuffer will now throw a TypeError if a null parameter is passed.
MediaSource::removeSourceBuffer will now throw a TypeError if a null parameter is passed.
SourceBuffer::appendBuffer will now throw a TypeError if a null parameter is passed.

Did some refactoring to use more references.

Covered by updated test.

* Modules/mediasource/MediaSource.cpp:
(WebCore::MediaSource::endOfStream):
(WebCore::MediaSource::addSourceBuffer):
(WebCore::MediaSource::removeSourceBuffer):
* Modules/mediasource/MediaSource.h:
* Modules/mediasource/MediaSource.idl:
* Modules/mediasource/SourceBuffer.cpp:
(WebCore::SourceBuffer::appendBuffer):
* Modules/mediasource/SourceBuffer.h:
* Modules/mediasource/SourceBuffer.idl:
* Modules/mediasource/SourceBufferList.cpp:
(WebCore::SourceBufferList::add):
(WebCore::SourceBufferList::remove):
* Modules/mediasource/SourceBufferList.h:

LayoutTests:

* http/tests/media/media-source/mediasource-addsourcebuffer.html: Changing expected exception to TypeError.
* http/tests/media/media-source/mediasource-append-buffer-expected.txt:
* http/tests/media/media-source/mediasource-append-buffer.html: Checking passing null or undefined to
appendBuffer, addSourceBuffer and removeSourceBuffer.
* media/media-source/media-source-addsourcebuffer-expected.txt:
* media/media-source/media-source-addsourcebuffer.html: Removing redundant test.

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (200197 => 200198)


--- trunk/LayoutTests/ChangeLog	2016-04-28 17:35:45 UTC (rev 200197)
+++ trunk/LayoutTests/ChangeLog	2016-04-28 17:36:33 UTC (rev 200198)
@@ -1,3 +1,18 @@
+2016-04-28  Youenn Fablet  <[email protected]>
+
+        Drop [UsePointersEvenForNonNullableObjectArguments] from MediaSource interfaces
+        https://bugs.webkit.org/show_bug.cgi?id=156904
+
+        Reviewed by Darin Adler.
+
+        * http/tests/media/media-source/mediasource-addsourcebuffer.html: Changing expected exception to TypeError.
+        * http/tests/media/media-source/mediasource-append-buffer-expected.txt:
+        * http/tests/media/media-source/mediasource-append-buffer.html: Checking passing null or undefined to
+        appendBuffer, addSourceBuffer and removeSourceBuffer.
+        * media/media-source/media-source-addsourcebuffer-expected.txt:
+        * media/media-source/media-source-addsourcebuffer.html: Removing redundant test.
+
+
 2016-04-27  Ada Chan  <[email protected]>
 
         Set overflow: hidden on ::-webkit-media-controls in mediaControlsApple.css

Modified: trunk/LayoutTests/http/tests/media/media-source/mediasource-addsourcebuffer.html (200197 => 200198)


--- trunk/LayoutTests/http/tests/media/media-source/mediasource-addsourcebuffer.html	2016-04-28 17:35:45 UTC (rev 200197)
+++ trunk/LayoutTests/http/tests/media/media-source/mediasource-addsourcebuffer.html	2016-04-28 17:36:33 UTC (rev 200198)
@@ -10,7 +10,7 @@
         <script>
           mediasource_test(function(test, mediaElement, mediaSource)
           {
-              assert_throws("InvalidAccessError",
+              assert_throws(new TypeError(),
                           function() { mediaSource.addSourceBuffer(""); },
                           "addSourceBuffer() threw an exception when passed an empty string.");
               test.done();

Modified: trunk/LayoutTests/http/tests/media/media-source/mediasource-append-buffer-expected.txt (200197 => 200198)


--- trunk/LayoutTests/http/tests/media/media-source/mediasource-append-buffer-expected.txt	2016-04-28 17:35:45 UTC (rev 200197)
+++ trunk/LayoutTests/http/tests/media/media-source/mediasource-append-buffer-expected.txt	2016-04-28 17:36:33 UTC (rev 200198)
@@ -9,4 +9,5 @@
 PASS Test set SourceBuffer.timestampOffset during a pending appendBuffer(). 
 PASS Test appending an empty ArrayBufferView. 
 PASS Test appending an empty ArrayBuffer. 
+PASS Test passing null or undefined to some MediaSource and SourceBuffer API methods. 
 

Modified: trunk/LayoutTests/http/tests/media/media-source/mediasource-append-buffer.html (200197 => 200198)


--- trunk/LayoutTests/http/tests/media/media-source/mediasource-append-buffer.html	2016-04-28 17:35:45 UTC (rev 200197)
+++ trunk/LayoutTests/http/tests/media/media-source/mediasource-append-buffer.html	2016-04-28 17:36:33 UTC (rev 200198)
@@ -245,6 +245,18 @@
               });
           }, "Test appending an empty ArrayBuffer.");
 
+          mediasource_test(function(test, mediaElement, mediaSource)
+          {
+              assert_throws(new TypeError(), function() { mediaSource.addSourceBuffer(MediaSourceUtil.VIDEO_ONLY_TYPE).appendBufer(null); });
+              assert_throws(new TypeError(), function() { mediaSource.addSourceBuffer(MediaSourceUtil.VIDEO_ONLY_TYPE).appendBufer(undefined); });
+              assert_throws(new TypeError(), function() { mediaSource.removeSourceBuffer(null); });
+              assert_throws(new TypeError(), function() { mediaSource.removeSourceBuffer(undefined); });
+              assert_throws(new TypeError(), function() { mediaSource.addSourceBuffer(null); });
+              assert_throws(new TypeError(), function() { mediaSource.addSourceBuffer(undefined); });
+
+              test.done();
+          }, "Test passing null or undefined to some MediaSource and SourceBuffer API methods.");
+
         </script>
     </body>
 </html>

Modified: trunk/LayoutTests/media/media-source/media-source-addsourcebuffer-expected.txt (200197 => 200198)


--- trunk/LayoutTests/media/media-source/media-source-addsourcebuffer-expected.txt	2016-04-28 17:35:45 UTC (rev 200197)
+++ trunk/LayoutTests/media/media-source/media-source-addsourcebuffer-expected.txt	2016-04-28 17:36:33 UTC (rev 200198)
@@ -1,6 +1,5 @@
 
 TEST(source.addSourceBuffer("invalid")) THROWS(DOMException.NOT_SUPPORTED_ERR) OK
-TEST(source.addSourceBuffer("")) THROWS(DOMException.INVALID_ACCESS_ERR) OK
 EXPECTED (MediaSource.isTypeSupported("invalid") == 'false') OK
 EXPECTED (MediaSource.isTypeSupported("video/mock; codecs=mock") == 'true') OK
 RUN(video.src = ""

Modified: trunk/LayoutTests/media/media-source/media-source-addsourcebuffer.html (200197 => 200198)


--- trunk/LayoutTests/media/media-source/media-source-addsourcebuffer.html	2016-04-28 17:35:45 UTC (rev 200197)
+++ trunk/LayoutTests/media/media-source/media-source-addsourcebuffer.html	2016-04-28 17:36:33 UTC (rev 200198)
@@ -16,7 +16,6 @@
 
         source = new MediaSource();
         testDOMException('source.addSourceBuffer("invalid")', 'DOMException.NOT_SUPPORTED_ERR');
-        testDOMException('source.addSourceBuffer("")', 'DOMException.INVALID_ACCESS_ERR');
         testExpected('MediaSource.isTypeSupported("invalid")', false);
         testExpected('MediaSource.isTypeSupported("video/mock; codecs=mock")', true);
 

Modified: trunk/Source/WebCore/ChangeLog (200197 => 200198)


--- trunk/Source/WebCore/ChangeLog	2016-04-28 17:35:45 UTC (rev 200197)
+++ trunk/Source/WebCore/ChangeLog	2016-04-28 17:36:33 UTC (rev 200198)
@@ -1,5 +1,35 @@
 2016-04-28  Youenn Fablet  <[email protected]>
 
+        Drop [UsePointersEvenForNonNullableObjectArguments] from MediaSource interfaces
+        https://bugs.webkit.org/show_bug.cgi?id=156904
+
+        Reviewed by Darin Adler.
+
+        MediaSource::addSourceBuffer will now throw a TypeError if a null parameter is passed.
+        MediaSource::removeSourceBuffer will now throw a TypeError if a null parameter is passed.
+        SourceBuffer::appendBuffer will now throw a TypeError if a null parameter is passed.
+
+        Did some refactoring to use more references.
+
+        Covered by updated test.
+
+        * Modules/mediasource/MediaSource.cpp:
+        (WebCore::MediaSource::endOfStream):
+        (WebCore::MediaSource::addSourceBuffer):
+        (WebCore::MediaSource::removeSourceBuffer):
+        * Modules/mediasource/MediaSource.h:
+        * Modules/mediasource/MediaSource.idl:
+        * Modules/mediasource/SourceBuffer.cpp:
+        (WebCore::SourceBuffer::appendBuffer):
+        * Modules/mediasource/SourceBuffer.h:
+        * Modules/mediasource/SourceBuffer.idl:
+        * Modules/mediasource/SourceBufferList.cpp:
+        (WebCore::SourceBufferList::add):
+        (WebCore::SourceBufferList::remove):
+        * Modules/mediasource/SourceBufferList.h:
+
+2016-04-28  Youenn Fablet  <[email protected]>
+
         Drop [UsePointersEvenForNonNullableObjectArguments] from Node
         https://bugs.webkit.org/show_bug.cgi?id=156978
 

Modified: trunk/Source/WebCore/Modules/mediasource/MediaSource.cpp (200197 => 200198)


--- trunk/Source/WebCore/Modules/mediasource/MediaSource.cpp	2016-04-28 17:35:45 UTC (rev 200197)
+++ trunk/Source/WebCore/Modules/mediasource/MediaSource.cpp	2016-04-28 17:36:33 UTC (rev 200198)
@@ -414,11 +414,6 @@
     onReadyStateChange(oldState, state);
 }
 
-static bool SourceBufferIsUpdating(RefPtr<SourceBuffer>& sourceBuffer)
-{
-    return sourceBuffer->updating();
-}
-
 void MediaSource::endOfStream(ExceptionCode& ec)
 {
     endOfStream(emptyAtom, ec);
@@ -436,7 +431,7 @@
 
     // 2. If the updating attribute equals true on any SourceBuffer in sourceBuffers, then throw an
     // INVALID_STATE_ERR exception and abort these steps.
-    if (std::any_of(m_sourceBuffers->begin(), m_sourceBuffers->end(), SourceBufferIsUpdating)) {
+    if (std::any_of(m_sourceBuffers->begin(), m_sourceBuffers->end(), [](RefPtr<SourceBuffer>& sourceBuffer) { return sourceBuffer->updating(); })) {
         ec = INVALID_STATE_ERR;
         return;
     }
@@ -519,10 +514,9 @@
     // 2.2 http://www.w3.org/TR/media-source/#widl-MediaSource-addSourceBuffer-SourceBuffer-DOMString-type
     // When this method is invoked, the user agent must run the following steps:
 
-    // 1. If type is null or an empty then throw an INVALID_ACCESS_ERR exception and
-    // abort these steps.
-    if (type.isNull() || type.isEmpty()) {
-        ec = INVALID_ACCESS_ERR;
+    // 1. If type is an empty string then throw a TypeError exception and abort these steps.
+    if (type.isEmpty()) {
+        ec = TypeError;
         return nullptr;
     }
 
@@ -551,7 +545,7 @@
         return nullptr;
     }
 
-    RefPtr<SourceBuffer> buffer = SourceBuffer::create(sourceBufferPrivate.releaseNonNull(), this);
+    Ref<SourceBuffer> buffer = SourceBuffer::create(sourceBufferPrivate.releaseNonNull(), this);
 
     // 6. Set the generate timestamps flag on the new object to the value in the "Generate Timestamps Flag"
     // column of the byte stream format registry [MSE-REGISTRY] entry that is associated with type.
@@ -566,27 +560,21 @@
     // ↳ Set the mode attribute on the new object to "segments".
     buffer->setMode(shouldGenerateTimestamps ? SourceBuffer::sequenceKeyword() : SourceBuffer::segmentsKeyword(), IGNORE_EXCEPTION);
 
+    SourceBuffer* result = buffer.ptr();
+
     // 8. Add the new object to sourceBuffers and fire a addsourcebuffer on that object.
-    m_sourceBuffers->add(buffer);
+    m_sourceBuffers->add(WTFMove(buffer));
     regenerateActiveSourceBuffers();
 
     // 9. Return the new object to the caller.
-    return buffer.get();
+    return result;
 }
 
-void MediaSource::removeSourceBuffer(SourceBuffer* buffer, ExceptionCode& ec)
+void MediaSource::removeSourceBuffer(SourceBuffer& buffer, ExceptionCode& ec)
 {
     LOG(MediaSource, "MediaSource::removeSourceBuffer() %p", this);
-    RefPtr<SourceBuffer> protect(buffer);
+    Ref<SourceBuffer> protect(buffer);
 
-    // 2.2 https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-source.html#widl-MediaSource-removeSourceBuffer-void-SourceBuffer-sourceBuffer
-    // 1. If sourceBuffer is null then throw an INVALID_ACCESS_ERR exception and
-    // abort these steps.
-    if (!buffer) {
-        ec = INVALID_ACCESS_ERR;
-        return;
-    }
-
     // 2. If sourceBuffer specifies an object that is not in sourceBuffers then
     // throw a NOT_FOUND_ERR exception and abort these steps.
     if (!m_sourceBuffers->length() || !m_sourceBuffers->contains(buffer)) {
@@ -595,10 +583,10 @@
     }
 
     // 3. If the sourceBuffer.updating attribute equals true, then run the following steps: ...
-    buffer->abortIfUpdating();
+    buffer.abortIfUpdating();
 
     // 4. Let SourceBuffer audioTracks list equal the AudioTrackList object returned by sourceBuffer.audioTracks.
-    RefPtr<AudioTrackList> audioTracks = buffer->audioTracks();
+    RefPtr<AudioTrackList> audioTracks = buffer.audioTracks();
 
     // 5. If the SourceBuffer audioTracks list is not empty, then run the following steps:
     if (audioTracks->length()) {
@@ -638,7 +626,7 @@
     }
 
     // 6. Let SourceBuffer videoTracks list equal the VideoTrackList object returned by sourceBuffer.videoTracks.
-    RefPtr<VideoTrackList> videoTracks = buffer->videoTracks();
+    RefPtr<VideoTrackList> videoTracks = buffer.videoTracks();
 
     // 7. If the SourceBuffer videoTracks list is not empty, then run the following steps:
     if (videoTracks->length()) {
@@ -678,7 +666,7 @@
     }
 
     // 8. Let SourceBuffer textTracks list equal the TextTrackList object returned by sourceBuffer.textTracks.
-    RefPtr<TextTrackList> textTracks = buffer->textTracks();
+    RefPtr<TextTrackList> textTracks = buffer.textTracks();
 
     // 9. If the SourceBuffer textTracks list is not empty, then run the following steps:
     if (textTracks->length()) {
@@ -726,7 +714,7 @@
     m_sourceBuffers->remove(buffer);
     
     // 12. Destroy all resources for sourceBuffer.
-    buffer->removedFromMediaSource();
+    buffer.removedFromMediaSource();
 }
 
 bool MediaSource::isTypeSupported(const String& type)

Modified: trunk/Source/WebCore/Modules/mediasource/MediaSource.h (200197 => 200198)


--- trunk/Source/WebCore/Modules/mediasource/MediaSource.h	2016-04-28 17:35:45 UTC (rev 200197)
+++ trunk/Source/WebCore/Modules/mediasource/MediaSource.h	2016-04-28 17:36:33 UTC (rev 200198)
@@ -96,7 +96,7 @@
     SourceBufferList* sourceBuffers() { return m_sourceBuffers.get(); }
     SourceBufferList* activeSourceBuffers() { return m_activeSourceBuffers.get(); }
     SourceBuffer* addSourceBuffer(const String& type, ExceptionCode&);
-    void removeSourceBuffer(SourceBuffer*, ExceptionCode&);
+    void removeSourceBuffer(SourceBuffer&, ExceptionCode&);
     static bool isTypeSupported(const String& type);
 
     // EventTarget interface

Modified: trunk/Source/WebCore/Modules/mediasource/MediaSource.idl (200197 => 200198)


--- trunk/Source/WebCore/Modules/mediasource/MediaSource.idl	2016-04-28 17:35:45 UTC (rev 200197)
+++ trunk/Source/WebCore/Modules/mediasource/MediaSource.idl	2016-04-28 17:36:33 UTC (rev 200198)
@@ -34,12 +34,11 @@
 };
 
 [
+    ActiveDOMObject,
     Conditional=MEDIA_SOURCE,
-    ActiveDOMObject,
-    EnabledBySetting=MediaSource,
     Constructor,
     ConstructorCallWith=ScriptExecutionContext,
-    UsePointersEvenForNonNullableObjectArguments,
+    EnabledBySetting=MediaSource,
 ] interface MediaSource : EventTarget {
     // All the source buffers created by this object.
     readonly attribute SourceBufferList sourceBuffers;
@@ -49,7 +48,8 @@
 
     [SetterRaisesException] attribute unrestricted double duration;
 
-    [RaisesException] SourceBuffer addSourceBuffer(DOMString type);
+    // FIXME: type should not be nullable.
+    [RaisesException] SourceBuffer addSourceBuffer(DOMString? type);
     [RaisesException] void removeSourceBuffer(SourceBuffer buffer);
 
     readonly attribute DOMString readyState;

Modified: trunk/Source/WebCore/Modules/mediasource/SourceBuffer.cpp (200197 => 200198)


--- trunk/Source/WebCore/Modules/mediasource/SourceBuffer.cpp	2016-04-28 17:35:45 UTC (rev 200197)
+++ trunk/Source/WebCore/Modules/mediasource/SourceBuffer.cpp	2016-04-28 17:36:33 UTC (rev 200198)
@@ -271,26 +271,15 @@
 }
 
 
-void SourceBuffer::appendBuffer(PassRefPtr<ArrayBuffer> data, ExceptionCode& ec)
+void SourceBuffer::appendBuffer(ArrayBuffer& data, ExceptionCode& ec)
 {
-    // Section 3.2 appendBuffer()
-    // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-source.html#widl-SourceBuffer-appendBuffer-void-ArrayBufferView-data
-    // 1. If data is null then throw an INVALID_ACCESS_ERR exception and abort these steps.
-    if (!data) {
-        ec = INVALID_ACCESS_ERR;
-        return;
-    }
-
-    appendBufferInternal(static_cast<unsigned char*>(data->data()), data->byteLength(), ec);
+    appendBufferInternal(static_cast<unsigned char*>(data.data()), data.byteLength(), ec);
 }
 
-void SourceBuffer::appendBuffer(PassRefPtr<ArrayBufferView> data, ExceptionCode& ec)
+void SourceBuffer::appendBuffer(ArrayBufferView* data, ExceptionCode& ec)
 {
-    // Section 3.2 appendBuffer()
-    // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-source.html#widl-SourceBuffer-appendBuffer-void-ArrayBufferView-data
-    // 1. If data is null then throw an INVALID_ACCESS_ERR exception and abort these steps.
     if (!data) {
-        ec = INVALID_ACCESS_ERR;
+        ec = TypeError;
         return;
     }
 

Modified: trunk/Source/WebCore/Modules/mediasource/SourceBuffer.h (200197 => 200198)


--- trunk/Source/WebCore/Modules/mediasource/SourceBuffer.h	2016-04-28 17:35:45 UTC (rev 200197)
+++ trunk/Source/WebCore/Modules/mediasource/SourceBuffer.h	2016-04-28 17:36:33 UTC (rev 200198)
@@ -86,8 +86,8 @@
     double appendWindowEnd() const;
     void setAppendWindowEnd(double, ExceptionCode&);
 
-    void appendBuffer(PassRefPtr<ArrayBuffer> data, ExceptionCode&);
-    void appendBuffer(PassRefPtr<ArrayBufferView> data, ExceptionCode&);
+    void appendBuffer(ArrayBuffer&, ExceptionCode&);
+    void appendBuffer(ArrayBufferView*, ExceptionCode&);
     void abort(ExceptionCode&);
     void remove(double start, double end, ExceptionCode&);
     void remove(const MediaTime&, const MediaTime&, ExceptionCode&);

Modified: trunk/Source/WebCore/Modules/mediasource/SourceBuffer.idl (200197 => 200198)


--- trunk/Source/WebCore/Modules/mediasource/SourceBuffer.idl	2016-04-28 17:35:45 UTC (rev 200197)
+++ trunk/Source/WebCore/Modules/mediasource/SourceBuffer.idl	2016-04-28 17:36:33 UTC (rev 200198)
@@ -34,11 +34,10 @@
 };
 
 [
-    Conditional=MEDIA_SOURCE,
-    NoInterfaceObject,
     ActiveDOMObject,
-    UsePointersEvenForNonNullableObjectArguments,
+    Conditional=MEDIA_SOURCE,
     ExportMacro=WEBCORE_EXPORT,
+    NoInterfaceObject,
 ] interface SourceBuffer : EventTarget {
 
     [SetterRaisesException] attribute AppendMode mode;

Modified: trunk/Source/WebCore/Modules/mediasource/SourceBufferList.cpp (200197 => 200198)


--- trunk/Source/WebCore/Modules/mediasource/SourceBufferList.cpp	2016-04-28 17:35:45 UTC (rev 200197)
+++ trunk/Source/WebCore/Modules/mediasource/SourceBufferList.cpp	2016-04-28 17:36:33 UTC (rev 200198)
@@ -49,15 +49,15 @@
     ASSERT(m_list.isEmpty());
 }
 
-void SourceBufferList::add(PassRefPtr<SourceBuffer> buffer)
+void SourceBufferList::add(Ref<SourceBuffer>&& buffer)
 {
-    m_list.append(buffer);
+    m_list.append(WTFMove(buffer));
     scheduleEvent(eventNames().addsourcebufferEvent);
 }
 
-void SourceBufferList::remove(SourceBuffer* buffer)
+void SourceBufferList::remove(SourceBuffer& buffer)
 {
-    size_t index = m_list.find(buffer);
+    size_t index = m_list.find(&buffer);
     if (index == notFound)
         return;
     m_list.remove(index);

Modified: trunk/Source/WebCore/Modules/mediasource/SourceBufferList.h (200197 => 200198)


--- trunk/Source/WebCore/Modules/mediasource/SourceBufferList.h	2016-04-28 17:35:45 UTC (rev 200197)
+++ trunk/Source/WebCore/Modules/mediasource/SourceBufferList.h	2016-04-28 17:36:33 UTC (rev 200198)
@@ -52,11 +52,11 @@
     virtual ~SourceBufferList();
 
     unsigned long length() const { return m_list.size(); }
-    SourceBuffer* item(unsigned long index) const { return (index < m_list.size()) ? m_list[index].get() : 0; }
+    SourceBuffer* item(unsigned long index) const { return (index < m_list.size()) ? m_list[index].get() : nullptr; }
 
-    void add(PassRefPtr<SourceBuffer>);
-    void remove(SourceBuffer*);
-    bool contains(SourceBuffer* buffer) { return m_list.find(buffer) != notFound; }
+    void add(Ref<SourceBuffer>&&);
+    void remove(SourceBuffer&);
+    bool contains(SourceBuffer& buffer) { return m_list.find(&buffer) != notFound; }
     void clear();
     void swap(Vector<RefPtr<SourceBuffer>>&);
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to