Skip to content

Commit

Permalink
Throw DataCloneError when transferring non-transferable objects
Browse files Browse the repository at this point in the history
Currently attempting to transfer non-transferable objects using the
structured clone algorithm throws a `TypeError`, rather than a
`DataCloneError` `DOMException` as per the spec.

This seems like a holdover from the original definition of transferable
objects as the `Transferable` WebIDL type, since transfer lists would be
defined as `sequence<Transferable>` and so would throw a `TypeError` on
conversion. whatwg/html#727 changed transfer
lists to be `sequence<object>` and changed the
`StructuredCloneWithTransfer` algorithm (now
`StructuredSerializeWithTransfer`) to throw a `DataCloneError`
`DOMException` if any element in the transfer list is not transferable.

Bug: 816447
Change-Id: I9f4f88a2d7a593766f394256606a688f299c7b57
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3229544
Reviewed-by: Yuki Shiino <[email protected]>
Reviewed-by: Kentaro Hara <[email protected]>
Commit-Queue: Yuki Shiino <[email protected]>
Cr-Commit-Position: refs/heads/main@{#934398}
  • Loading branch information
andreubotella authored and chromium-wpt-export-bot committed Oct 25, 2021
1 parent 818c722 commit fa77036
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion webcodecs/encoded-audio-chunk.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ test(t => {
TypeError,
() => chunk.copyTo(new Uint8Array(2)), 'destination is not large enough');

const detached = makeDetachedArrayBuffer();
assert_throws_js(
TypeError,
() => chunk.copyTo(makeDetachedArrayBuffer()), 'destination is detached');
() => chunk.copyTo(detached), 'destination is detached');
}, 'Test copyTo() exception if destination invalid');
3 changes: 2 additions & 1 deletion webcodecs/encoded-video-chunk.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ test(t => {
TypeError,
() => chunk.copyTo(new Uint8Array(2)), 'destination is not large enough');

const detached = makeDetachedArrayBuffer();
assert_throws_js(
TypeError,
() => chunk.copyTo(makeDetachedArrayBuffer()), 'destiation is detached');
() => chunk.copyTo(detached), 'destination is detached');
}, 'Test copyTo() exception if destiation invalid');
5 changes: 3 additions & 2 deletions webcodecs/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ function testCanvas(ctx, width, height, expected_pixel, imageSetting, assert_com
}

function makeDetachedArrayBuffer() {
let buffer = new Uint8Array();
const buffer = new ArrayBuffer(10);
const view = new Uint8Array(buffer);
new MessageChannel().port1.postMessage(buffer, [buffer]);
return buffer;
return view;
}

0 comments on commit fa77036

Please sign in to comment.