From 3389a5e168531ba57e9c65a58c118b9f869c824e Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Sun, 25 Sep 2022 11:37:26 -0400 Subject: [PATCH] buffer: initialize TextDecoder once on blob.text() --- lib/internal/blob.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/internal/blob.js b/lib/internal/blob.js index 8014a1bb5b0349..397bffabba7b5a 100644 --- a/lib/internal/blob.js +++ b/lib/internal/blob.js @@ -78,6 +78,7 @@ let ReadableStream; let URL; const enc = new TextEncoder(); +let dec; // Yes, lazy loading is annoying but because of circular // references between the url, internal/blob, and buffer @@ -311,7 +312,8 @@ class Blob { if (!isBlob(this)) throw new ERR_INVALID_THIS('Blob'); - const dec = new TextDecoder(); + dec ??= new TextDecoder(); + return dec.decode(await this.arrayBuffer()); }