From bb642e8c7c9f8ab16540d2e3b1ef6a5543ded91e Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Fri, 15 Mar 2019 16:29:54 -0400 Subject: Fix TextDecoder for SharedArrayBuffer backed TypedArray (#1940) --- js/text_encoding_test.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'js/text_encoding_test.ts') diff --git a/js/text_encoding_test.ts b/js/text_encoding_test.ts index 4eab24808..0799b1c3e 100644 --- a/js/text_encoding_test.ts +++ b/js/text_encoding_test.ts @@ -65,3 +65,29 @@ test(function textEncoder2() { 0xf0, 0x9d, 0x93, 0xbd ]); }); + +test(function textDecoderSharedUint8Array() { + const ab = new SharedArrayBuffer(6); + const dataView = new DataView(ab); + const charCodeA = "A".charCodeAt(0); + for (let i = 0; i < ab.byteLength; i++) { + dataView.setUint8(i, charCodeA + i); + } + const ui8 = new Uint8Array(ab); + const decoder = new TextDecoder(); + const actual = decoder.decode(ui8); + assertEquals(actual, "ABCDEF"); +}); + +test(function textDecoderSharedInt32Array() { + const ab = new SharedArrayBuffer(8); + const dataView = new DataView(ab); + const charCodeA = "A".charCodeAt(0); + for (let i = 0; i < ab.byteLength; i++) { + dataView.setUint8(i, charCodeA + i); + } + const i32 = new Int32Array(ab); + const decoder = new TextDecoder(); + const actual = decoder.decode(i32); + assertEquals(actual, "ABCDEFGH"); +}); -- cgit v1.2.3