fune/testing/web-platform/tests/encoding/textdecoder-arguments.any.js
Joshua Bell 62a6b8f656 Bug 1692045 [wpt PR 27580] - TextDecoder: Passing explicit undefined to decode(), a=testonly
Automatic update from web-platform-tests
TextDecoder: Passing explicit undefined to decode()

Test various permutations of passing explicit undefined to decode(),
which has two optional arguments.

Chrome's binding layer had incorrect behavior here, which wasn't
tested.

Bug: 1172968
Change-Id: I6f20caa5db5505192cb8eb4b27e251bf7f42117b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2686917
Commit-Queue: Yuki Shiino <yukishiino@chromium.org>
Auto-Submit: Joshua Bell <jsbell@chromium.org>
Reviewed-by: Yuki Shiino <yukishiino@chromium.org>
Cr-Commit-Position: refs/heads/master@{#853395}

--

wpt-commits: 35f70910d3753c8b650fdfd4c716caedfefe88c9
wpt-pr: 27580
2021-02-15 11:35:20 +00:00

49 lines
1.4 KiB
JavaScript

// META: title=Encoding API: TextDecoder decode() optional arguments
test(t => {
const decoder = new TextDecoder();
// Just passing nothing.
assert_equals(
decoder.decode(undefined), '',
'Undefined as first arg should decode to empty string');
// Flushing an incomplete sequence.
decoder.decode(new Uint8Array([0xc9]), {stream: true});
assert_equals(
decoder.decode(undefined), '\uFFFD',
'Undefined as first arg should flush the stream');
}, 'TextDecoder decode() with explicit undefined');
test(t => {
const decoder = new TextDecoder();
// Just passing nothing.
assert_equals(
decoder.decode(undefined, undefined), '',
'Undefined as first arg should decode to empty string');
// Flushing an incomplete sequence.
decoder.decode(new Uint8Array([0xc9]), {stream: true});
assert_equals(
decoder.decode(undefined, undefined), '\uFFFD',
'Undefined as first arg should flush the stream');
}, 'TextDecoder decode() with undefined and undefined');
test(t => {
const decoder = new TextDecoder();
// Just passing nothing.
assert_equals(
decoder.decode(undefined, {}), '',
'Undefined as first arg should decode to empty string');
// Flushing an incomplete sequence.
decoder.decode(new Uint8Array([0xc9]), {stream: true});
assert_equals(
decoder.decode(undefined, {}), '\uFFFD',
'Undefined as first arg should flush the stream');
}, 'TextDecoder decode() with undefined and options');