���� JFIF �� � ( %"1"%)+...383,7(-.-
![]() Server : Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.4.20 System : Linux st2.domain.com 3.10.0-1127.10.1.el7.x86_64 #1 SMP Wed Jun 3 14:28:03 UTC 2020 x86_64 User : apache ( 48) PHP Version : 7.4.20 Disable Function : NONE Directory : /home/real/node-v13.0.1/test/fixtures/wpt/encoding/streams/ |
// META: global=worker 'use strict'; // The browser is assumed to use the same implementation as for TextDecoder, so // this file don't replicate the exhaustive checks it has. It is just a smoke // test that non-UTF-8 encodings work at all. const encodings = [ { name: 'UTF-16BE', value: [108, 52], expected: "\u{6c34}", invalid: [0xD8, 0x00] }, { name: 'UTF-16LE', value: [52, 108], expected: "\u{6c34}", invalid: [0x00, 0xD8] }, { name: 'Shift_JIS', value: [144, 133], expected: "\u{6c34}", invalid: [255] }, { name: 'ISO-8859-14', value: [100, 240, 114], expected: "d\u{0175}r", invalid: undefined // all bytes are treated as valid } ]; for (const encoding of encodings) { promise_test(async () => { const stream = new TextDecoderStream(encoding.name); const reader = stream.readable.getReader(); const writer = stream.writable.getWriter(); const writePromise = writer.write(new Uint8Array(encoding.value)); const {value, done} = await reader.read(); assert_false(done, 'readable should not be closed'); assert_equals(value, encoding.expected, 'chunk should match expected'); await writePromise; }, `TextDecoderStream should be able to decode ${encoding.name}`); if (!encoding.invalid) continue; promise_test(async t => { const stream = new TextDecoderStream(encoding.name); const reader = stream.readable.getReader(); const writer = stream.writable.getWriter(); const writePromise = writer.write(new Uint8Array(encoding.invalid)); const closePromise = writer.close(); const {value, done} = await reader.read(); assert_false(done, 'readable should not be closed'); assert_equals(value, '\u{FFFD}', 'output should be replacement character'); await Promise.all([writePromise, closePromise]); }, `TextDecoderStream should be able to decode invalid sequences in ` + `${encoding.name}`); promise_test(async t => { const stream = new TextDecoderStream(encoding.name, {fatal: true}); const reader = stream.readable.getReader(); const writer = stream.writable.getWriter(); const writePromise = writer.write(new Uint8Array(encoding.invalid)); const closePromise = writer.close(); await promise_rejects(t, new TypeError(), reader.read(), 'readable should be errored'); await promise_rejects(t, new TypeError(), Promise.all([writePromise, closePromise]), 'writable should be errored'); }, `TextDecoderStream should be able to reject invalid sequences in ` + `${encoding.name}`); }