Skip to content

Commit e5c3a24

Browse files
committed
Owning WritableStream reference implementation
1 parent c4ebc02 commit e5c3a24

5 files changed

+18
-8
lines changed

reference-implementation/lib/UnderlyingSink.webidl

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ dictionary UnderlyingSink {
33
UnderlyingSinkWriteCallback write;
44
UnderlyingSinkCloseCallback close;
55
UnderlyingSinkAbortCallback abort;
6-
any type;
6+
WritableStreamType type;
77
};
88

99
callback UnderlyingSinkStartCallback = any (WritableStreamDefaultController controller);
1010
callback UnderlyingSinkWriteCallback = Promise<undefined> (any chunk, WritableStreamDefaultController controller);
1111
callback UnderlyingSinkCloseCallback = Promise<undefined> ();
1212
callback UnderlyingSinkAbortCallback = Promise<undefined> (optional any reason);
13+
14+
enum WritableStreamType { "owning" };

reference-implementation/lib/WritableStream-impl.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ exports.implementation = class WritableStreamImpl {
1212
underlyingSink = null;
1313
}
1414
const underlyingSinkDict = UnderlyingSink.convert(underlyingSink);
15-
if ('type' in underlyingSinkDict) {
15+
if ('type' in underlyingSinkDict && underlyingSourceDict.type !== 'owning') {
1616
throw new RangeError('Invalid type is specified');
1717
}
1818

reference-implementation/lib/WritableStreamDefaultWriter-impl.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,13 @@ exports.implementation = class WritableStreamDefaultWriterImpl {
5959
aos.WritableStreamDefaultWriterRelease(this);
6060
}
6161

62-
write(chunk) {
62+
write(chunk, options) {
63+
const transferList = options ? options.transfer : undefined;
6364
if (this._stream === undefined) {
6465
return promiseRejectedWith(defaultWriterLockException('write to'));
6566
}
6667

67-
return aos.WritableStreamDefaultWriterWrite(this, chunk);
68+
return aos.WritableStreamDefaultWriterWrite(this, chunk, transferList);
6869
}
6970
};
7071

reference-implementation/lib/WritableStreamDefaultWriter.webidl

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
dictionary StructuredSerializeOptions {
2+
sequence<object> transfer = [];
3+
};
4+
15
[Exposed=(Window,Worker,Worklet)]
26
interface WritableStreamDefaultWriter {
37
constructor(WritableStream stream);
@@ -9,5 +13,5 @@ interface WritableStreamDefaultWriter {
913
Promise<undefined> abort(optional any reason);
1014
Promise<undefined> close();
1115
undefined releaseLock();
12-
Promise<undefined> write(optional any chunk);
16+
Promise<undefined> write(optional any chunk, optional StructuredSerializeOptions options = { });
1317
};

reference-implementation/lib/abstract-ops/writable-streams.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ function WritableStreamDefaultWriterWrite(writer, chunk) {
529529
// Default controllers
530530

531531
function SetUpWritableStreamDefaultController(stream, controller, startAlgorithm, writeAlgorithm, closeAlgorithm,
532-
abortAlgorithm, highWaterMark, sizeAlgorithm) {
532+
abortAlgorithm, highWaterMark, sizeAlgorithm, isOwning) {
533533
assert(WritableStream.isImpl(stream));
534534
assert(stream._controller === undefined);
535535

@@ -551,6 +551,8 @@ function SetUpWritableStreamDefaultController(stream, controller, startAlgorithm
551551
controller._closeAlgorithm = closeAlgorithm;
552552
controller._abortAlgorithm = abortAlgorithm;
553553

554+
controller._isOwning = isOwning;
555+
554556
const backpressure = WritableStreamDefaultControllerGetBackpressure(controller);
555557
WritableStreamUpdateBackpressure(stream, backpressure);
556558

@@ -579,6 +581,7 @@ function SetUpWritableStreamDefaultControllerFromUnderlyingSink(stream, underlyi
579581
let writeAlgorithm = () => promiseResolvedWith(undefined);
580582
let closeAlgorithm = () => promiseResolvedWith(undefined);
581583
let abortAlgorithm = () => promiseResolvedWith(undefined);
584+
const isOwning = underlyingSinkDict.type === 'owning';
582585

583586
if ('start' in underlyingSinkDict) {
584587
startAlgorithm = () => underlyingSinkDict.start.call(underlyingSink, controller);
@@ -594,8 +597,8 @@ function SetUpWritableStreamDefaultControllerFromUnderlyingSink(stream, underlyi
594597
}
595598

596599
SetUpWritableStreamDefaultController(
597-
stream, controller, startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, highWaterMark, sizeAlgorithm
598-
);
600+
stream, controller, startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, highWaterMark, sizeAlgorithm,
601+
isOwning);
599602
}
600603

601604
function WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller) {

0 commit comments

Comments
 (0)