<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[208002] trunk/Source/WebCore</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/208002">208002</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2016-10-27 13:36:12 -0700 (Thu, 27 Oct 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>BufferSource should behave as an union
https://bugs.webkit.org/show_bug.cgi?id=164056

Patch by Zan Dobersek &lt;zdobersek@igalia.com&gt; on 2016-10-27
Reviewed by Chris Dumez.

WebIDL typedefs BufferSource as (ArrayBufferView or ArrayBuffer).
To follow that definition, IDLBufferSource is now type-aliased
to IDLUnion&lt;IDLInterface&lt;ArrayBufferView&gt;, IDLInterface&lt;ArrayBuffer&gt;&gt;.

Converter&lt;IDLBufferSource&gt; template specialization can now be
removed since the default specialization for IDLUnion will be
used.

C++ implementations still work through a BufferSource object.
That class now has an implicit constructor that consumes the
Variant object. The data() and length() methods on the class
now iterate the variant to find an existing object that can
provide a pointer to the data or the length of it.

* Modules/mediasource/SourceBuffer.cpp:
(WebCore::SourceBuffer::appendBuffer):
* bindings/generic/IDLTypes.h:
* bindings/js/BufferSource.h:
(WebCore::BufferSource::BufferSource):
(WebCore::BufferSource::data):
(WebCore::BufferSource::length):
* bindings/js/JSDOMConvert.h:
(WebCore::Converter&lt;IDLBufferSource&gt;::convert): Deleted.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreModulesmediasourceSourceBuffercpp">trunk/Source/WebCore/Modules/mediasource/SourceBuffer.cpp</a></li>
<li><a href="#trunkSourceWebCorebindingsgenericIDLTypesh">trunk/Source/WebCore/bindings/generic/IDLTypes.h</a></li>
<li><a href="#trunkSourceWebCorebindingsjsBufferSourceh">trunk/Source/WebCore/bindings/js/BufferSource.h</a></li>
<li><a href="#trunkSourceWebCorebindingsjsJSDOMConverth">trunk/Source/WebCore/bindings/js/JSDOMConvert.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (208001 => 208002)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-10-27 20:23:06 UTC (rev 208001)
+++ trunk/Source/WebCore/ChangeLog        2016-10-27 20:36:12 UTC (rev 208002)
</span><span class="lines">@@ -1,3 +1,34 @@
</span><ins>+2016-10-27  Zan Dobersek  &lt;zdobersek@igalia.com&gt;
+
+        BufferSource should behave as an union
+        https://bugs.webkit.org/show_bug.cgi?id=164056
+
+        Reviewed by Chris Dumez.
+
+        WebIDL typedefs BufferSource as (ArrayBufferView or ArrayBuffer).
+        To follow that definition, IDLBufferSource is now type-aliased
+        to IDLUnion&lt;IDLInterface&lt;ArrayBufferView&gt;, IDLInterface&lt;ArrayBuffer&gt;&gt;.
+
+        Converter&lt;IDLBufferSource&gt; template specialization can now be
+        removed since the default specialization for IDLUnion will be
+        used.
+
+        C++ implementations still work through a BufferSource object.
+        That class now has an implicit constructor that consumes the
+        Variant object. The data() and length() methods on the class
+        now iterate the variant to find an existing object that can
+        provide a pointer to the data or the length of it.
+
+        * Modules/mediasource/SourceBuffer.cpp:
+        (WebCore::SourceBuffer::appendBuffer):
+        * bindings/generic/IDLTypes.h:
+        * bindings/js/BufferSource.h:
+        (WebCore::BufferSource::BufferSource):
+        (WebCore::BufferSource::data):
+        (WebCore::BufferSource::length):
+        * bindings/js/JSDOMConvert.h:
+        (WebCore::Converter&lt;IDLBufferSource&gt;::convert): Deleted.
+
</ins><span class="cx"> 2016-10-27  Chris Dumez  &lt;cdumez@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Merge Element::ShadowRootMode and ShadowRoot::Mode enumerations
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesmediasourceSourceBuffercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/mediasource/SourceBuffer.cpp (208001 => 208002)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/mediasource/SourceBuffer.cpp        2016-10-27 20:23:06 UTC (rev 208001)
+++ trunk/Source/WebCore/Modules/mediasource/SourceBuffer.cpp        2016-10-27 20:36:12 UTC (rev 208002)
</span><span class="lines">@@ -234,7 +234,7 @@
</span><span class="cx"> 
</span><span class="cx"> ExceptionOr&lt;void&gt; SourceBuffer::appendBuffer(const BufferSource&amp; data)
</span><span class="cx"> {
</span><del>-    return appendBufferInternal(static_cast&lt;const unsigned char*&gt;(data.data), data.length);
</del><ins>+    return appendBufferInternal(static_cast&lt;const unsigned char*&gt;(data.data()), data.length());
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void SourceBuffer::resetParserState()
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsgenericIDLTypesh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/generic/IDLTypes.h (208001 => 208002)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/generic/IDLTypes.h        2016-10-27 20:23:06 UTC (rev 208001)
+++ trunk/Source/WebCore/bindings/generic/IDLTypes.h        2016-10-27 20:36:12 UTC (rev 208002)
</span><span class="lines">@@ -30,12 +30,13 @@
</span><span class="cx"> #include &lt;wtf/text/WTFString.h&gt;
</span><span class="cx"> 
</span><span class="cx"> namespace JSC {
</span><ins>+class ArrayBuffer;
+class ArrayBufferView;
</ins><span class="cx"> class JSValue;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><del>-class BufferSource;
</del><span class="cx"> template &lt;typename Value&gt; class DOMPromise;
</span><span class="cx"> 
</span><span class="cx"> template&lt;typename T&gt;
</span><span class="lines">@@ -137,7 +138,7 @@
</span><span class="cx">     static double extractValueFromNullable(double value) { return value; }
</span><span class="cx"> };
</span><span class="cx"> 
</span><del>-struct IDLBufferSource : IDLType&lt;BufferSource&gt; { };
</del><ins>+using IDLBufferSource = IDLUnion&lt;IDLInterface&lt;JSC::ArrayBufferView&gt;, IDLInterface&lt;JSC::ArrayBuffer&gt;&gt;;
</ins><span class="cx"> 
</span><span class="cx"> // Helper predicates
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsjsBufferSourceh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/js/BufferSource.h (208001 => 208002)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/js/BufferSource.h        2016-10-27 20:23:06 UTC (rev 208001)
+++ trunk/Source/WebCore/bindings/js/BufferSource.h        2016-10-27 20:36:12 UTC (rev 208002)
</span><span class="lines">@@ -25,12 +25,35 @@
</span><span class="cx"> 
</span><span class="cx"> #pragma once
</span><span class="cx"> 
</span><ins>+#include &lt;runtime/ArrayBuffer.h&gt;
+#include &lt;runtime/ArrayBufferView.h&gt;
+#include &lt;wtf/RefPtr.h&gt;
+#include &lt;wtf/Variant.h&gt;
+
</ins><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><span class="cx"> class BufferSource {
</span><span class="cx"> public:
</span><del>-    const uint8_t* data;
-    size_t length;
</del><ins>+    BufferSource(WTF::Variant&lt;RefPtr&lt;JSC::ArrayBufferView&gt;, RefPtr&lt;JSC::ArrayBuffer&gt;&gt;&amp;&amp; variant)
+        : m_variant(WTFMove(variant))
+    { }
+
+    const uint8_t* data() const
+    {
+        return WTF::visit([](auto&amp; buffer) -&gt; const uint8_t* {
+            return static_cast&lt;const uint8_t*&gt;(buffer-&gt;data());
+        }, m_variant);
+    }
+
+    size_t length() const
+    {
+        return WTF::visit([](auto&amp; buffer) -&gt; size_t {
+            return buffer-&gt;byteLength();
+        }, m_variant);
+    }
+
+private:
+    WTF::Variant&lt;RefPtr&lt;JSC::ArrayBufferView&gt;, RefPtr&lt;JSC::ArrayBuffer&gt;&gt; m_variant;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsjsJSDOMConverth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/js/JSDOMConvert.h (208001 => 208002)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/js/JSDOMConvert.h        2016-10-27 20:23:06 UTC (rev 208001)
+++ trunk/Source/WebCore/bindings/js/JSDOMConvert.h        2016-10-27 20:36:12 UTC (rev 208002)
</span><span class="lines">@@ -1031,27 +1031,6 @@
</span><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> // MARK: -
</span><del>-// MARK: BufferSource type
-
-template&lt;&gt; struct Converter&lt;IDLBufferSource&gt; : DefaultConverter&lt;IDLBufferSource&gt; {
-    using ReturnType = BufferSource;
-
-    static ReturnType convert(JSC::ExecState&amp; state, JSC::JSValue value)
-    {
-        JSC::VM&amp; vm = state.vm();
-        auto scope = DECLARE_THROW_SCOPE(vm);
-
-        if (JSC::ArrayBuffer* buffer = JSC::toArrayBuffer(value))
-            return { static_cast&lt;uint8_t*&gt;(buffer-&gt;data()), buffer-&gt;byteLength() };
-        if (RefPtr&lt;JSC::ArrayBufferView&gt; bufferView = toArrayBufferView(value))
-            return { static_cast&lt;uint8_t*&gt;(bufferView-&gt;baseAddress()), bufferView-&gt;byteLength() };
-
-        throwTypeError(&amp;state, scope, ASCIILiteral(&quot;Only ArrayBuffer and ArrayBufferView objects can be passed as BufferSource arguments&quot;));
-        return { nullptr, 0 };
-    }
-};
-
-// MARK: -
</del><span class="cx"> // MARK: Date type
</span><span class="cx"> 
</span><span class="cx"> template&lt;&gt; struct Converter&lt;IDLDate&gt; : DefaultConverter&lt;IDLDate&gt; {
</span></span></pre>
</div>
</div>

</body>
</html>