Skip to content

Commit

Permalink
Use HTML's Transfer abstract operation directly
Browse files Browse the repository at this point in the history
This allows us to eliminate the somewhat-silly SameRealmTransfer.
  • Loading branch information
domenic committed Aug 26, 2016
1 parent aff2c3a commit 0810b64
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions index.bs
Expand Up @@ -30,7 +30,7 @@ Ignored Vars: e
<pre class="anchors">
urlPrefix: https://html.spec.whatwg.org/multipage/; spec: HTML
text: StructuredClone; urlPrefix: infrastructure.html; type: abstract-op
text: StructuredCloneWithTransfer; urlPrefix: infrastructure.html; type: abstract-op
text: Transfer; url: infrastructure.html#transfer-abstract-op; type: abstract-op
text: WebSocket; url: comms.html#websocket; type: interface
text: transferable objects; url: infrastructure.html; type: dfn
urlPrefix: https://tc39.github.io/ecma262/; spec: ECMASCRIPT
Expand Down Expand Up @@ -2124,7 +2124,7 @@ nothrow>ReadableByteStreamControllerEnqueue ( <var>controller</var>, <var>chunk<
1. Let _buffer_ be _chunk_.[[ViewedArrayBuffer]].
1. Let _byteOffset_ be _chunk_.[[ByteOffset]].
1. Let _byteLength_ be _chunk_.[[ByteLength]].
1. Let _transferredBuffer_ be ! SameRealmTransfer(_buffer_).
1. Let _transferredBuffer_ be ! <a abstract-op>Transfer</a>(_buffer_, the current Realm Record).
1. If ! ReadableStreamHasDefaultReader(_stream_) is *true*
1. If ! ReadableStreamGetNumReadRequests(_stream_) is *0*,
1. Perform ! ReadableByteStreamControllerEnqueueChunkToQueue(_controller_, _transferredBuffer_, _byteOffset_,
Expand Down Expand Up @@ -2279,7 +2279,8 @@ nothrow>ReadableByteStreamControllerPullInto ( <var>controller</var>, <var>view<
_view_.[[ByteOffset]], [[byteLength]]: _view_.[[ByteLength]], [[bytesFilled]]: *0*, [[elementSize]]: _elementSize_,
[[ctor]]: _ctor_, [[readerType]]: `"byob"`}.
1. If _controller_.[[pendingPullIntos]] is not empty,
1. Set _pullIntoDescriptor_.[[buffer]] to ! SameRealmTransfer(_pullIntoDescriptor_.[[buffer]]).
1. Set _pullIntoDescriptor_.[[buffer]] to ! <a abstract-op>Transfer</a>(_pullIntoDescriptor_.[[buffer]], the current
Realm Record).
1. Append _pullIntoDescriptor_ as the last element of _controller_.[[pendingPullIntos]].
1. Return ! ReadableStreamAddReadIntoRequest(_stream_).
1. If _stream_.[[state]] is `"closed"`,
Expand All @@ -2294,7 +2295,8 @@ nothrow>ReadableByteStreamControllerPullInto ( <var>controller</var>, <var>view<
1. Let _e_ be a *TypeError* exception.
1. Perform ! ReadableByteStreamControllerError(_controller_, _e_).
1. Return a promise rejected with _e_.
1. Set _pullIntoDescriptor_.[[buffer]] to ! SameRealmTransfer(_pullIntoDescriptor_.[[buffer]]).
1. Set _pullIntoDescriptor_.[[buffer]] to ! <a abstract-op>Transfer</a>(_pullIntoDescriptor_.[[buffer]], the current
Realm Record).
1. Append _pullIntoDescriptor_ as the last element of _controller_.[[pendingPullIntos]].
1. Let _promise_ be ! ReadableStreamAddReadIntoRequest(_stream_).
1. Perform ! ReadableByteStreamControllerCallPullIfNeeded(_controller_).
Expand All @@ -2316,7 +2318,8 @@ throws>ReadableByteStreamControllerRespond ( <var>controller</var>, <var>bytesWr
nothrow>ReadableByteStreamControllerRespondInClosedState ( <var>controller</var>, <var>firstDescriptor</var> )</h4>

<emu-alg>
1. Set _firstDescriptor_.[[buffer]] to ! SameRealmTransfer(_firstDescriptor_.[[buffer]]).
1. Set _firstDescriptor_.[[buffer]] to ! <a abstract-op>Transfer</a>(_firstDescriptor_.[[buffer]], the current Realm
Record).
1. Assert: _firstDescriptor_.[[bytesFilled]] is *0*.
1. Let _stream_ be _controller_.[[controlledReadableStream]].
1. Repeat the following steps while ! ReadableStreamGetNumReadIntoRequests(_stream_) > *0*,
Expand All @@ -2342,7 +2345,8 @@ aoid="ReadableByteStreamControllerRespondInReadableState" throws>ReadableByteStr
%ArrayBuffer%).
1. Perform ! ReadableByteStreamControllerEnqueueChunkToQueue(_controller_, _remainder_, *0*,
_remainder_.[[ByteLength]]).
1. Set _pullIntoDescriptor_.[[buffer]] to ! SameRealmTransfer(_pullIntoDescriptor_.[[buffer]]).
1. Set _pullIntoDescriptor_.[[buffer]] to ! <a abstract-op>Transfer</a>(_pullIntoDescriptor_.[[buffer]], the current
Realm Record).
1. Set _pullIntoDescriptor_.[[bytesFilled]] to _pullIntoDescriptor_.[[bytesFilled]] − _remainderSize_.
1. Perform ! ReadableByteStreamControllerCommitPullIntoDescriptor(_controller_.[[controlledReadableStream]],
_pullIntoDescriptor_).
Expand Down Expand Up @@ -3581,19 +3585,6 @@ A few abstract operations are used in this specification for utility purposes. W
1. Otherwise, return a new promise resolved with _returnValue_.[[Value]].
</emu-alg>

<h4 id="same-realm-transfer" aoid="SameRealmTransfer" nothrow>SameRealmTransfer( <var>O</var> )</h4>

<div class="note">
SameRealmTransfer takes as its argument a <a>transferable object</a> and returns a new object, created in the same
realm, with the same underlying data. The original object becomes detached.
</div>

<emu-alg>
1. Let _transferResult_ be ! <a abstract-op>StructuredCloneWithTransfer</a>(*undefined*, « _O_ », the current Realm
Record).
1. Return the first (and only) element of _transferResult_.[[TransferList]].
</emu-alg>

<h4 id="validate-and-normalize-high-water-mark" aoid="ValidateAndNormalizeHighWaterMark"
throws>ValidateAndNormalizeHighWaterMark ( <var>highWaterMark</var> )</h4>

Expand Down

0 comments on commit 0810b64

Please sign in to comment.