@@ -461,10 +461,10 @@ ReadableStream(<var>underlyingSource</var> = {}, { <var>size</var>, <var>highWat
461
461
1. If _highWaterMark_ is *undefined*, let _highWaterMark_ be *0*.
462
462
1. Set *this*.[[readableStreamController]] to ? Construct(`<a idl>ReadableByteStreamController</a> `, « *this*,
463
463
_underlyingSource_, _highWaterMark_ »).
464
- 1. Otherwise, if _type_ is *undefined*,
464
+ 1. Otherwise, if _type_ is *undefined* or _type_ is `"cloning"` ,
465
465
1. If _highWaterMark_ is *undefined*, let _highWaterMark_ be *1*.
466
466
1. Set *this*.[[readableStreamController]] to ? Construct(`<a idl>ReadableStreamDefaultController</a> `, « *this*,
467
- _underlyingSource_, _size_, _highWaterMark_ »).
467
+ _underlyingSource_, _size_, _highWaterMark_, _type_ »).
468
468
1. Otherwise, throw a *RangeError* exception.
469
469
</emu-alg>
470
470
@@ -747,12 +747,17 @@ The following internal method is implemented by each {{ReadableStream}} instance
747
747
<emu-alg>
748
748
1. If ! IsReadableStreamLocked(*this*) is *true*, throw a *TypeError* exception.
749
749
1. If *this*.[[state]] is `"errored"`, throw a *TypeError* exception.
750
+ 1. Let _controller_ be *this*.[[readableStreamController]] .
751
+ 1. If _controller_.[[targetRealm]] is *undefined*, throw a *TypeError* exception.
750
752
1. Let _that_ be a new instance of <a idl>ReadableStream</a> in _targetRealm_.
751
753
1. Set _that_.[[state]] to *this*.[[state]] .
752
754
1. Set _that_.[[disturbed]] to *this*.[[disturbed]] .
753
- 1. Let _controller_ be *this*.[[readableStreamController]] .
754
755
1. Set _controller_.[[controlledReadableStream]] to _that_.
755
756
1. Set _that_.[[readableStreamController]] to _controller_.
757
+ 1. Let _queue_ be _controller_.[[queue]] .
758
+ 1. Repeat for each Record {[[value]] , [[size]] } _pair_ that is an element of _queue_,
759
+ 1. Set _pair_.[[value]] to ! <a abstract-op>StructuredClone</a> (_pair_.[[value]] , _targetRealm_).
760
+ 1. Set _controller_.[[targetRealm]] to _targetRealm_.
756
761
1. Set _this_.[[Detached]] to *true*.
757
762
1. Return _that_.
758
763
</emu-alg>
@@ -1472,6 +1477,12 @@ Instances of {{ReadableStreamDefaultController}} are created with the internal s
1472
1477
<th> Description (<em> non-normative</em> )</th>
1473
1478
</tr>
1474
1479
</thead>
1480
+ <tr>
1481
+ <td> \[[targetRealm]]
1482
+ <td> Either *undefined*, or a Realm Record. If set to a Realm Record, ReadableStreamDefaultControllerEnqueue
1483
+ will perform the structured clone algorithm on passed chunks, cloning them into the targetRealm
1484
+ and enqueueing the result.
1485
+ </tr>
1475
1486
<tr>
1476
1487
<td> \[[closeRequested]]
1477
1488
<td> A boolean flag indicating whether the stream has been closed by its <a>underlying source</a> , but still has
@@ -1520,7 +1531,7 @@ Instances of {{ReadableStreamDefaultController}} are created with the internal s
1520
1531
<h4 id="rs-default-controller-constructor" constructor for="ReadableStreamDefaultController"
1521
1532
lt="ReadableStreamDefaultController(stream, underlyingSource, size, highWaterMark)">new
1522
1533
ReadableStreamDefaultController(<var>stream</var>, <var>underlyingSource</var>, <var>size</var>,
1523
- <var>highWaterMark</var>)</h4>
1534
+ <var>highWaterMark</var>, <var>type</var> )</h4>
1524
1535
1525
1536
<div class="note">
1526
1537
The <code> ReadableStreamDefaultController</code> constructor cannot be used directly; it only works on a
@@ -1534,6 +1545,8 @@ ReadableStreamDefaultController(<var>stream</var>, <var>underlyingSource</var>,
1534
1545
1. Set *this*.[[underlyingSource]] to _underlyingSource_.
1535
1546
1. Set *this*.[[queue]] to a new empty List.
1536
1547
1. Set *this*.[[started]] , *this*.[[closeRequested]] , *this*.[[pullAgain]] , and *this*.[[pulling]] to *false*.
1548
+ 1. Set *this*.[[targetRealm]] to *undefined*.
1549
+ 1. If _type_ is `"cloning"`, set *this*.[[targetRealm]] to the current Realm Record.
1537
1550
1. Let _normalizedStrategy_ be ? ValidateAndNormalizeQueuingStrategy(_size_, _highWaterMark_).
1538
1551
1. Set *this*.[[strategySize]] to _normalizedStrategy_.[[size]] and *this*.[[strategyHWM]] to
1539
1552
_normalizedStrategy_.[[highWaterMark]] .
@@ -1707,8 +1720,14 @@ asserts).
1707
1720
1. Let _stream_ be _controller_.[[controlledReadableStream]] .
1708
1721
1. Assert: _controller_.[[closeRequested]] is *false*.
1709
1722
1. Assert: _stream_.[[state]] is `"readable"`.
1710
- 1. If ! IsReadableStreamLocked(_stream_) is *true* and ! ReadableStreamGetNumReadRequests(_stream_) > *0*, perform
1711
- ! ReadableStreamFulfillReadRequest(_stream_, _chunk_, *false*).
1723
+ 1. If ! IsReadableStreamLocked(_stream_) is *true* and ! ReadableStreamGetNumReadRequests(_stream_) > *0*,
1724
+ 1. If _controller_.[[targetRealm]] is not *undefined*,
1725
+ 1. Let _chunk_ be <a abstract-op>StructuredClone</a> (_chunk_, _controller_.[[targetRealm]] ).
1726
+ 1. If _chunk_ is an abrupt completion,
1727
+ 1. Perform ! ReadableStreamDefaultControllerErrorIfNeeded(_controller_, _chunk_.[[Value]] ).
1728
+ 1. Return _chunk_.
1729
+ 1. Let _chunk_ be _chunk_.[[Value]] .
1730
+ 1. Perform ! ReadableStreamFulfillReadRequest(_stream_, _chunk_, *false*).
1712
1731
1. Otherwise,
1713
1732
1. Let _chunkSize_ be *1*.
1714
1733
1. If _controller_.[[strategySize]] is not *undefined*,
@@ -3615,11 +3634,13 @@ throughout the rest of this standard.
3615
3634
</emu-alg>
3616
3635
3617
3636
<h4 id="enqueue-value-with-size" aoid="EnqueueValueWithSize" throws>EnqueueValueWithSize ( <var>queue</var>,
3618
- <var>value</var>, <var>size</var> )</h4>
3637
+ <var>value</var>, <var>size</var>, <var>targetRealm</var> )</h4>
3619
3638
3620
3639
<emu-alg>
3640
+ 1. If _targetRealm_ was not passed, let _targetRealm_ be *undefined*.
3621
3641
1. Let _size_ be ? ToNumber(_size_).
3622
3642
1. If ! IsFiniteNonNegativeNumber(_size_) is *false*, throw a *RangeError* exception.
3643
+ 1. If _targetRealm_ is not *undefined*, let _value_ be the result of ? StructuredClone(_value_, _targetRealm_).
3623
3644
1. Append Record {[[value]] : _value_, [[size]] : _size_} as the last element of _queue_.
3624
3645
</emu-alg>
3625
3646
0 commit comments