Skip to content

Commit

Permalink
switch to owning
Browse files Browse the repository at this point in the history
  • Loading branch information
youennf committed Apr 13, 2023
1 parent f8a02fe commit b388278
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 243 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@ promise_test(async () => {

const source = {
start(controller) {
controller.enqueue(port1, { transfer : port1 });
controller.enqueue(port1, { transfer : [ port1 ] });
},
type: 'transfer'
type: 'owning'
};

const stream = new ReadableStream(source);

const chunk = await clone1.getReader().read().then((value) => {
assert_unreached('clone2 should error');
}, () => { });
const chunk = await stream.getReader().read();

assert_not_equals(chunk.value, port1);

Expand All @@ -39,9 +37,9 @@ promise_test(async () => {

const source = {
start(controller) {
controller.enqueue({port1}, { transfer : port1 });
controller.enqueue({ port1 }, { transfer : [ port1 ] });
},
type: 'transfer'
type: 'owning'
};

const stream = new ReadableStream(source);
Expand All @@ -54,4 +52,4 @@ promise_test(async () => {
await clone2.getReader().read().then((value) => {
assert_unreached('clone2 should error');
}, () => { });
}, 'Second branch of transfer-only value ReadableStream tee should end up into errors');
}, 'Second branch of owning ReadableStream tee should end up into errors with transfer only values');
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,29 @@ promise_test(async () => {
const source = {
start(controller) {
assert_equals(videoFrame.format, 'I420');
controller.enqueue(videoFrame, { transfer : videoFrame });
controller.enqueue(videoFrame, { transfer : [ videoFrame ] });
assert_equals(videoFrame.format, null);
assert_equals(videoFrame.test, 1);
},
type: 'transfer'
type: 'owning'
};

const stream = new ReadableStream(source);
// Cancelling the stream should close all video frames, thus no console messages of GCing VideoFrames should happen.
stream.cancel();
}, 'ReadableStream of type transfer should close serialized chunks');
}, 'ReadableStream of type owning should close serialized chunks');

promise_test(async () => {
const videoFrame = createVideoFrame();
videoFrame.test = 1;
const source = {
start(controller) {
assert_equals(videoFrame.format, 'I420');
controller.enqueue({ videoFrame }, { transfer : videoFrame });
controller.enqueue({ videoFrame }, { transfer : [ videoFrame ] });
assert_equals(videoFrame.format, null);
assert_equals(videoFrame.test, 1);
},
type: 'transfer'
type: 'owning'
};

const stream = new ReadableStream(source);
Expand All @@ -59,21 +59,21 @@ promise_test(async () => {
assert_equals(chunk.value.videoFrame.test, undefined);

chunk.value.videoFrame.close();
}, 'ReadableStream of type transfer should transfer JS chunks with transferred values');
}, 'ReadableStream of type owning should transfer JS chunks with transferred values');

promise_test(async () => {
const videoFrame = createVideoFrame();
videoFrame.close();
const source = {
start(controller) {
try {
controller.enqueue(videoFrame, { transfer : videoFrame });
controller.enqueue(videoFrame, { transfer : [ videoFrame ] });
assert_unreached('enqueue should throw');
} catch (e) {
//
}
},
type: 'transfer'
type: 'owning'
};

const stream = new ReadableStream(source);
Expand All @@ -83,15 +83,15 @@ promise_test(async () => {
assert_unreached('enqueue should error the stream');
}, () => {
});
}, 'ReadableStream of type transfer should error when trying to enqueue not serializable values');
}, 'ReadableStream of type owning should error when trying to enqueue not serializable values');

promise_test(async () => {
const videoFrame = createVideoFrame();
const source = {
start(controller) {
controller.enqueue(videoFrame, { transfer : videoFrame });
controller.enqueue(videoFrame, { transfer : [ videoFrame ] });
},
type: 'transfer'
type: 'owning'
};

const stream = new ReadableStream(source);
Expand All @@ -106,19 +106,19 @@ promise_test(async () => {

chunk1.value.close();
chunk2.value.close();
}, 'ReadableStream of type transfer should clone serializable objects when teeing');
}, 'ReadableStream of type owning should clone serializable objects when teeing');

promise_test(async () => {
const videoFrame = createVideoFrame();
videoFrame.test = 1;
const source = {
start(controller) {
assert_equals(videoFrame.format, 'I420');
controller.enqueue({ videoFrame }, { transfer : videoFrame });
controller.enqueue({ videoFrame }, { transfer : [ videoFrame ] });
assert_equals(videoFrame.format, null);
assert_equals(videoFrame.test, 1);
},
type: 'transfer'
type: 'owning'
};

const stream = new ReadableStream(source);
Expand All @@ -133,4 +133,4 @@ promise_test(async () => {

chunk1.value.videoFrame.close();
chunk2.value.videoFrame.close();
}, 'ReadableStream of type transfer should clone JS Objects with serializables when teeing');
}, 'ReadableStream of type owning should clone JS Objects with serializables when teeing');
47 changes: 47 additions & 0 deletions streams/readable-streams/owning-type.any.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// META: global=window,worker
// META: script=../resources/test-utils.js
// META: script=../resources/rs-utils.js
'use strict';

test(() => {
new ReadableStream({ type: 'owning' }); // ReadableStream constructed with 'owning' type
}, 'ReadableStream can be constructed with owning type');

test(() => {
let startCalled = false;

const source = {
start(controller) {
assert_equals(this, source, 'source is this during start');
assert_true(controller instanceof ReadableStreamDefaultController, 'default controller');
startCalled = true;
},
type: 'owning'
};

new ReadableStream(source);
assert_true(startCalled);
}, 'ReadableStream of type owning should call start with a ReadableStreamDefaultController');

promise_test(async () => {
const uint8Array = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
const buffer = uint8Array.buffer;
buffer.test = 1;
const source = {
start(controller) {
assert_equals(buffer.byteLength, 8);
controller.enqueue(buffer, { transfer : [ buffer ] });
assert_equals(buffer.test, 1);
},
type: 'owning'
};

const stream = new ReadableStream(source);
const reader = stream.getReader();

const chunk = await reader.read();

assert_not_equals(chunk.value, buffer);
assert_equals(chunk.value.byteLength, 8);
assert_equals(chunk.value.test, undefined);
}, 'ReadableStream of type owning should transfer enqueued chunks');
Loading

1 comment on commit b388278

@community-tc-integration
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh oh! Looks like an error! Details

HttpError: Invalid request.

Only 65535 characters are allowed; 85636 were supplied.

Please sign in to comment.