fune/testing/web-platform/tests/webcodecs/encoded-audio-chunk.any.js
Andreu Botella f027ecde87 Bug 1736789 [wpt PR 31328] - Throw DataCloneError when transferring non-transferable objects, a=testonly
Automatic update from web-platform-tests
Throw `DataCloneError` when transferring non-transferable objects

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. https://github.com/whatwg/html/pull/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 <yukishiino@chromium.org>
Reviewed-by: Kentaro Hara <haraken@chromium.org>
Commit-Queue: Yuki Shiino <yukishiino@chromium.org>
Cr-Commit-Position: refs/heads/main@{#934398}

--

wpt-commits: 4287b41333755fc3a4909a06ecb0780623c637fc
wpt-pr: 31328
2021-10-29 10:24:36 +00:00

45 lines
1.9 KiB
JavaScript

// META: global=window,dedicatedworker
// META: script=/webcodecs/utils.js
test(t => {
let chunk = new EncodedAudioChunk({type: 'key',
timestamp: 10,
duration: 123,
data: new Uint8Array([0x0A, 0x0B, 0x0C])});
assert_equals(chunk.type, 'key', 'type');
assert_equals(chunk.timestamp, 10, 'timestamp');
assert_equals(chunk.duration, 123, 'duration');
assert_equals(chunk.byteLength, 3, 'byteLength');
let copyDest = new Uint8Array(3);
chunk.copyTo(copyDest);
assert_equals(copyDest[0], 0x0A, 'copyDest[0]');
assert_equals(copyDest[1], 0x0B, 'copyDest[1]');
assert_equals(copyDest[2], 0x0C, 'copyDest[2]');
// Make another chunk with different values for good measure.
chunk = new EncodedAudioChunk({type: 'delta',
timestamp: 100,
data: new Uint8Array([0x00, 0x01])});
assert_equals(chunk.type, 'delta', 'type');
assert_equals(chunk.timestamp, 100, 'timestamp');
assert_equals(chunk.duration, null, 'missing duration');
assert_equals(chunk.byteLength, 2, 'byteLength');
copyDest = new Uint8Array(2);
chunk.copyTo(copyDest);
assert_equals(copyDest[0], 0x00, 'copyDest[0]');
assert_equals(copyDest[1], 0x01, 'copyDest[1]');
}, 'Test we can construct an EncodedAudioChunk.');
test(t => {
let chunk = new EncodedAudioChunk({type: 'delta',
timestamp: 100,
data: new Uint8Array([0x00, 0x01, 0x02])});
assert_throws_js(
TypeError,
() => chunk.copyTo(new Uint8Array(2)), 'destination is not large enough');
const detached = makeDetachedArrayBuffer();
assert_throws_js(
TypeError,
() => chunk.copyTo(detached), 'destination is detached');
}, 'Test copyTo() exception if destination invalid');