gecko-dev/testing/web-platform/tests/encoding/streams/decode-bad-chunks.any.js
Adam Rice 4078f670b8 Bug 1523562 [wpt PR 14794] - TextDecoderStream: Permit detached buffers, a=testonly
Automatic update from web-platform-tests
TextDecoderStream: Permit detached buffers

Since https://github.com/heycam/webidl/pull/605 converting a chunk to a
BufferSource no longer throws if the chunk is detached. Update the
TextDecoderStream implementation and tests to match the new behaviour.

Change-Id: I26230d9cbfce871b3dae75e612539564d4578977
Reviewed-on: https://chromium-review.googlesource.com/c/1404906
Reviewed-by: Joshua Bell <jsbell@chromium.org>
Commit-Queue: Adam Rice <ricea@chromium.org>
Cr-Commit-Position: refs/heads/master@{#621897}

--

wpt-commits: 35d1ca9cb52f755566ba6681fe555626379b9e2c
wpt-pr: 14794
2019-02-07 21:50:14 +00:00

52 lines
1.1 KiB
JavaScript

// META: global=worker
'use strict';
const badChunks = [
{
name: 'undefined',
value: undefined
},
{
name: 'null',
value: null
},
{
name: 'numeric',
value: 3.14
},
{
name: 'object, not BufferSource',
value: {}
},
{
name: 'array',
value: [65]
},
{
name: 'SharedArrayBuffer',
// Use a getter to postpone construction so that all tests don't fail where
// SharedArrayBuffer is not yet implemented.
get value() {
return new SharedArrayBuffer();
}
},
{
name: 'shared Uint8Array',
get value() {
new Uint8Array(new SharedArrayBuffer())
}
}
];
for (const chunk of badChunks) {
promise_test(async t => {
const tds = new TextDecoderStream();
const reader = tds.readable.getReader();
const writer = tds.writable.getWriter();
const writePromise = writer.write(chunk.value);
const readPromise = reader.read();
await promise_rejects(t, new TypeError(), writePromise, 'write should reject');
await promise_rejects(t, new TypeError(), readPromise, 'read should reject');
}, `chunk of type ${chunk.name} should error the stream`);
}