<!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>[282278] trunk</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/282278">282278</a></dd>
<dt>Author</dt> <dd>youenn@apple.com</dd>
<dt>Date</dt> <dd>2021-09-10 10:22:01 -0700 (Fri, 10 Sep 2021)</dd>
</dl>

<h3>Log Message</h3>
<pre>Allow to subclass WritableStream
https://bugs.webkit.org/show_bug.cgi?id=230146

Reviewed by Alex Christensen.

LayoutTests/imported/w3c:

* web-platform-tests/streams/idlharness.any-expected.txt:
* web-platform-tests/streams/idlharness.any.worker-expected.txt:
* web-platform-tests/streams/writable-streams/general.any-expected.txt:
* web-platform-tests/streams/writable-streams/general.any.worker-expected.txt:

Source/WebCore:

Introduce a WebIDL-based WritableStream C++ class.
To keep the existing implementation, the previous JS WritableStream implementation is wrapped around an InternalWritableStream C++ class
which is a wrapper around JS-builtins manipulated objects.
InternalWritableStream is made DOMGuarded to enable to keep a ref to the JS object from WritableStream.

Update JS built-in code to manage hopping to the InternalWritableStream JS object from the exposed WritableStream JS object.
We introduce getInternalWritableStream routine for that purpose.

Transition existing WritableStream users to the new C++ class.
Minor code generator change to make use of the now available JSWritableStream.

Covered by existing and rebased tests.

* CMakeLists.txt:
* DerivedSources-input.xcfilelist:
* DerivedSources-output.xcfilelist:
* DerivedSources.make:
* Modules/mediastream/RTCRtpSFrameTransform.cpp:
(WebCore::RTCRtpSFrameTransform::isAttached const):
(WebCore::RTCRtpSFrameTransform::createStreams):
(WebCore::RTCRtpSFrameTransform::readable):
(WebCore::RTCRtpSFrameTransform::writable):
* Modules/mediastream/RTCRtpSFrameTransform.h:
* Modules/streams/ReadableStream.js:
(pipeThrough):
* Modules/streams/TransformStreamInternals.js:
(initializeTransformStream):
(transformStreamErrorWritableAndUnblockWrite):
(transformStreamDefaultSinkWriteAlgorithm):
* Modules/streams/WritableStream.cpp: Added.
(WebCore::WritableStream::create):
(WebCore::WritableStream::WritableStream):
(WebCore::JSWritableStream::abort):
(WebCore::JSWritableStream::close):
(WebCore::JSWritableStream::getWriter):
* Modules/streams/WritableStream.h: Added.
(WebCore::WritableStream::lock):
(WebCore::WritableStream::locked const):
(WebCore::WritableStream::internalWritableStream):

* Modules/streams/WritableStream.idl:
* Modules/streams/WritableStream.js: Removed.
* Modules/streams/WritableStreamDefaultWriter.js:
(initializeWritableStreamDefaultWriter):
* Modules/streams/WritableStreamInternals.js:
(initializeWritableStreamSlots):
(writableStreamCloseForBindings):
(writableStreamAbortForBindings):
* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/InternalWritableStream.cpp: Added.
(WebCore::invokeWritableStreamFunction):
(WebCore::InternalWritableStream::create):
(WebCore::InternalWritableStream::locked const):
(WebCore::InternalWritableStream::lock):
(WebCore::InternalWritableStream::abort):
(WebCore::InternalWritableStream::close):
(WebCore::InternalWritableStream::getWriter):
* bindings/js/InternalWritableStream.h: Added.
* bindings/js/JSDOMGlobalObject.cpp:
(WebCore::JSC_DEFINE_HOST_FUNCTION):
(WebCore::JSDOMGlobalObject::addBuiltinGlobals):
* bindings/js/WebCoreBuiltinNames.h:
* bindings/js/WritableStream.cpp: Removed.
* bindings/js/WritableStream.h: Removed.
* bindings/scripts/CodeGeneratorJS.pm:
(AddToIncludesForIDLType):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsimportedw3cChangeLog">trunk/LayoutTests/imported/w3c/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsstreamsidlharnessanyexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/streams/idlharness.any-expected.txt</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsstreamsidlharnessanyworkerexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/streams/idlharness.any.worker-expected.txt</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsstreamswritablestreamsgeneralanyexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/streams/writable-streams/general.any-expected.txt</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsstreamswritablestreamsgeneralanyworkerexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/streams/writable-streams/general.any.worker-expected.txt</a></li>
<li><a href="#trunkSourceWebCoreCMakeListstxt">trunk/Source/WebCore/CMakeLists.txt</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreDerivedSourcesinputxcfilelist">trunk/Source/WebCore/DerivedSources-input.xcfilelist</a></li>
<li><a href="#trunkSourceWebCoreDerivedSourcesoutputxcfilelist">trunk/Source/WebCore/DerivedSources-output.xcfilelist</a></li>
<li><a href="#trunkSourceWebCoreDerivedSourcesmake">trunk/Source/WebCore/DerivedSources.make</a></li>
<li><a href="#trunkSourceWebCoreModulesmediastreamRTCRtpSFrameTransformcpp">trunk/Source/WebCore/Modules/mediastream/RTCRtpSFrameTransform.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesmediastreamRTCRtpSFrameTransformh">trunk/Source/WebCore/Modules/mediastream/RTCRtpSFrameTransform.h</a></li>
<li><a href="#trunkSourceWebCoreModulesstreamsReadableStreamjs">trunk/Source/WebCore/Modules/streams/ReadableStream.js</a></li>
<li><a href="#trunkSourceWebCoreModulesstreamsTransformStreamInternalsjs">trunk/Source/WebCore/Modules/streams/TransformStreamInternals.js</a></li>
<li><a href="#trunkSourceWebCoreModulesstreamsWritableStreamidl">trunk/Source/WebCore/Modules/streams/WritableStream.idl</a></li>
<li><a href="#trunkSourceWebCoreModulesstreamsWritableStreamDefaultWriterjs">trunk/Source/WebCore/Modules/streams/WritableStreamDefaultWriter.js</a></li>
<li><a href="#trunkSourceWebCoreModulesstreamsWritableStreamInternalsjs">trunk/Source/WebCore/Modules/streams/WritableStreamInternals.js</a></li>
<li><a href="#trunkSourceWebCoreSourcestxt">trunk/Source/WebCore/Sources.txt</a></li>
<li><a href="#trunkSourceWebCoreWebCorexcodeprojprojectpbxproj">trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkSourceWebCorebindingsjsJSDOMGlobalObjectcpp">trunk/Source/WebCore/bindings/js/JSDOMGlobalObject.cpp</a></li>
<li><a href="#trunkSourceWebCorebindingsjsWebCoreBuiltinNamesh">trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h</a></li>
<li><a href="#trunkSourceWebCorebindingsscriptsCodeGeneratorJSpm">trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreModulesstreamsWritableStreamcpp">trunk/Source/WebCore/Modules/streams/WritableStream.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesstreamsWritableStreamh">trunk/Source/WebCore/Modules/streams/WritableStream.h</a></li>
<li><a href="#trunkSourceWebCorebindingsjsInternalWritableStreamcpp">trunk/Source/WebCore/bindings/js/InternalWritableStream.cpp</a></li>
<li><a href="#trunkSourceWebCorebindingsjsInternalWritableStreamh">trunk/Source/WebCore/bindings/js/InternalWritableStream.h</a></li>
</ul>

<h3>Removed Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreModulesstreamsWritableStreamjs">trunk/Source/WebCore/Modules/streams/WritableStream.js</a></li>
<li><a href="#trunkSourceWebCorebindingsjsWritableStreamcpp">trunk/Source/WebCore/bindings/js/WritableStream.cpp</a></li>
<li><a href="#trunkSourceWebCorebindingsjsWritableStreamh">trunk/Source/WebCore/bindings/js/WritableStream.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsimportedw3cChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/ChangeLog (282277 => 282278)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/ChangeLog 2021-09-10 17:16:43 UTC (rev 282277)
+++ trunk/LayoutTests/imported/w3c/ChangeLog    2021-09-10 17:22:01 UTC (rev 282278)
</span><span class="lines">@@ -1,5 +1,17 @@
</span><span class="cx"> 2021-09-10  Youenn Fablet  <youenn@apple.com>
</span><span class="cx"> 
</span><ins>+        Allow to subclass WritableStream
+        https://bugs.webkit.org/show_bug.cgi?id=230146
+
+        Reviewed by Alex Christensen.
+
+        * web-platform-tests/streams/idlharness.any-expected.txt:
+        * web-platform-tests/streams/idlharness.any.worker-expected.txt:
+        * web-platform-tests/streams/writable-streams/general.any-expected.txt:
+        * web-platform-tests/streams/writable-streams/general.any.worker-expected.txt:
+
+2021-09-10  Youenn Fablet  <youenn@apple.com>
+
</ins><span class="cx">         Use RTCErrorEvent for data channel error event
</span><span class="cx">         https://bugs.webkit.org/show_bug.cgi?id=230090
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsstreamsidlharnessanyexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/streams/idlharness.any-expected.txt (282277 => 282278)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/streams/idlharness.any-expected.txt    2021-09-10 17:16:43 UTC (rev 282277)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/streams/idlharness.any-expected.txt       2021-09-10 17:22:01 UTC (rev 282278)
</span><span class="lines">@@ -128,7 +128,7 @@
</span><span class="cx"> PASS WritableStream interface: existence and properties of interface prototype object's "constructor" property
</span><span class="cx"> PASS WritableStream interface: existence and properties of interface prototype object's @@unscopables property
</span><span class="cx"> PASS WritableStream interface: attribute locked
</span><del>-FAIL WritableStream interface: operation abort(optional any) assert_equals: property has wrong .length expected 0 but got 1
</del><ins>+PASS WritableStream interface: operation abort(optional any)
</ins><span class="cx"> PASS WritableStream interface: operation close()
</span><span class="cx"> PASS WritableStream interface: operation getWriter()
</span><span class="cx"> PASS WritableStream must be primary interface of new WritableStream()
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsstreamsidlharnessanyworkerexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/streams/idlharness.any.worker-expected.txt (282277 => 282278)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/streams/idlharness.any.worker-expected.txt     2021-09-10 17:16:43 UTC (rev 282277)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/streams/idlharness.any.worker-expected.txt        2021-09-10 17:22:01 UTC (rev 282278)
</span><span class="lines">@@ -128,7 +128,7 @@
</span><span class="cx"> PASS WritableStream interface: existence and properties of interface prototype object's "constructor" property
</span><span class="cx"> PASS WritableStream interface: existence and properties of interface prototype object's @@unscopables property
</span><span class="cx"> PASS WritableStream interface: attribute locked
</span><del>-FAIL WritableStream interface: operation abort(optional any) assert_equals: property has wrong .length expected 0 but got 1
</del><ins>+PASS WritableStream interface: operation abort(optional any)
</ins><span class="cx"> PASS WritableStream interface: operation close()
</span><span class="cx"> PASS WritableStream interface: operation getWriter()
</span><span class="cx"> PASS WritableStream must be primary interface of new WritableStream()
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsstreamswritablestreamsgeneralanyexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/streams/writable-streams/general.any-expected.txt (282277 => 282278)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/streams/writable-streams/general.any-expected.txt      2021-09-10 17:16:43 UTC (rev 282277)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/streams/writable-streams/general.any-expected.txt 2021-09-10 17:22:01 UTC (rev 282278)
</span><span class="lines">@@ -13,6 +13,6 @@
</span><span class="cx"> PASS WritableStream's strategy.size should not be called as a method
</span><span class="cx"> PASS redundant releaseLock() is no-op
</span><span class="cx"> PASS ready promise should fire before closed on releaseLock
</span><del>-FAIL Subclassing WritableStream should work assert_true: Subclass object should be an instance of Subclass expected true got false
</del><ins>+PASS Subclassing WritableStream should work
</ins><span class="cx"> PASS the locked getter should return true if the stream has a writer
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsstreamswritablestreamsgeneralanyworkerexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/streams/writable-streams/general.any.worker-expected.txt (282277 => 282278)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/streams/writable-streams/general.any.worker-expected.txt       2021-09-10 17:16:43 UTC (rev 282277)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/streams/writable-streams/general.any.worker-expected.txt  2021-09-10 17:22:01 UTC (rev 282278)
</span><span class="lines">@@ -13,6 +13,6 @@
</span><span class="cx"> PASS WritableStream's strategy.size should not be called as a method
</span><span class="cx"> PASS redundant releaseLock() is no-op
</span><span class="cx"> PASS ready promise should fire before closed on releaseLock
</span><del>-FAIL Subclassing WritableStream should work assert_true: Subclass object should be an instance of Subclass expected true got false
</del><ins>+PASS Subclassing WritableStream should work
</ins><span class="cx"> PASS the locked getter should return true if the stream has a writer
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreCMakeListstxt"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/CMakeLists.txt (282277 => 282278)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/CMakeLists.txt      2021-09-10 17:16:43 UTC (rev 282277)
+++ trunk/Source/WebCore/CMakeLists.txt 2021-09-10 17:22:01 UTC (rev 282278)
</span><span class="lines">@@ -2058,7 +2058,6 @@
</span><span class="cx">     ${WEBCORE_DIR}/Modules/streams/TransformStream.js
</span><span class="cx">     ${WEBCORE_DIR}/Modules/streams/TransformStreamDefaultController.js
</span><span class="cx">     ${WEBCORE_DIR}/Modules/streams/TransformStreamInternals.js
</span><del>-    ${WEBCORE_DIR}/Modules/streams/WritableStream.js
</del><span class="cx">     ${WEBCORE_DIR}/Modules/streams/WritableStreamDefaultController.js
</span><span class="cx">     ${WEBCORE_DIR}/Modules/streams/WritableStreamDefaultWriter.js
</span><span class="cx">     ${WEBCORE_DIR}/Modules/streams/WritableStreamInternals.js
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (282277 => 282278)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog   2021-09-10 17:16:43 UTC (rev 282277)
+++ trunk/Source/WebCore/ChangeLog      2021-09-10 17:22:01 UTC (rev 282278)
</span><span class="lines">@@ -1,3 +1,78 @@
</span><ins>+2021-09-10  Youenn Fablet  <youenn@apple.com>
+
+        Allow to subclass WritableStream
+        https://bugs.webkit.org/show_bug.cgi?id=230146
+
+        Reviewed by Alex Christensen.
+
+        Introduce a WebIDL-based WritableStream C++ class.
+        To keep the existing implementation, the previous JS WritableStream implementation is wrapped around an InternalWritableStream C++ class
+        which is a wrapper around JS-builtins manipulated objects.
+        InternalWritableStream is made DOMGuarded to enable to keep a ref to the JS object from WritableStream.
+
+        Update JS built-in code to manage hopping to the InternalWritableStream JS object from the exposed WritableStream JS object.
+        We introduce getInternalWritableStream routine for that purpose.
+
+        Transition existing WritableStream users to the new C++ class.
+        Minor code generator change to make use of the now available JSWritableStream.
+
+        Covered by existing and rebased tests.
+
+        * CMakeLists.txt:
+        * DerivedSources-input.xcfilelist:
+        * DerivedSources-output.xcfilelist:
+        * DerivedSources.make:
+        * Modules/mediastream/RTCRtpSFrameTransform.cpp:
+        (WebCore::RTCRtpSFrameTransform::isAttached const):
+        (WebCore::RTCRtpSFrameTransform::createStreams):
+        (WebCore::RTCRtpSFrameTransform::readable):
+        (WebCore::RTCRtpSFrameTransform::writable):
+        * Modules/mediastream/RTCRtpSFrameTransform.h:
+        * Modules/streams/ReadableStream.js:
+        (pipeThrough):
+        * Modules/streams/TransformStreamInternals.js:
+        (initializeTransformStream):
+        (transformStreamErrorWritableAndUnblockWrite):
+        (transformStreamDefaultSinkWriteAlgorithm):
+        * Modules/streams/WritableStream.cpp: Added.
+        (WebCore::WritableStream::create):
+        (WebCore::WritableStream::WritableStream):
+        (WebCore::JSWritableStream::abort):
+        (WebCore::JSWritableStream::close):
+        (WebCore::JSWritableStream::getWriter):
+        * Modules/streams/WritableStream.h: Added.
+        (WebCore::WritableStream::lock):
+        (WebCore::WritableStream::locked const):
+        (WebCore::WritableStream::internalWritableStream):
+
+        * Modules/streams/WritableStream.idl:
+        * Modules/streams/WritableStream.js: Removed.
+        * Modules/streams/WritableStreamDefaultWriter.js:
+        (initializeWritableStreamDefaultWriter):
+        * Modules/streams/WritableStreamInternals.js:
+        (initializeWritableStreamSlots):
+        (writableStreamCloseForBindings):
+        (writableStreamAbortForBindings):
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * bindings/js/InternalWritableStream.cpp: Added.
+        (WebCore::invokeWritableStreamFunction):
+        (WebCore::InternalWritableStream::create):
+        (WebCore::InternalWritableStream::locked const):
+        (WebCore::InternalWritableStream::lock):
+        (WebCore::InternalWritableStream::abort):
+        (WebCore::InternalWritableStream::close):
+        (WebCore::InternalWritableStream::getWriter):
+        * bindings/js/InternalWritableStream.h: Added.
+        * bindings/js/JSDOMGlobalObject.cpp:
+        (WebCore::JSC_DEFINE_HOST_FUNCTION):
+        (WebCore::JSDOMGlobalObject::addBuiltinGlobals):
+        * bindings/js/WebCoreBuiltinNames.h:
+        * bindings/js/WritableStream.cpp: Removed.
+        * bindings/js/WritableStream.h: Removed.
+        * bindings/scripts/CodeGeneratorJS.pm:
+        (AddToIncludesForIDLType):
+
</ins><span class="cx"> 2021-09-10  Antti Koivisto  <antti@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Factor more text painting functions to TextBoxPainter
</span></span></pre></div>
<a id="trunkSourceWebCoreDerivedSourcesinputxcfilelist"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/DerivedSources-input.xcfilelist (282277 => 282278)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/DerivedSources-input.xcfilelist     2021-09-10 17:16:43 UTC (rev 282277)
+++ trunk/Source/WebCore/DerivedSources-input.xcfilelist        2021-09-10 17:22:01 UTC (rev 282278)
</span><span class="lines">@@ -450,7 +450,6 @@
</span><span class="cx"> $(PROJECT_DIR)/Modules/streams/TransformStreamDefaultController.js
</span><span class="cx"> $(PROJECT_DIR)/Modules/streams/TransformStreamInternals.js
</span><span class="cx"> $(PROJECT_DIR)/Modules/streams/WritableStream.idl
</span><del>-$(PROJECT_DIR)/Modules/streams/WritableStream.js
</del><span class="cx"> $(PROJECT_DIR)/Modules/streams/WritableStreamDefaultController.idl
</span><span class="cx"> $(PROJECT_DIR)/Modules/streams/WritableStreamDefaultController.js
</span><span class="cx"> $(PROJECT_DIR)/Modules/streams/WritableStreamDefaultWriter.idl
</span></span></pre></div>
<a id="trunkSourceWebCoreDerivedSourcesoutputxcfilelist"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/DerivedSources-output.xcfilelist (282277 => 282278)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/DerivedSources-output.xcfilelist    2021-09-10 17:16:43 UTC (rev 282277)
+++ trunk/Source/WebCore/DerivedSources-output.xcfilelist       2021-09-10 17:22:01 UTC (rev 282278)
</span><span class="lines">@@ -2643,7 +2643,6 @@
</span><span class="cx"> $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/WebKitFontFamilyNames.h
</span><span class="cx"> $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/WorkerGlobalScopeConstructors.idl
</span><span class="cx"> $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/WorkletGlobalScopeConstructors.idl
</span><del>-$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/WritableStreamBuiltins.h
</del><span class="cx"> $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/WritableStreamDefaultControllerBuiltins.h
</span><span class="cx"> $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/WritableStreamDefaultWriterBuiltins.h
</span><span class="cx"> $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/WritableStreamInternalsBuiltins.h
</span></span></pre></div>
<a id="trunkSourceWebCoreDerivedSourcesmake"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/DerivedSources.make (282277 => 282278)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/DerivedSources.make 2021-09-10 17:16:43 UTC (rev 282277)
+++ trunk/Source/WebCore/DerivedSources.make    2021-09-10 17:22:01 UTC (rev 282278)
</span><span class="lines">@@ -1952,7 +1952,6 @@
</span><span class="cx">     $(WebCore)/Modules/streams/TransformStream.js \
</span><span class="cx">     $(WebCore)/Modules/streams/TransformStreamDefaultController.js \
</span><span class="cx">     $(WebCore)/Modules/streams/TransformStreamInternals.js \
</span><del>-    $(WebCore)/Modules/streams/WritableStream.js \
</del><span class="cx">     $(WebCore)/Modules/streams/WritableStreamDefaultController.js \
</span><span class="cx">     $(WebCore)/Modules/streams/WritableStreamDefaultWriter.js \
</span><span class="cx">     $(WebCore)/Modules/streams/WritableStreamInternals.js \
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesmediastreamRTCRtpSFrameTransformcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/mediastream/RTCRtpSFrameTransform.cpp (282277 => 282278)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/mediastream/RTCRtpSFrameTransform.cpp       2021-09-10 17:16:43 UTC (rev 282277)
+++ trunk/Source/WebCore/Modules/mediastream/RTCRtpSFrameTransform.cpp  2021-09-10 17:22:01 UTC (rev 282278)
</span><span class="lines">@@ -32,6 +32,7 @@
</span><span class="cx"> #include "JSDOMConvertBufferSource.h"
</span><span class="cx"> #include "JSRTCEncodedAudioFrame.h"
</span><span class="cx"> #include "JSRTCEncodedVideoFrame.h"
</span><ins>+#include "JSWritableStreamSink.h"
</ins><span class="cx"> #include "Logging.h"
</span><span class="cx"> #include "RTCEncodedAudioFrame.h"
</span><span class="cx"> #include "RTCEncodedVideoFrame.h"
</span><span class="lines">@@ -43,7 +44,6 @@
</span><span class="cx"> #include "ReadableStreamSource.h"
</span><span class="cx"> #include "SharedBuffer.h"
</span><span class="cx"> #include "WritableStream.h"
</span><del>-#include "WritableStreamSink.h"
</del><span class="cx"> #include <wtf/IsoMallocInlines.h>
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="lines">@@ -98,7 +98,7 @@
</span><span class="cx"> 
</span><span class="cx"> bool RTCRtpSFrameTransform::isAttached() const
</span><span class="cx"> {
</span><del>-    return m_isAttached || (m_readable && m_readable->isLocked()) || (m_writable && m_writable->isLocked());
</del><ins>+    return m_isAttached || (m_readable && m_readable->isLocked()) || (m_writable && m_writable->locked());
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> static RTCRtpSFrameTransformErrorEvent::Type errorTypeFromInformation(const RTCRtpSFrameTransformer::ErrorInformation& errorInformation)
</span><span class="lines">@@ -208,14 +208,18 @@
</span><span class="cx">     source.enqueue(toJS(&globalObject, &globalObject, frame));
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void RTCRtpSFrameTransform::createStreams(JSC::JSGlobalObject& globalObject)
</del><ins>+ExceptionOr<void> RTCRtpSFrameTransform::createStreams()
</ins><span class="cx"> {
</span><ins>+    auto* globalObject = scriptExecutionContext() ? scriptExecutionContext()->globalObject() : nullptr;
+    if (!globalObject)
+        return Exception { InvalidStateError };
+
</ins><span class="cx">     m_readableStreamSource = SimpleReadableStreamSource::create();
</span><del>-    auto readable = ReadableStream::create(globalObject, m_readableStreamSource.copyRef());
</del><ins>+    auto readable = ReadableStream::create(*globalObject, m_readableStreamSource.copyRef());
</ins><span class="cx">     if (readable.hasException())
</span><del>-        return;
</del><ins>+        return readable.releaseException();
</ins><span class="cx"> 
</span><del>-    auto writable = WritableStream::create(globalObject, SimpleWritableStreamSink::create([transformer = m_transformer, readableStreamSource = m_readableStreamSource, weakThis = makeWeakPtr(this)](auto& context, auto value) -> ExceptionOr<void> {
</del><ins>+    auto writable = WritableStream::create(*JSC::jsCast<JSDOMGlobalObject*>(globalObject), SimpleWritableStreamSink::create([transformer = m_transformer, readableStreamSource = m_readableStreamSource, weakThis = makeWeakPtr(this)](auto& context, auto value) -> ExceptionOr<void> {
</ins><span class="cx">         if (!context.globalObject())
</span><span class="cx">             return Exception { InvalidStateError };
</span><span class="cx">         auto& globalObject = *JSC::jsCast<JSDOMGlobalObject*>(context.globalObject());
</span><span class="lines">@@ -238,7 +242,7 @@
</span><span class="cx">         return { };
</span><span class="cx">     }));
</span><span class="cx">     if (writable.hasException())
</span><del>-        return;
</del><ins>+        return writable.releaseException();
</ins><span class="cx"> 
</span><span class="cx">     m_readable = readable.releaseReturnValue();
</span><span class="cx">     m_writable = writable.releaseReturnValue();
</span><span class="lines">@@ -246,37 +250,27 @@
</span><span class="cx">         m_readable->lock();
</span><span class="cx">         m_writable->lock();
</span><span class="cx">     }
</span><ins>+    return { };
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> ExceptionOr<RefPtr<ReadableStream>> RTCRtpSFrameTransform::readable()
</span><span class="cx"> {
</span><del>-    auto* context = scriptExecutionContext();
-    if (!context)
-        return Exception { InvalidStateError };
-
-    auto* globalObject = context->globalObject();
-    if (!globalObject)
-        return Exception { InvalidStateError };
-
-    if (!m_readable)
-        createStreams(*globalObject);
-
</del><ins>+    if (!m_readable) {
+        auto result = createStreams();
+        if (result.hasException())
+            return result.releaseException();
+    }
</ins><span class="cx">     return m_readable.copyRef();
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> ExceptionOr<RefPtr<WritableStream>> RTCRtpSFrameTransform::writable()
</span><span class="cx"> {
</span><del>-    auto* context = scriptExecutionContext();
-    if (!context)
-        return Exception { InvalidStateError };
</del><ins>+    if (!m_writable) {
+        auto result = createStreams();
+        if (result.hasException())
+            return result.releaseException();
+    }
</ins><span class="cx"> 
</span><del>-    auto* globalObject = context->globalObject();
-    if (!globalObject)
-        return Exception { InvalidStateError };
-
-    if (!m_writable)
-        createStreams(*globalObject);
-
</del><span class="cx">     m_hasWritable = true;
</span><span class="cx">     return m_writable.copyRef();
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesmediastreamRTCRtpSFrameTransformh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/mediastream/RTCRtpSFrameTransform.h (282277 => 282278)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/mediastream/RTCRtpSFrameTransform.h 2021-09-10 17:16:43 UTC (rev 282277)
+++ trunk/Source/WebCore/Modules/mediastream/RTCRtpSFrameTransform.h    2021-09-10 17:22:01 UTC (rev 282278)
</span><span class="lines">@@ -93,7 +93,7 @@
</span><span class="cx"> 
</span><span class="cx">     enum class Side { Sender, Receiver };
</span><span class="cx">     void initializeTransformer(RTCRtpTransformBackend&, Side);
</span><del>-    void createStreams(JSC::JSGlobalObject&);
</del><ins>+    ExceptionOr<void> createStreams();
</ins><span class="cx"> 
</span><span class="cx">     bool m_isAttached { false };
</span><span class="cx">     bool m_hasWritable { false };
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesstreamsReadableStreamjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/streams/ReadableStream.js (282277 => 282278)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/streams/ReadableStream.js   2021-09-10 17:16:43 UTC (rev 282277)
+++ trunk/Source/WebCore/Modules/streams/ReadableStream.js      2021-09-10 17:22:01 UTC (rev 282278)
</span><span class="lines">@@ -123,7 +123,8 @@
</span><span class="cx">             throw @makeTypeError("readable should be ReadableStream");
</span><span class="cx"> 
</span><span class="cx">         const writable = transforms["writable"];
</span><del>-        if (!@isWritableStream(writable))
</del><ins>+        const internalWritable = @getInternalWritableStream(writable);
+        if (!@isWritableStream(internalWritable))
</ins><span class="cx">             throw @makeTypeError("writable should be WritableStream");
</span><span class="cx"> 
</span><span class="cx">         let preventClose = false;
</span><span class="lines">@@ -149,10 +150,10 @@
</span><span class="cx">         if (@isReadableStreamLocked(this))
</span><span class="cx">             throw @makeTypeError("ReadableStream is locked");
</span><span class="cx"> 
</span><del>-        if (@isWritableStreamLocked(writable))
</del><ins>+        if (@isWritableStreamLocked(internalWritable))
</ins><span class="cx">             throw @makeTypeError("WritableStream is locked");
</span><span class="cx"> 
</span><del>-        @readableStreamPipeToWritableStream(this, writable, preventClose, preventAbort, preventCancel, signal);
</del><ins>+        @readableStreamPipeToWritableStream(this, internalWritable, preventClose, preventAbort, preventCancel, signal);
</ins><span class="cx"> 
</span><span class="cx">         return readable;
</span><span class="cx">     }
</span><span class="lines">@@ -196,7 +197,8 @@
</span><span class="cx">                 return @Promise.@reject(@makeTypeError("options.signal must be AbortSignal"));
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        if (!@isWritableStream(destination))
</del><ins>+        const internalDestination = @getInternalWritableStream(destination);
+        if (!@isWritableStream(internalDestination))
</ins><span class="cx">             return @Promise.@reject(@makeTypeError("ReadableStream pipeTo requires a WritableStream"));
</span><span class="cx"> 
</span><span class="cx">         if (!@isReadableStream(this))
</span><span class="lines">@@ -205,10 +207,10 @@
</span><span class="cx">         if (@isReadableStreamLocked(this))
</span><span class="cx">             return @Promise.@reject(@makeTypeError("ReadableStream is locked"));
</span><span class="cx"> 
</span><del>-        if (@isWritableStreamLocked(destination))
</del><ins>+        if (@isWritableStreamLocked(internalDestination))
</ins><span class="cx">             return @Promise.@reject(@makeTypeError("WritableStream is locked"));
</span><span class="cx"> 
</span><del>-        return @readableStreamPipeToWritableStream(this, destination, preventClose, preventAbort, preventCancel, signal);
</del><ins>+        return @readableStreamPipeToWritableStream(this, internalDestination, preventClose, preventAbort, preventCancel, signal);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     // FIXME: rewrite pipeTo so as to require to have 'this' as a ReadableStream and destination be a WritableStream.
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesstreamsTransformStreamInternalsjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/streams/TransformStreamInternals.js (282277 => 282278)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/streams/TransformStreamInternals.js 2021-09-10 17:16:43 UTC (rev 282277)
+++ trunk/Source/WebCore/Modules/streams/TransformStreamInternals.js    2021-09-10 17:22:01 UTC (rev 282278)
</span><span class="lines">@@ -95,7 +95,11 @@
</span><span class="cx">     @putByIdDirectPrivate(options, "highWaterMark", readableHighWaterMark);
</span><span class="cx">     const readable = new @ReadableStream(underlyingSource, options);
</span><span class="cx"> 
</span><ins>+    // The writable to expose to JS through writable getter.
</ins><span class="cx">     @putByIdDirectPrivate(stream, "writable", writable);
</span><ins>+    // The writable to use for the actual transform algorithms.
+    @putByIdDirectPrivate(stream, "internalWritable", @getInternalWritableStream(writable));
+
</ins><span class="cx">     @putByIdDirectPrivate(stream, "readable", readable);
</span><span class="cx">     @putByIdDirectPrivate(stream, "backpressure", @undefined);
</span><span class="cx">     @putByIdDirectPrivate(stream, "backpressureChangePromise", @undefined);
</span><span class="lines">@@ -121,7 +125,7 @@
</span><span class="cx"> 
</span><span class="cx">     @transformStreamDefaultControllerClearAlgorithms(@getByIdDirectPrivate(stream, "controller"));
</span><span class="cx"> 
</span><del>-    const writable = @getByIdDirectPrivate(stream, "writable");
</del><ins>+    const writable = @getByIdDirectPrivate(stream, "internalWritable");
</ins><span class="cx">     @writableStreamDefaultControllerErrorIfNeeded(@getByIdDirectPrivate(writable, "controller"), e);
</span><span class="cx"> 
</span><span class="cx">     if (@getByIdDirectPrivate(stream, "backpressure"))
</span><span class="lines">@@ -262,7 +266,7 @@
</span><span class="cx"> {
</span><span class="cx">     "use strict";
</span><span class="cx"> 
</span><del>-    const writable = @getByIdDirectPrivate(stream, "writable");
</del><ins>+    const writable = @getByIdDirectPrivate(stream, "internalWritable");
</ins><span class="cx"> 
</span><span class="cx">     @assert(@getByIdDirectPrivate(writable, "state") === "writable");
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesstreamsWritableStreamcpp"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/Modules/streams/WritableStream.cpp (0 => 282278)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/streams/WritableStream.cpp                          (rev 0)
+++ trunk/Source/WebCore/Modules/streams/WritableStream.cpp     2021-09-10 17:22:01 UTC (rev 282278)
</span><span class="lines">@@ -0,0 +1,81 @@
</span><ins>+/*
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WritableStream.h"
+
+#include "JSWritableStream.h"
+#include "JSWritableStreamSink.h"
+
+namespace WebCore {
+
+ExceptionOr<Ref<WritableStream>> WritableStream::create(JSC::JSGlobalObject& globalObject, std::optional<JSC::Strong<JSC::JSObject>>&& underlyingSink, std::optional<JSC::Strong<JSC::JSObject>>&& strategy)
+{
+    JSC::JSValue underlyingSinkValue = JSC::jsUndefined();
+    if (underlyingSink)
+        underlyingSinkValue = underlyingSink->get();
+
+    JSC::JSValue strategyValue = JSC::jsUndefined();
+    if (strategy)
+        strategyValue = strategy->get();
+
+    return create(globalObject, underlyingSinkValue, strategyValue);
+}
+
+ExceptionOr<Ref<WritableStream>> WritableStream::create(JSC::JSGlobalObject& globalObject, JSC::JSValue underlyingSink, JSC::JSValue strategy)
+{
+    auto result = InternalWritableStream::create(*JSC::jsCast<JSDOMGlobalObject*>(&globalObject), underlyingSink, strategy);
+    if (result.hasException())
+        return result.releaseException();
+
+    return adoptRef(*new WritableStream(result.releaseReturnValue()));
+}
+
+ExceptionOr<Ref<WritableStream>> WritableStream::create(JSDOMGlobalObject& globalObject, Ref<WritableStreamSink>&& sink)
+{
+    return create(globalObject, toJSNewlyCreated(&globalObject, &globalObject, WTFMove(sink)), JSC::jsUndefined());
+}
+
+WritableStream::WritableStream(Ref<InternalWritableStream>&& internalWritableStream)
+    : m_internalWritableStream(WTFMove(internalWritableStream))
+{
+}
+
+JSC::JSValue JSWritableStream::abort(JSC::JSGlobalObject& globalObject, JSC::CallFrame& callFrame)
+{
+    return wrapped().internalWritableStream().abort(globalObject, callFrame.argument(0));
+}
+
+JSC::JSValue JSWritableStream::close(JSC::JSGlobalObject& globalObject, JSC::CallFrame&)
+{
+    return wrapped().internalWritableStream().close(globalObject);
+}
+
+JSC::JSValue JSWritableStream::getWriter(JSC::JSGlobalObject& globalObject, JSC::CallFrame&)
+{
+    return wrapped().internalWritableStream().getWriter(globalObject);
+}
+
+} // namespace WebCore
</ins></span></pre></div>
<a id="trunkSourceWebCoreModulesstreamsWritableStreamh"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/Modules/streams/WritableStream.h (0 => 282278)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/streams/WritableStream.h                            (rev 0)
+++ trunk/Source/WebCore/Modules/streams/WritableStream.h       2021-09-10 17:22:01 UTC (rev 282278)
</span><span class="lines">@@ -0,0 +1,57 @@
</span><ins>+/*
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "InternalWritableStream.h"
+#include <JavaScriptCore/Strong.h>
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+class InternalWritableStream;
+class JSDOMGlobalObject;
+class WritableStreamSink;
+
+class WritableStream : public RefCounted<WritableStream> {
+public:
+    static ExceptionOr<Ref<WritableStream>> create(JSC::JSGlobalObject&, std::optional<JSC::Strong<JSC::JSObject>>&&, std::optional<JSC::Strong<JSC::JSObject>>&&);
+    static ExceptionOr<Ref<WritableStream>> create(JSDOMGlobalObject&, Ref<WritableStreamSink>&&);
+
+    ~WritableStream() = default;
+
+    void lock() { m_internalWritableStream->lock(); }
+    bool locked() const { return m_internalWritableStream->locked(); }
+
+    InternalWritableStream& internalWritableStream() { return m_internalWritableStream.get(); }
+
+private:
+    static ExceptionOr<Ref<WritableStream>> create(JSC::JSGlobalObject&, JSC::JSValue, JSC::JSValue);
+    explicit WritableStream(Ref<InternalWritableStream>&&);
+
+    Ref<InternalWritableStream> m_internalWritableStream;
+};
+
+} // namespace WebCore
</ins></span></pre></div>
<a id="trunkSourceWebCoreModulesstreamsWritableStreamidl"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/streams/WritableStream.idl (282277 => 282278)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/streams/WritableStream.idl  2021-09-10 17:16:43 UTC (rev 282277)
+++ trunk/Source/WebCore/Modules/streams/WritableStream.idl     2021-09-10 17:22:01 UTC (rev 282278)
</span><span class="lines">@@ -1,7 +1,7 @@
</span><span class="cx"> /*
</span><span class="cx">  * Copyright (C) 2015 Canon Inc.
</span><span class="cx">  * Copyright (C) 2015 Igalia S.L.
</span><del>- * Copyright (C) 2020 Apple Inc.
</del><ins>+ * Copyright (C) 2020-2021 Apple Inc.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted, provided that the following conditions
</span><span class="lines">@@ -31,15 +31,16 @@
</span><span class="cx"> [
</span><span class="cx">     EnabledAtRuntime=WritableStreamAPI,
</span><span class="cx">     Exposed=(Window,Worker),
</span><del>-    JSBuiltin,
</del><span class="cx">     PrivateIdentifier,
</span><del>-    PublicIdentifier
</del><ins>+    PublicIdentifier,
+    SkipVTableValidation
</ins><span class="cx"> ] interface WritableStream {
</span><del>-    constructor(optional object underlyingSink, optional QueuingStrategy strategy);
</del><ins>+    // FIXME: Tighten parameter matching
+    [CallWith=GlobalObject] constructor(optional object underlyingSink, optional object strategy);
</ins><span class="cx"> 
</span><span class="cx">     readonly attribute boolean locked;
</span><span class="cx"> 
</span><del>-    Promise<any> abort(optional any reason);
-    Promise<any> close();
-    WritableStreamDefaultWriter getWriter();
</del><ins>+    [Custom, ReturnsOwnPromise] Promise<any> abort(optional any reason);
+    [Custom, ReturnsOwnPromise] Promise<any> close();
+    [Custom] WritableStreamDefaultWriter getWriter();
</ins><span class="cx"> };
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesstreamsWritableStreamjs"></a>
<div class="delfile"><h4>Deleted: trunk/Source/WebCore/Modules/streams/WritableStream.js (282277 => 282278)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/streams/WritableStream.js   2021-09-10 17:16:43 UTC (rev 282277)
+++ trunk/Source/WebCore/Modules/streams/WritableStream.js      2021-09-10 17:22:01 UTC (rev 282278)
</span><span class="lines">@@ -1,132 +0,0 @@
</span><del>-/*
- * Copyright (C) 2015 Canon Inc.
- * Copyright (C) 2015 Igalia
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-function initializeWritableStream(underlyingSink, strategy)
-{
-    "use strict";
-
-    if (underlyingSink === @undefined)
-        underlyingSink = { };
-
-    if (strategy === @undefined)
-        strategy = { };
-
-    if (!@isObject(underlyingSink))
-        @throwTypeError("WritableStream constructor takes an object as first argument");
-
-    // CreateWriteStream code path.
-    if (@getByIdDirectPrivate(underlyingSink, "WritableStream")) {
-        @privateInitializeWritableStream(this, underlyingSink);
-
-        const controller = new @WritableStreamDefaultController();
-
-        @setUpWritableStreamDefaultController(this, controller, underlyingSink.startAlgorithm, underlyingSink.writeAlgorithm, underlyingSink.closeAlgorithm, underlyingSink.abortAlgorithm, strategy.highWaterMark, strategy.sizeAlgorithm);
-        return this;
-    }
-
-    if ("type" in underlyingSink)
-        @throwRangeError("Invalid type is specified");
-
-    const sizeAlgorithm = @extractSizeAlgorithm(strategy);
-    const highWaterMark = @extractHighWaterMark(strategy, 1);
-
-    const underlyingSinkDict = { };
-    if ("start" in underlyingSink) {
-        underlyingSinkDict["start"] = underlyingSink["start"];
-        if (typeof underlyingSinkDict["start"] !== "function")
-            @throwTypeError("underlyingSink.start should be a function");
-    }
-    if ("write" in underlyingSink) {
-        underlyingSinkDict["write"] = underlyingSink["write"];
-        if (typeof underlyingSinkDict["write"] !== "function")
-            @throwTypeError("underlyingSink.write should be a function");
-    }
-    if ("close" in underlyingSink) {
-        underlyingSinkDict["close"] = underlyingSink["close"];
-        if (typeof underlyingSinkDict["close"] !== "function")
-            @throwTypeError("underlyingSink.close should be a function");
-    }
-    if ("abort" in underlyingSink) {
-        underlyingSinkDict["abort"] = underlyingSink["abort"];
-        if (typeof underlyingSinkDict["abort"] !== "function")
-            @throwTypeError("underlyingSink.abort should be a function");
-    }
-
-    @privateInitializeWritableStream(this, underlyingSink);
-    @setUpWritableStreamDefaultControllerFromUnderlyingSink(this, underlyingSink, underlyingSinkDict, highWaterMark, sizeAlgorithm);
-
-    return this;
-}
-
-@getter
-function locked()
-{
-    "use strict";
-
-    if (!@isWritableStream(this))
-        throw @makeThisTypeError("WritableStream", "locked");
-
-    return @isWritableStreamLocked(this);
-}
-
-function abort(reason)
-{
-    "use strict";
-
-    if (!@isWritableStream(this))
-        return @Promise.@reject(@makeThisTypeError("WritableStream", "abort"));
-
-    if (@isWritableStreamLocked(this))
-        return @Promise.@reject(@makeTypeError("WritableStream.abort method can only be used on non locked WritableStream"));
-
-    return @writableStreamAbort(this, reason);
-}
-
-function close()
-{
-    "use strict";
-
-    if (!@isWritableStream(this))
-        return @Promise.@reject(@makeThisTypeError("WritableStream", "close"));
-
-    if (@isWritableStreamLocked(this))
-        return @Promise.@reject(@makeTypeError("WritableStream.close method can only be used on non locked WritableStream"));
-
-    if (@writableStreamCloseQueuedOrInFlight(this))
-        return @Promise.@reject(@makeTypeError("WritableStream.close method can only be used on a being close WritableStream"));
-
-    return @writableStreamClose(this);
-}
-
-function getWriter()
-{
-    "use strict";
-
-    if (!@isWritableStream(this))
-        throw @makeThisTypeError("WritableStream", "getWriter");
-
-    return @acquireWritableStreamDefaultWriter(this);
-}
</del></span></pre></div>
<a id="trunkSourceWebCoreModulesstreamsWritableStreamDefaultWriterjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/streams/WritableStreamDefaultWriter.js (282277 => 282278)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/streams/WritableStreamDefaultWriter.js      2021-09-10 17:16:43 UTC (rev 282277)
+++ trunk/Source/WebCore/Modules/streams/WritableStreamDefaultWriter.js 2021-09-10 17:22:01 UTC (rev 282278)
</span><span class="lines">@@ -27,6 +27,12 @@
</span><span class="cx"> {
</span><span class="cx">     "use strict";
</span><span class="cx"> 
</span><ins>+    // stream can be a WritableStream if WritableStreamDefaultWriter constructor is called directly from JS
+    // or an InternalWritableStream in other code paths.
+    const internalStream = @getInternalWritableStream(stream);
+    if (internalStream)
+        stream = internalStream;
+
</ins><span class="cx">     if (!@isWritableStream(stream))
</span><span class="cx">         @throwTypeError("WritableStreamDefaultWriter constructor takes a WritableStream");
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesstreamsWritableStreamInternalsjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/streams/WritableStreamInternals.js (282277 => 282278)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/streams/WritableStreamInternals.js  2021-09-10 17:16:43 UTC (rev 282277)
+++ trunk/Source/WebCore/Modules/streams/WritableStreamInternals.js     2021-09-10 17:22:01 UTC (rev 282278)
</span><span class="lines">@@ -57,8 +57,67 @@
</span><span class="cx">     return new @WritableStream(underlyingSink, { sizeAlgorithm: writableSizeAlgorithm, highWaterMark: writableHighWaterMark });
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-function privateInitializeWritableStream(stream, underlyingSink)
</del><ins>+function createInternalWritableStream(underlyingSink, strategy)
</ins><span class="cx"> {
</span><ins>+    "use strict";
+
+    const stream = { };
+
+    if (underlyingSink === @undefined)
+        underlyingSink = { };
+
+    if (strategy === @undefined)
+        strategy = { };
+
+    if (!@isObject(underlyingSink))
+        @throwTypeError("WritableStream constructor takes an object as first argument");
+
+    // createWriteStream code path.
+    if (@getByIdDirectPrivate(underlyingSink, "WritableStream")) {
+        @initializeWritableStreamSlots(stream, underlyingSink);
+
+        const controller = new @WritableStreamDefaultController();
+
+        @setUpWritableStreamDefaultController(stream, controller, underlyingSink.startAlgorithm, underlyingSink.writeAlgorithm, underlyingSink.closeAlgorithm, underlyingSink.abortAlgorithm, strategy.highWaterMark, strategy.sizeAlgorithm);
+        return stream;
+    }
+
+    if ("type" in underlyingSink)
+        @throwRangeError("Invalid type is specified");
+
+    const sizeAlgorithm = @extractSizeAlgorithm(strategy);
+    const highWaterMark = @extractHighWaterMark(strategy, 1);
+
+    const underlyingSinkDict = { };
+    if ("start" in underlyingSink) {
+        underlyingSinkDict["start"] = underlyingSink["start"];
+        if (typeof underlyingSinkDict["start"] !== "function")
+            @throwTypeError("underlyingSink.start should be a function");
+    }
+    if ("write" in underlyingSink) {
+        underlyingSinkDict["write"] = underlyingSink["write"];
+        if (typeof underlyingSinkDict["write"] !== "function")
+            @throwTypeError("underlyingSink.write should be a function");
+    }
+    if ("close" in underlyingSink) {
+        underlyingSinkDict["close"] = underlyingSink["close"];
+        if (typeof underlyingSinkDict["close"] !== "function")
+            @throwTypeError("underlyingSink.close should be a function");
+    }
+    if ("abort" in underlyingSink) {
+        underlyingSinkDict["abort"] = underlyingSink["abort"];
+        if (typeof underlyingSinkDict["abort"] !== "function")
+            @throwTypeError("underlyingSink.abort should be a function");
+    }
+
+    @initializeWritableStreamSlots(stream, underlyingSink);
+    @setUpWritableStreamDefaultControllerFromUnderlyingSink(stream, underlyingSink, underlyingSinkDict, highWaterMark, sizeAlgorithm);
+
+    return stream;
+}
+
+function initializeWritableStreamSlots(stream, underlyingSink)
+{
</ins><span class="cx">     @putByIdDirectPrivate(stream, "state", "writable");
</span><span class="cx">     @putByIdDirectPrivate(stream, "storedError", @undefined);
</span><span class="cx">     @putByIdDirectPrivate(stream, "writer", @undefined);
</span><span class="lines">@@ -72,6 +131,25 @@
</span><span class="cx">     @putByIdDirectPrivate(stream, "underlyingSink", underlyingSink);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+function writableStreamCloseForBindings(stream)
+{
+    if (@isWritableStreamLocked(stream))
+        return @Promise.@reject(@makeTypeError("WritableStream.close method can only be used on non locked WritableStream"));
+
+    if (@writableStreamCloseQueuedOrInFlight(stream))
+        return @Promise.@reject(@makeTypeError("WritableStream.close method can only be used on a being close WritableStream"));
+
+    return @writableStreamClose(stream);
+}
+
+function writableStreamAbortForBindings(stream, reason)
+{
+    if (@isWritableStreamLocked(stream))
+        return @Promise.@reject(@makeTypeError("WritableStream.abort method can only be used on non locked WritableStream"));
+
+    return @writableStreamAbort(stream, reason);
+}
+
</ins><span class="cx"> function isWritableStreamLocked(stream)
</span><span class="cx"> {
</span><span class="cx">     return @getByIdDirectPrivate(stream, "writer") !== @undefined;
</span></span></pre></div>
<a id="trunkSourceWebCoreSourcestxt"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Sources.txt (282277 => 282278)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Sources.txt 2021-09-10 17:16:43 UTC (rev 282277)
+++ trunk/Source/WebCore/Sources.txt    2021-09-10 17:22:01 UTC (rev 282278)
</span><span class="lines">@@ -235,6 +235,7 @@
</span><span class="cx"> Modules/storage/StorageManager.cpp
</span><span class="cx"> Modules/streams/ReadableStreamSink.cpp
</span><span class="cx"> Modules/streams/ReadableStreamSource.cpp
</span><ins>+Modules/streams/WritableStream.cpp
</ins><span class="cx"> Modules/webaudio/AnalyserNode.cpp
</span><span class="cx"> Modules/webaudio/AsyncAudioDecoder.cpp
</span><span class="cx"> Modules/webaudio/AudioBasicInspectorNode.cpp
</span><span class="lines">@@ -427,6 +428,7 @@
</span><span class="cx"> bindings/js/DOMWrapperWorld.cpp
</span><span class="cx"> bindings/js/GCController.cpp
</span><span class="cx"> bindings/js/IDBBindingUtilities.cpp
</span><ins>+bindings/js/InternalWritableStream.cpp
</ins><span class="cx"> bindings/js/JSAbortSignalCustom.cpp
</span><span class="cx"> bindings/js/JSAbstractRangeCustom.cpp
</span><span class="cx"> bindings/js/JSAnimationEffectCustom.cpp
</span><span class="lines">@@ -570,7 +572,6 @@
</span><span class="cx"> bindings/js/WebCoreTypedArrayController.cpp
</span><span class="cx"> bindings/js/WorkerModuleScriptLoader.cpp
</span><span class="cx"> bindings/js/WindowProxy.cpp
</span><del>-bindings/js/WritableStream.cpp
</del><span class="cx"> bridge/IdentifierRep.cpp
</span><span class="cx"> bridge/NP_jsobject.cpp
</span><span class="cx"> bridge/c/CRuntimeObject.cpp
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCorexcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (282277 => 282278)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj   2021-09-10 17:16:43 UTC (rev 282277)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj      2021-09-10 17:22:01 UTC (rev 282278)
</span><span class="lines">@@ -1114,7 +1114,6 @@
</span><span class="cx">          416E6FE81BBD12DF000A6043 /* ReadableByteStreamInternalsBuiltins.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B03D8061BB3110D00B73F64 /* ReadableByteStreamInternalsBuiltins.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">          416E6FE81BBD12DF000A6053 /* WritableStreamInternalsBuiltins.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B03D8061BB3110D00B764E9 /* WritableStreamInternalsBuiltins.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">          416E6FE91BBD12E5000A6043 /* ReadableStreamBuiltins.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B03D8061BB3110D00B764D8 /* ReadableStreamBuiltins.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><del>-               416E6FE91BBD12E5000A6053 /* WritableStreamBuiltins.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B03D8061BB3110D00B764E8 /* WritableStreamBuiltins.h */; settings = {ATTRIBUTES = (Private, ); }; };
</del><span class="cx">           416ECAE525B58CC400B34DA5 /* MediaSessionGroupIdentifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 416ECAE325B58CC400B34DA5 /* MediaSessionGroupIdentifier.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">          416EDBF62600D67900092675 /* RTCDataChannelRemoteHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = 416EDBF42600D67800092675 /* RTCDataChannelRemoteHandler.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">          416EDC002600E78800092675 /* RTCDataChannelIdentifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 416EDBFF2600E78700092675 /* RTCDataChannelIdentifier.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="lines">@@ -7832,8 +7831,8 @@
</span><span class="cx">          414189FF256418E700363417 /* RTCEncodedVideoFrame.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RTCEncodedVideoFrame.cpp; sourceTree = "<group>"; };
</span><span class="cx">          41418A002564359700363417 /* WritableStreamSink.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = WritableStreamSink.idl; sourceTree = "<group>"; };
</span><span class="cx">          41418A022564359800363417 /* WritableStreamSink.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WritableStreamSink.h; sourceTree = "<group>"; };
</span><del>-               41418A0325643E1200363417 /* WritableStream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WritableStream.cpp; sourceTree = "<group>"; };
-               41418A0425643E1300363417 /* WritableStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WritableStream.h; sourceTree = "<group>"; };
</del><ins>+                41418A0325643E1200363417 /* InternalWritableStream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InternalWritableStream.cpp; sourceTree = "<group>"; };
+               41418A0425643E1300363417 /* InternalWritableStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InternalWritableStream.h; sourceTree = "<group>"; };
</ins><span class="cx">           41418A05256660AF00363417 /* RTCEncodedFrame.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RTCEncodedFrame.cpp; sourceTree = "<group>"; };
</span><span class="cx">          41418A06256660B000363417 /* RTCEncodedFrame.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RTCEncodedFrame.h; sourceTree = "<group>"; };
</span><span class="cx">          414460A02412994100814BE7 /* MediaSessionIdentifier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaSessionIdentifier.h; sourceTree = "<group>"; };
</span><span class="lines">@@ -8130,6 +8129,8 @@
</span><span class="cx">          41E59401214865AB00D3CB61 /* RTCRtpFecParameters.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = RTCRtpFecParameters.idl; sourceTree = "<group>"; };
</span><span class="cx">          41E67A7F25D16846007B0A4C /* STUNMessageParsing.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = STUNMessageParsing.cpp; sourceTree = "<group>"; };
</span><span class="cx">          41E67A8125D16847007B0A4C /* STUNMessageParsing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STUNMessageParsing.h; sourceTree = "<group>"; };
</span><ins>+               41E6D72126EAA04500B765D6 /* WritableStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WritableStream.h; sourceTree = "<group>"; };
+               41E6D72226EAA04600B765D6 /* WritableStream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WritableStream.cpp; sourceTree = "<group>"; };
</ins><span class="cx">           41E9DCE4231973FE00F35949 /* BlobLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BlobLoader.h; sourceTree = "<group>"; };
</span><span class="cx">          41E9DCE62319742300F35949 /* EndingType.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = EndingType.idl; sourceTree = "<group>"; };
</span><span class="cx">          41E9DCE82319CA7500F35949 /* NetworkSendQueue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetworkSendQueue.h; sourceTree = "<group>"; };
</span><span class="lines">@@ -12251,7 +12252,6 @@
</span><span class="cx">          9908B0ED1BCACF9100ED0F65 /* ByteLengthQueuingStrategy.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = ByteLengthQueuingStrategy.js; sourceTree = "<group>"; };
</span><span class="cx">          9908B0EE1BCACF9100ED0F65 /* CountQueuingStrategy.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = CountQueuingStrategy.js; sourceTree = "<group>"; };
</span><span class="cx">          9908B0EF1BCACF9100ED0F65 /* ReadableStream.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = ReadableStream.js; sourceTree = "<group>"; };
</span><del>-               9908B0EF1BCACF9100ED0F75 /* WritableStream.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = WritableStream.js; sourceTree = "<group>"; };
</del><span class="cx">           9908B0F01BCACF9100ED0F65 /* ReadableStreamDefaultController.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = ReadableStreamDefaultController.js; sourceTree = "<group>"; };
</span><span class="cx">          9908B0F01BCACF9100ED3F64 /* ReadableByteStreamController.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = ReadableByteStreamController.js; sourceTree = "<group>"; };
</span><span class="cx">          9908B0F01BCACF9100ED5672 /* ReadableStreamBYOBRequest.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = ReadableStreamBYOBRequest.js; sourceTree = "<group>"; };
</span><span class="lines">@@ -12266,7 +12266,6 @@
</span><span class="cx">          9908B0F61BCAD07D00ED0F65 /* CountQueuingStrategyBuiltins.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CountQueuingStrategyBuiltins.cpp; path = DerivedSources/WebCore/CountQueuingStrategyBuiltins.cpp; sourceTree = BUILT_PRODUCTS_DIR; };
</span><span class="cx">          9908B0F71BCAD07D00ED0F65 /* CountQueuingStrategyBuiltins.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CountQueuingStrategyBuiltins.h; path = DerivedSources/WebCore/CountQueuingStrategyBuiltins.h; sourceTree = BUILT_PRODUCTS_DIR; };
</span><span class="cx">          9908B0F91BCAD07D00ED0F65 /* ReadableStreamBuiltins.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ReadableStreamBuiltins.cpp; path = DerivedSources/WebCore/ReadableStreamBuiltins.cpp; sourceTree = BUILT_PRODUCTS_DIR; };
</span><del>-               9908B0F91BCAD07D00ED0F75 /* WritableStreamBuiltins.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = WritableStreamBuiltins.cpp; path = DerivedSources/WebCore/WritableStreamBuiltins.cpp; sourceTree = BUILT_PRODUCTS_DIR; };
</del><span class="cx">           9908B0FA1BCAD07D00ED0F65 /* ReadableStreamDefaultControllerBuiltins.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ReadableStreamDefaultControllerBuiltins.cpp; path = DerivedSources/WebCore/ReadableStreamDefaultControllerBuiltins.cpp; sourceTree = BUILT_PRODUCTS_DIR; };
</span><span class="cx">          9908B0FB1BCAD07D00ED0F65 /* ReadableStreamDefaultControllerBuiltins.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ReadableStreamDefaultControllerBuiltins.h; path = DerivedSources/WebCore/ReadableStreamDefaultControllerBuiltins.h; sourceTree = BUILT_PRODUCTS_DIR; };
</span><span class="cx">          9908B0FD1BCAD07D00ED0F55 /* StreamInternalsBuiltins.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = StreamInternalsBuiltins.cpp; path = DerivedSources/WebCore/StreamInternalsBuiltins.cpp; sourceTree = BUILT_PRODUCTS_DIR; };
</span><span class="lines">@@ -12306,7 +12305,6 @@
</span><span class="cx">          9B03D8061BB3110D00B764D8 /* ReadableStreamBuiltins.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ReadableStreamBuiltins.h; path = DerivedSources/WebCore/ReadableStreamBuiltins.h; sourceTree = BUILT_PRODUCTS_DIR; };
</span><span class="cx">          9B03D8061BB3110D00B764D9 /* ReadableStreamInternalsBuiltins.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ReadableStreamInternalsBuiltins.h; path = DerivedSources/WebCore/ReadableStreamInternalsBuiltins.h; sourceTree = BUILT_PRODUCTS_DIR; };
</span><span class="cx">          9B03D8061BB3110D00B764DA /* JSDOMBindingInternalsBuiltins.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = JSDOMBindingInternalsBuiltins.h; path = DerivedSources/WebCore/JSDOMBindingInternalsBuiltins.h; sourceTree = BUILT_PRODUCTS_DIR; };
</span><del>-               9B03D8061BB3110D00B764E8 /* WritableStreamBuiltins.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WritableStreamBuiltins.h; path = DerivedSources/WebCore/WritableStreamBuiltins.h; sourceTree = BUILT_PRODUCTS_DIR; };
</del><span class="cx">           9B03D8061BB3110D00B764E9 /* WritableStreamInternalsBuiltins.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WritableStreamInternalsBuiltins.h; path = DerivedSources/WebCore/WritableStreamInternalsBuiltins.h; sourceTree = BUILT_PRODUCTS_DIR; };
</span><span class="cx">          9B03D8061BB3110D00B764EA /* TransformStreamInternalsBuiltins.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TransformStreamInternalsBuiltins.h; path = DerivedSources/WebCore/TransformStreamInternalsBuiltins.h; sourceTree = BUILT_PRODUCTS_DIR; };
</span><span class="cx">          9B098BD51F3D6033002DD562 /* DataTransferItem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DataTransferItem.cpp; sourceTree = "<group>"; };
</span><span class="lines">@@ -19653,8 +19651,9 @@
</span><span class="cx">                          41FCA5FA24EAAF16005E1BA6 /* TransformStreamDefaultController.idl */,
</span><span class="cx">                          41FCA5FB24EAAF16005E1BA6 /* TransformStreamDefaultController.js */,
</span><span class="cx">                          41FCA5FC24EAB780005E1BA6 /* TransformStreamInternals.js */,
</span><ins>+                               41E6D72226EAA04600B765D6 /* WritableStream.cpp */,
+                               41E6D72126EAA04500B765D6 /* WritableStream.h */,
</ins><span class="cx">                           41A023ED1A39DB7900F722DF /* WritableStream.idl */,
</span><del>-                               9908B0EF1BCACF9100ED0F75 /* WritableStream.js */,
</del><span class="cx">                           4176673424DC08EB008BFE28 /* WritableStreamDefaultController.idl */,
</span><span class="cx">                          4176673324DC08EB008BFE28 /* WritableStreamDefaultController.js */,
</span><span class="cx">                          4176673024DC08EA008BFE28 /* WritableStreamDefaultWriter.idl */,
</span><span class="lines">@@ -21760,8 +21759,6 @@
</span><span class="cx">                          C21BF74221CD963B00227979 /* WHLSLStandardLibrary.h */,
</span><span class="cx">                          1C50C49522C84F2400A6E4BE /* WHLSLStandardLibraryFunctionMap.cpp */,
</span><span class="cx">                          51748FA21CC6EEEB00728D84 /* WorkerGlobalScopeConstructors.idl */,
</span><del>-                               9908B0F91BCAD07D00ED0F75 /* WritableStreamBuiltins.cpp */,
-                               9B03D8061BB3110D00B764E8 /* WritableStreamBuiltins.h */,
</del><span class="cx">                           9908B0FD1BCAD07D00ED0F75 /* WritableStreamInternalsBuiltins.cpp */,
</span><span class="cx">                          9B03D8061BB3110D00B764E9 /* WritableStreamInternalsBuiltins.h */,
</span><span class="cx">                          656581EA09D1508D000E61D7 /* XLinkNames.cpp */,
</span><span class="lines">@@ -27139,6 +27136,8 @@
</span><span class="cx">                          1432E8460C51493800B1500F /* GCController.h */,
</span><span class="cx">                          C585A66011D4FAC5004C3E4B /* IDBBindingUtilities.cpp */,
</span><span class="cx">                          C585A66111D4FAC5004C3E4B /* IDBBindingUtilities.h */,
</span><ins>+                               41418A0325643E1200363417 /* InternalWritableStream.cpp */,
+                               41418A0425643E1300363417 /* InternalWritableStream.h */,
</ins><span class="cx">                           9BD4E9141C462872005065BC /* JSCustomElementInterface.cpp */,
</span><span class="cx">                          9BD4E9151C462872005065BC /* JSCustomElementInterface.h */,
</span><span class="cx">                          7C57BFE61EDE2F5B00534A48 /* JSDOMAbstractOperations.h */,
</span><span class="lines">@@ -27233,8 +27232,6 @@
</span><span class="cx">                          E3432DE325D377E30058E612 /* WorkerModuleScriptLoader.cpp */,
</span><span class="cx">                          E3432DE025D377E20058E612 /* WorkerModuleScriptLoader.h */,
</span><span class="cx">                          E347E5F825D4F00000F17A5C /* WorkerScriptFetcher.h */,
</span><del>-                               41418A0325643E1200363417 /* WritableStream.cpp */,
-                               41418A0425643E1300363417 /* WritableStream.h */,
</del><span class="cx">                   );
</span><span class="cx">                  path = js;
</span><span class="cx">                  sourceTree = "<group>";
</span><span class="lines">@@ -35624,7 +35621,7 @@
</span><span class="cx">                          834A6A3A2526844A00747F5D /* WorkletParameters.h in Headers */,
</span><span class="cx">                          833BD8172524D4F2006E72B3 /* WorkletPendingTasks.h in Headers */,
</span><span class="cx">                          93309E24099E64920056E581 /* WrapContentsInDummySpanCommand.h in Headers */,
</span><del>-                               416E6FE91BBD12E5000A6053 /* WritableStreamBuiltins.h in Headers */,
</del><ins>+                                41E6D72326EAA04600B765D6 /* WritableStream.h in Headers */,
</ins><span class="cx">                           416E6FE81BBD12DF000A6053 /* WritableStreamInternalsBuiltins.h in Headers */,
</span><span class="cx">                          9BAF3B2412C1A39800014BF1 /* WritingDirection.h in Headers */,
</span><span class="cx">                          14476AA815DC4BB100305DB2 /* WritingMode.h in Headers */,
</span><span class="lines">@@ -36875,6 +36872,7 @@
</span><span class="cx">                          E1EE8B912413195000E794D6 /* WebXRViewport.cpp in Sources */,
</span><span class="cx">                          E1EE8B832413191F00E794D6 /* WebXRWebGLLayer.cpp in Sources */,
</span><span class="cx">                          A14832C2187F65C700DA63A6 /* WKUtilities.c in Sources */,
</span><ins>+                               41E6D72426EAA04600B765D6 /* WritableStream.cpp in Sources */,
</ins><span class="cx">                           A833C7CC0A2CF07400D57664 /* XLinkNames.cpp in Sources */,
</span><span class="cx">                          A833C80C0A2CF25600D57664 /* XMLNames.cpp in Sources */,
</span><span class="cx">                          E15A36D91104572700B7B639 /* XMLNSNames.cpp in Sources */,
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsjsInternalWritableStreamcpp"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/bindings/js/InternalWritableStream.cpp (0 => 282278)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/js/InternalWritableStream.cpp                              (rev 0)
+++ trunk/Source/WebCore/bindings/js/InternalWritableStream.cpp 2021-09-10 17:22:01 UTC (rev 282278)
</span><span class="lines">@@ -0,0 +1,161 @@
</span><ins>+/*
+ * Copyright (C) 2020-2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY CANON INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL CANON INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "InternalWritableStream.h"
+
+#include "Exception.h"
+#include "WebCoreJSClientData.h"
+
+namespace WebCore {
+
+static ExceptionOr<JSC::JSValue> invokeWritableStreamFunction(JSC::JSGlobalObject& globalObject, const JSC::Identifier& identifier, const JSC::MarkedArgumentBuffer& arguments)
+{
+    JSC::VM& vm = globalObject.vm();
+    JSC::JSLockHolder lock(vm);
+
+    auto function = globalObject.get(&globalObject, identifier);
+    ASSERT(function.isCallable(vm));
+
+    auto scope = DECLARE_THROW_SCOPE(vm);
+    auto callData = JSC::getCallData(vm, function);
+
+    auto result = call(&globalObject, function, callData, JSC::jsUndefined(), arguments);
+    if (UNLIKELY(scope.exception()))
+        return Exception { ExistingExceptionError };
+
+    return result;
+}
+
+ExceptionOr<Ref<InternalWritableStream>> InternalWritableStream::create(JSDOMGlobalObject& globalObject, JSC::JSValue underlyingSink, JSC::JSValue strategy)
+{
+    auto* clientData = static_cast<JSVMClientData*>(globalObject.vm().clientData);
+    auto& privateName = clientData->builtinFunctions().writableStreamInternalsBuiltins().createInternalWritableStreamPrivateName();
+
+    JSC::MarkedArgumentBuffer arguments;
+    arguments.append(underlyingSink);
+    arguments.append(strategy);
+    ASSERT(!arguments.hasOverflowed());
+
+    auto result = invokeWritableStreamFunction(globalObject, privateName, arguments);
+    if (UNLIKELY(result.hasException()))
+        return result.releaseException();
+
+    ASSERT(result.returnValue().isObject());
+    return adoptRef(*new InternalWritableStream(globalObject, *result.returnValue().toObject(&globalObject)));
+}
+
+bool InternalWritableStream::locked() const
+{
+    auto* globalObject = this->globalObject();
+    if (!globalObject)
+        return false;
+
+    auto scope = DECLARE_CATCH_SCOPE(globalObject->vm());
+
+    auto* clientData = static_cast<JSVMClientData*>(globalObject->vm().clientData);
+    auto& privateName = clientData->builtinFunctions().writableStreamInternalsBuiltins().isWritableStreamLockedPrivateName();
+
+    JSC::MarkedArgumentBuffer arguments;
+    arguments.append(guardedObject());
+    ASSERT(!arguments.hasOverflowed());
+
+    auto result = invokeWritableStreamFunction(*globalObject, privateName, arguments);
+    if (scope.exception())
+        scope.clearException();
+
+    return result.hasException() ? false : result.returnValue().isTrue();
+}
+
+void InternalWritableStream::lock()
+{
+    auto* globalObject = this->globalObject();
+    if (!globalObject)
+        return;
+
+    auto scope = DECLARE_CATCH_SCOPE(globalObject->vm());
+
+    auto* clientData = static_cast<JSVMClientData*>(globalObject->vm().clientData);
+    auto& privateName = clientData->builtinFunctions().writableStreamInternalsBuiltins().acquireWritableStreamDefaultWriterPrivateName();
+
+    JSC::MarkedArgumentBuffer arguments;
+    arguments.append(guardedObject());
+    ASSERT(!arguments.hasOverflowed());
+
+    invokeWritableStreamFunction(*globalObject, privateName, arguments);
+    if (UNLIKELY(scope.exception()))
+        scope.clearException();
+}
+
+JSC::JSValue InternalWritableStream::abort(JSC::JSGlobalObject& globalObject, JSC::JSValue reason)
+{
+    auto* clientData = static_cast<JSVMClientData*>(globalObject.vm().clientData);
+    auto& privateName = clientData->builtinFunctions().writableStreamInternalsBuiltins().writableStreamAbortForBindingsPrivateName();
+
+    JSC::MarkedArgumentBuffer arguments;
+    arguments.append(guardedObject());
+    arguments.append(reason);
+    ASSERT(!arguments.hasOverflowed());
+
+    auto result = invokeWritableStreamFunction(globalObject, privateName, arguments);
+    if (result.hasException())
+        return { };
+
+    return result.returnValue();
+}
+
+JSC::JSValue InternalWritableStream::close(JSC::JSGlobalObject& globalObject)
+{
+    auto* clientData = static_cast<JSVMClientData*>(globalObject.vm().clientData);
+    auto& privateName = clientData->builtinFunctions().writableStreamInternalsBuiltins().writableStreamCloseForBindingsPrivateName();
+
+    JSC::MarkedArgumentBuffer arguments;
+    arguments.append(guardedObject());
+    ASSERT(!arguments.hasOverflowed());
+
+    auto result = invokeWritableStreamFunction(globalObject, privateName, arguments);
+    if (result.hasException())
+        return { };
+
+    return result.returnValue();
+}
+
+JSC::JSValue InternalWritableStream::getWriter(JSC::JSGlobalObject& globalObject)
+{
+    auto* clientData = static_cast<JSVMClientData*>(globalObject.vm().clientData);
+    auto& privateName = clientData->builtinFunctions().writableStreamInternalsBuiltins().acquireWritableStreamDefaultWriterPrivateName();
+
+    JSC::MarkedArgumentBuffer arguments;
+    arguments.append(guardedObject());
+    ASSERT(!arguments.hasOverflowed());
+
+    auto result = invokeWritableStreamFunction(globalObject, privateName, arguments);
+    if (result.hasException())
+        return { };
+
+    return result.returnValue();
+}
+
+}
</ins></span></pre></div>
<a id="trunkSourceWebCorebindingsjsInternalWritableStreamh"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/bindings/js/InternalWritableStream.h (0 => 282278)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/js/InternalWritableStream.h                                (rev 0)
+++ trunk/Source/WebCore/bindings/js/InternalWritableStream.h   2021-09-10 17:22:01 UTC (rev 282278)
</span><span class="lines">@@ -0,0 +1,52 @@
</span><ins>+/*
+ * Copyright (C) 2020-2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY CANON INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL CANON INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "ExceptionOr.h"
+#include "JSDOMGuardedObject.h"
+#include <JavaScriptCore/JSObject.h>
+
+namespace WebCore {
+class InternalWritableStream final : public DOMGuarded<JSC::JSObject> {
+public:
+    static ExceptionOr<Ref<InternalWritableStream>> create(JSDOMGlobalObject&, JSC::JSValue underlyingSink, JSC::JSValue strategy);
+
+    operator JSC::JSValue() const { return guarded(); }
+
+    bool locked() const;
+    void lock();
+    JSC::JSValue abort(JSC::JSGlobalObject&, JSC::JSValue);
+    JSC::JSValue close(JSC::JSGlobalObject&);
+    JSC::JSValue getWriter(JSC::JSGlobalObject&);
+
+private:
+    InternalWritableStream(JSDOMGlobalObject& globalObject, JSC::JSObject& jsObject)
+        : DOMGuarded<JSC::JSObject>(globalObject, jsObject)
+    {
+    }
+};
+
+}
</ins></span></pre></div>
<a id="trunkSourceWebCorebindingsjsJSDOMGlobalObjectcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/js/JSDOMGlobalObject.cpp (282277 => 282278)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/js/JSDOMGlobalObject.cpp   2021-09-10 17:16:43 UTC (rev 282277)
+++ trunk/Source/WebCore/bindings/js/JSDOMGlobalObject.cpp      2021-09-10 17:22:01 UTC (rev 282278)
</span><span class="lines">@@ -46,6 +46,7 @@
</span><span class="cx"> #include "JSRemoteDOMWindow.h"
</span><span class="cx"> #include "JSWorkerGlobalScope.h"
</span><span class="cx"> #include "JSWorkletGlobalScope.h"
</span><ins>+#include "JSWritableStream.h"
</ins><span class="cx"> #include "RejectedPromiseTracker.h"
</span><span class="cx"> #include "RuntimeEnabledFeatures.h"
</span><span class="cx"> #include "ScriptModuleLoader.h"
</span><span class="lines">@@ -71,6 +72,7 @@
</span><span class="cx"> JSC_DECLARE_HOST_FUNCTION(makeGetterTypeErrorForBuiltins);
</span><span class="cx"> JSC_DECLARE_HOST_FUNCTION(makeDOMExceptionForBuiltins);
</span><span class="cx"> JSC_DECLARE_HOST_FUNCTION(isReadableByteStreamAPIEnabled);
</span><ins>+JSC_DECLARE_HOST_FUNCTION(getInternalWritableStream);
</ins><span class="cx"> JSC_DECLARE_HOST_FUNCTION(isWritableStreamAPIEnabled);
</span><span class="cx"> JSC_DECLARE_HOST_FUNCTION(whenSignalAborted);
</span><span class="cx"> JSC_DECLARE_HOST_FUNCTION(isAbortSignal);
</span><span class="lines">@@ -163,6 +165,18 @@
</span><span class="cx">     return JSValue::encode(jsBoolean(RuntimeEnabledFeatures::sharedFeatures().writableStreamAPIEnabled()));
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+JSC_DEFINE_HOST_FUNCTION(getInternalWritableStream, (JSGlobalObject* globalObject, CallFrame* callFrame))
+{
+    ASSERT(callFrame);
+    ASSERT(callFrame->argumentCount() == 1);
+
+    auto& vm = globalObject->vm();
+    auto* writableStream = jsDynamicCast<JSWritableStream*>(vm, callFrame->uncheckedArgument(0));
+    if (UNLIKELY(!writableStream))
+        return JSValue::encode(jsUndefined());
+    return JSValue::encode(writableStream->wrapped().internalWritableStream());
+}
+
</ins><span class="cx"> JSC_DEFINE_HOST_FUNCTION(whenSignalAborted, (JSGlobalObject* globalObject, CallFrame* callFrame))
</span><span class="cx"> {
</span><span class="cx">     ASSERT(callFrame);
</span><span class="lines">@@ -214,6 +228,7 @@
</span><span class="cx">         JSDOMGlobalObject::GlobalPropertyInfo(clientData.builtinNames().readableByteStreamAPIEnabledPrivateName(), JSFunction::create(vm, this, 0, String(), isReadableByteStreamAPIEnabled), PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
</span><span class="cx">         JSDOMGlobalObject::GlobalPropertyInfo(clientData.builtinNames().writableStreamAPIEnabledPrivateName(), JSFunction::create(vm, this, 0, String(), isWritableStreamAPIEnabled), PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
</span><span class="cx">         JSDOMGlobalObject::GlobalPropertyInfo(clientData.builtinNames().isAbortSignalPrivateName(), JSFunction::create(vm, this, 1, String(), isAbortSignal), PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
</span><ins>+        JSDOMGlobalObject::GlobalPropertyInfo(clientData.builtinNames().getInternalWritableStreamPrivateName(), JSFunction::create(vm, this, 1, String(), getInternalWritableStream), PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
</ins><span class="cx">     };
</span><span class="cx">     addStaticGlobals(staticGlobals, WTF_ARRAY_LENGTH(staticGlobals));
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsjsWebCoreBuiltinNamesh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h (282277 => 282278)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h   2021-09-10 17:16:43 UTC (rev 282277)
+++ trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h      2021-09-10 17:22:01 UTC (rev 282278)
</span><span class="lines">@@ -348,6 +348,7 @@
</span><span class="cx">     macro(flushAlgorithm) \
</span><span class="cx">     macro(focus) \
</span><span class="cx">     macro(frames) \
</span><ins>+    macro(getInternalWritableStream) \
</ins><span class="cx">     macro(getTracks) \
</span><span class="cx">     macro(getUserMedia) \
</span><span class="cx">     macro(gpu) \
</span><span class="lines">@@ -359,6 +360,8 @@
</span><span class="cx">     macro(inFlightWriteRequest) \
</span><span class="cx">     macro(indexedDB) \
</span><span class="cx">     macro(initializeWith) \
</span><ins>+    macro(internalStream) \
+    macro(internalWritable) \
</ins><span class="cx">     macro(isAbortSignal) \
</span><span class="cx">     macro(isDisturbed) \
</span><span class="cx">     macro(isLoading) \
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsjsWritableStreamcpp"></a>
<div class="delfile"><h4>Deleted: trunk/Source/WebCore/bindings/js/WritableStream.cpp (282277 => 282278)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/js/WritableStream.cpp      2021-09-10 17:16:43 UTC (rev 282277)
+++ trunk/Source/WebCore/bindings/js/WritableStream.cpp 2021-09-10 17:22:01 UTC (rev 282278)
</span><span class="lines">@@ -1,113 +0,0 @@
</span><del>-/*
- * Copyright (C) 2020-2021 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY CANON INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL CANON INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#include "WritableStream.h"
-
-#include "Exception.h"
-#include "ExceptionCode.h"
-#include "JSDOMConvertSequences.h"
-#include "JSWritableStreamSink.h"
-#include "WebCoreJSClientData.h"
-
-
-namespace WebCore {
-using namespace JSC;
-
-namespace WritableStreamInternal {
-static inline JSC::JSValue callFunction(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue jsFunction, JSC::JSValue thisValue, const JSC::ArgList& arguments)
-{
-    VM& vm = lexicalGlobalObject.vm();
-    auto scope = DECLARE_CATCH_SCOPE(vm);
-    auto callData = JSC::getCallData(vm, jsFunction);
-    ASSERT(callData.type != JSC::CallData::Type::None);
-    auto result = call(&lexicalGlobalObject, jsFunction, callData, thisValue, arguments);
-    scope.assertNoExceptionExceptTermination();
-    return result;
-}
-}
-
-static inline bool checkWritableStream(JSDOMGlobalObject& globalObject, JSWritableStream* writableStream, JSC::JSValue function)
-{
-    auto& lexicalGlobalObject = globalObject;
-
-    ASSERT(function);
-    JSC::MarkedArgumentBuffer arguments;
-    arguments.append(writableStream);
-    ASSERT(!arguments.hasOverflowed());
-    return WritableStreamInternal::callFunction(lexicalGlobalObject, function, JSC::jsUndefined(), arguments).isTrue();
-}
-
-ExceptionOr<Ref<WritableStream>> WritableStream::create(JSC::JSGlobalObject& lexicalGlobalObject, RefPtr<WritableStreamSink>&& sink)
-{
-    VM& vm = lexicalGlobalObject.vm();
-    auto scope = DECLARE_THROW_SCOPE(vm);
-
-    auto& clientData = *static_cast<JSVMClientData*>(vm.clientData);
-    auto& globalObject = *JSC::jsCast<JSDOMGlobalObject*>(&lexicalGlobalObject);
-
-    auto* constructor = JSC::asObject(globalObject.get(&lexicalGlobalObject, clientData.builtinNames().WritableStreamPrivateName()));
-
-    auto constructData = getConstructData(vm, constructor);
-    ASSERT(constructData.type != CallData::Type::None);
-
-    MarkedArgumentBuffer args;
-    args.append(sink ? toJSNewlyCreated(&lexicalGlobalObject, &globalObject, sink.releaseNonNull()) : JSC::jsUndefined());
-    ASSERT(!args.hasOverflowed());
-
-    JSObject* object = JSC::construct(&lexicalGlobalObject, constructor, constructData, args);
-    ASSERT(!!scope.exception() == !object);
-    RETURN_IF_EXCEPTION(scope, Exception { ExistingExceptionError });
-
-    return create(globalObject, *jsCast<JSWritableStream*>(object));
-}
-
-void WritableStream::lock()
-{
-    auto& lexicalGlobalObject = *m_globalObject;
-    VM& vm = lexicalGlobalObject.vm();
-    auto scope = DECLARE_CATCH_SCOPE(vm);
-
-    auto& clientData = *static_cast<JSVMClientData*>(vm.clientData);
-
-    auto* constructor = JSC::asObject(m_globalObject->get(&lexicalGlobalObject, clientData.builtinNames().WritableStreamDefaultWriterPrivateName()));
-
-    auto constructData = getConstructData(vm, constructor);
-    ASSERT(constructData.type != CallData::Type::None);
-
-    MarkedArgumentBuffer args;
-    args.append(writableStream());
-    ASSERT(!args.hasOverflowed());
-
-    JSC::construct(&lexicalGlobalObject, constructor, constructData, args);
-    scope.assertNoExceptionExceptTermination();
-}
-
-bool WritableStream::isLocked() const
-{
-    return checkWritableStream(*globalObject(), writableStream(), globalObject()->builtinInternalFunctions().writableStreamInternals().m_isWritableStreamLockedFunction.get());
-}
-
-}
</del></span></pre></div>
<a id="trunkSourceWebCorebindingsjsWritableStreamh"></a>
<div class="delfile"><h4>Deleted: trunk/Source/WebCore/bindings/js/WritableStream.h (282277 => 282278)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/js/WritableStream.h        2021-09-10 17:16:43 UTC (rev 282277)
+++ trunk/Source/WebCore/bindings/js/WritableStream.h   2021-09-10 17:22:01 UTC (rev 282278)
</span><span class="lines">@@ -1,94 +0,0 @@
</span><del>-/*
- * Copyright (C) 2020 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY CANON INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL CANON INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#pragma once
-
-#include "ExceptionOr.h"
-#include "JSDOMBinding.h"
-#include "JSDOMConvert.h"
-#include "JSDOMGuardedObject.h"
-#include "JSWritableStream.h"
-
-namespace WebCore {
-
-class WritableStreamSink;
-
-class WritableStream final : public DOMGuarded<JSWritableStream> {
-public:
-    static Ref<WritableStream> create(JSDOMGlobalObject& globalObject, JSWritableStream& jsStream) { return adoptRef(*new WritableStream(globalObject, jsStream)); }
-
-    static ExceptionOr<Ref<WritableStream>> create(JSC::JSGlobalObject&, RefPtr<WritableStreamSink>&&);
-    JSWritableStream* writableStream() const { return guarded(); }
-
-    void lock();
-    bool isLocked() const;
-
-private:
-    WritableStream(JSDOMGlobalObject&, JSWritableStream&);
-};
-
-struct JSWritableStreamWrapperConverter {
-    static RefPtr<WritableStream> toWrapped(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value)
-    {
-        JSC::VM& vm = JSC::getVM(&lexicalGlobalObject);
-        auto* globalObject = JSC::jsDynamicCast<JSDOMGlobalObject*>(vm, &lexicalGlobalObject);
-        if (!globalObject)
-            return nullptr;
-
-        auto* WritableStream = JSC::jsDynamicCast<JSWritableStream*>(vm, value);
-        if (!WritableStream)
-            return nullptr;
-
-        return WritableStream::create(*globalObject, *WritableStream);
-    }
-};
-
-template<> struct JSDOMWrapperConverterTraits<WritableStream> {
-    using WrapperClass = JSWritableStreamWrapperConverter;
-    using ToWrappedReturnType = RefPtr<WritableStream>;
-    static constexpr bool needsState = true;
-};
-
-inline WritableStream::WritableStream(JSDOMGlobalObject& globalObject, JSWritableStream& WritableStream)
-    : DOMGuarded<JSWritableStream>(globalObject, WritableStream)
-{
-}
-
-inline JSC::JSValue toJS(JSC::JSGlobalObject*, JSC::JSGlobalObject*, WritableStream* stream)
-{
-    return stream ? stream->writableStream() : JSC::jsUndefined();
-}
-
-inline JSC::JSValue toJS(JSC::JSGlobalObject*, JSC::JSGlobalObject*, WritableStream& stream)
-{
-    return stream.writableStream();
-}
-
-inline JSC::JSValue toJSNewlyCreated(JSC::JSGlobalObject*, JSDOMGlobalObject*, Ref<WritableStream>&& stream)
-{
-    return stream->writableStream();
-}
-
-}
</del></span></pre></div>
<a id="trunkSourceWebCorebindingsscriptsCodeGeneratorJSpm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm (282277 => 282278)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm 2021-09-10 17:16:43 UTC (rev 282277)
+++ trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm    2021-09-10 17:22:01 UTC (rev 282278)
</span><span class="lines">@@ -627,11 +627,6 @@
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    if ($type->name eq "WritableStream") {
-        AddToIncludes("WritableStream.h", $includesRef, $conditional);
-        return;
-    }
-
</del><span class="cx">     if ($type->name eq "XPathNSResolver") {
</span><span class="cx">         AddToIncludes("JSXPathNSResolver.h", $includesRef, $conditional);
</span><span class="cx">         AddToIncludes("JSDOMConvertXPathNSResolver.h", $includesRef, $conditional);
</span></span></pre>
</div>
</div>

</body>
</html>