Revision dcc531a79a68cd725ffe68fe06467c7e8560c8ad authored by Boris Zbarsky on 08 April 2016, 10:15:41 UTC, committed by James Graham on 08 April 2016, 10:47:04 UTC
1 parent 3d7a057
textdecoder-streaming.html
<!DOCTYPE html>
<title>Encoding API: Streaming decode</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/encodings.js"></script>
<script>
var string = '\x00123ABCabc\x80\xFF\u0100\u1000\uFFFD\uD800\uDC00\uDBFF\uDFFF';
var octets = {
'utf-16le': [0x00,0x00,0x31,0x00,0x32,0x00,0x33,0x00,0x41,0x00,0x42,0x00,
0x43,0x00,0x61,0x00,0x62,0x00,0x63,0x00,0x80,0x00,0xFF,0x00,
0x00,0x01,0x00,0x10,0xFD,0xFF,0x00,0xD8,0x00,0xDC,0xFF,0xDB,
0xFF,0xDF],
'utf-16be': [0x00,0x00,0x00,0x31,0x00,0x32,0x00,0x33,0x00,0x41,0x00,0x42,
0x00,0x43,0x00,0x61,0x00,0x62,0x00,0x63,0x00,0x80,0x00,0xFF,
0x01,0x00,0x10,0x00,0xFF,0xFD,0xD8,0x00,0xDC,0x00,0xDB,0xFF,
0xDF,0xFF]
};
utf_encodings.forEach(function (encoding) {
for (var len = 1; len <= 5; ++len) {
test(function() {
var encoded = octets[encoding] ||
new TextEncoder(encoding).encode(string);
var out = '';
var decoder = new TextDecoder(encoding);
for (var i = 0; i < encoded.length; i += len) {
var sub = [];
for (var j = i; j < encoded.length && j < i + len; ++j)
sub.push(encoded[j]);
out += decoder.decode(new Uint8Array(sub), {stream: true});
}
out += decoder.decode();
assert_equals(out, string);
}, 'Streaming decode: ' + encoding + ', ' + len + ' byte window');
}
});
</script>
![swh spinner](/static/img/swh-spinner.gif)
Computing file changes ...