summaryrefslogtreecommitdiff
path: root/js/text_encoding_test.ts
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2019-03-15 16:29:54 -0400
committerGitHub <noreply@github.com>2019-03-15 16:29:54 -0400
commitbb642e8c7c9f8ab16540d2e3b1ef6a5543ded91e (patch)
tree2c93ae4faa665b93e8f10793b1edf54362581a5b /js/text_encoding_test.ts
parentb2f15cf21ae7b08986468dd8d18b06f9c2e97dc2 (diff)
Fix TextDecoder for SharedArrayBuffer backed TypedArray (#1940)
Diffstat (limited to 'js/text_encoding_test.ts')
-rw-r--r--js/text_encoding_test.ts26
1 files changed, 26 insertions, 0 deletions
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");
+});