summaryrefslogtreecommitdiff
path: root/op_crates/web/text_encoding_test.js
diff options
context:
space:
mode:
authorCraig Morten <46491566+asos-craigmorten@users.noreply.github.com>2020-08-24 19:09:31 +0100
committerGitHub <noreply@github.com>2020-08-24 20:09:31 +0200
commit2d800f2cb936d2974982248e589a888250b5b604 (patch)
treeea02cf624452b0f30af5c376d61c2d60c7d58d31 /op_crates/web/text_encoding_test.js
parent545ea8e2171b0dc83477b98441241afe39771ed6 (diff)
fix(op_crates/web): throw TypeError on invalid input types in TextDecoder.decode() (#7179)
Diffstat (limited to 'op_crates/web/text_encoding_test.js')
-rw-r--r--op_crates/web/text_encoding_test.js41
1 files changed, 41 insertions, 0 deletions
diff --git a/op_crates/web/text_encoding_test.js b/op_crates/web/text_encoding_test.js
index f741fe409..06537df24 100644
--- a/op_crates/web/text_encoding_test.js
+++ b/op_crates/web/text_encoding_test.js
@@ -131,6 +131,44 @@ function textDecoderErrorEncoding() {
assert(didThrow);
}
+function textDecoderHandlesUndefined() {
+ const fixture = undefined;
+ const decoder = new TextDecoder();
+ assert(decoder.decode(fixture) === "");
+}
+
+function textDecoderThrowsOnEmpty() {
+ const fixture = "";
+ const decoder = new TextDecoder();
+ let didThrow = false;
+ try {
+ decoder.decode(fixture);
+ } catch (e) {
+ didThrow = true;
+ assert(
+ e.message ===
+ "Provided input is not of type ArrayBuffer or ArrayBufferView",
+ );
+ }
+ assert(didThrow);
+}
+
+function textDecoderThrowsOnNull() {
+ const fixture = null;
+ const decoder = new TextDecoder();
+ let didThrow = false;
+ try {
+ decoder.decode(fixture);
+ } catch (e) {
+ didThrow = true;
+ assert(
+ e.message ===
+ "Provided input is not of type ArrayBuffer or ArrayBufferView",
+ );
+ }
+ assert(didThrow);
+}
+
function textEncoder() {
const fixture = "𝓽𝓮𝔁𝓽";
const encoder = new TextEncoder();
@@ -231,6 +269,9 @@ function main() {
textDecoderNotBOM();
textDecoderASCII();
textDecoderErrorEncoding();
+ textDecoderHandlesUndefined();
+ textDecoderThrowsOnEmpty();
+ textDecoderThrowsOnNull();
textEncoder();
textEncodeInto();
textEncodeInto2();