Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add TransformStreamDefaultController terminate() method
Replace close() with terminate(). In addition to closing the readable side, terminate() also errors the writable side. This stops data from being produced after we are no longer interested in it. Modify existing tests to handle the new method, and add tests for the new functionality. Closes #774.
- Loading branch information
Showing
7 changed files
with
123 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
reference-implementation/to-upstream-wpts/transform-streams/terminate.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>terminate.js browser context wrapper file</title> | ||
|
||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
|
||
<script src="../resources/test-utils.js"></script> | ||
<script src="../resources/recording-streams.js"></script> | ||
|
||
<script src="terminate.js"></script> |
86 changes: 86 additions & 0 deletions
86
reference-implementation/to-upstream-wpts/transform-streams/terminate.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
'use strict'; | ||
|
||
if (self.importScripts) { | ||
self.importScripts('/resources/testharness.js'); | ||
self.importScripts('../resources/recording-streams.js'); | ||
self.importScripts('../resources/test-utils.js'); | ||
} | ||
|
||
promise_test(t => { | ||
const ts = recordingTransformStream({}, undefined, { highWaterMark: 0 }); | ||
const rs = new ReadableStream({ | ||
start(controller) { | ||
controller.enqueue(0); | ||
} | ||
}); | ||
let pipeToRejected = false; | ||
const pipeToPromise = promise_rejects(t, new TypeError(), rs.pipeTo(ts.writable), 'pipeTo should reject').then(() => { | ||
pipeToRejected = true; | ||
}); | ||
return delay(0).then(() => { | ||
assert_array_equals(ts.events, [], 'transform() should have seen no chunks'); | ||
assert_false(pipeToRejected, 'pipeTo() should not have rejected yet'); | ||
ts.controller.terminate(); | ||
return pipeToPromise; | ||
}).then(() => { | ||
assert_array_equals(ts.events, [], 'transform() should still have seen no chunks'); | ||
assert_true(pipeToRejected, 'pipeToRejected must be true'); | ||
}); | ||
}, 'controller.terminate() should error pipeTo()'); | ||
|
||
promise_test(t => { | ||
const ts = recordingTransformStream({}, undefined, { highWaterMark: 1 }); | ||
const rs = new ReadableStream({ | ||
start(controller) { | ||
controller.enqueue(0); | ||
controller.enqueue(1); | ||
} | ||
}); | ||
const pipeToPromise = rs.pipeTo(ts.writable); | ||
return delay(0).then(() => { | ||
assert_array_equals(ts.events, ['transform', 0], 'transform() should have seen one chunk'); | ||
ts.controller.terminate(); | ||
return promise_rejects(t, new TypeError(), pipeToPromise, 'pipeTo() should reject'); | ||
}).then(() => { | ||
assert_array_equals(ts.events, ['transform', 0], 'transform() should still have seen only one chunk'); | ||
}); | ||
}, 'controller.terminate() should prevent remaining chunks from being processed'); | ||
|
||
test(() => { | ||
new TransformStream({ | ||
start(controller) { | ||
controller.enqueue(0); | ||
controller.terminate(); | ||
assert_throws(new TypeError(), () => controller.enqueue(1), 'enqueue should throw'); | ||
} | ||
}); | ||
}, 'controller.enqueue() should throw after controller.terminate()'); | ||
|
||
const error1 = new Error('error1'); | ||
error1.name = 'error1'; | ||
|
||
promise_test(t => { | ||
const ts = new TransformStream({ | ||
start(controller) { | ||
controller.enqueue(0); | ||
controller.terminate(); | ||
controller.error(error1); | ||
} | ||
}); | ||
return Promise.all([ | ||
promise_rejects(t, new TypeError(), ts.writable.abort(), 'abort() should reject with a TypeError'), | ||
promise_rejects(t, error1, ts.readable.cancel(), 'cancel() should reject with error1'), | ||
promise_rejects(t, error1, ts.readable.getReader().closed, 'closed should reject with error1') | ||
]); | ||
}, 'controller.error() after controller.terminate() with queued chunk should error the readable'); | ||
|
||
test(() => { | ||
new TransformStream({ | ||
start(controller) { | ||
controller.terminate(); | ||
assert_throws(new TypeError(), () => controller.error(error1), 'error() should throw'); | ||
} | ||
}); | ||
}, 'controller.error() after controller.terminate() without queued chunk should throw'); | ||
|
||
done(); |