From 01a71dd3935beda7a4672227b6447bf848be4326 Mon Sep 17 00:00:00 2001 From: raisinten Date: Fri, 11 Dec 2020 20:04:02 +0530 Subject: [PATCH] lib: refactor to use more primordials in internal/encoding.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/36480 Reviewed-By: Michaƫl Zasso Reviewed-By: Rich Trott Reviewed-By: Pooja D P Reviewed-By: Antoine du Hamel --- lib/internal/encoding.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/internal/encoding.js b/lib/internal/encoding.js index 8cc9bc13fbb343..17d83cc6b26c67 100644 --- a/lib/internal/encoding.js +++ b/lib/internal/encoding.js @@ -4,10 +4,11 @@ // https://encoding.spec.whatwg.org const { - Map, ObjectCreate, ObjectDefineProperties, ObjectGetOwnPropertyDescriptors, + SafeMap, + StringPrototypeSlice, Symbol, SymbolToStringTag, Uint32Array, @@ -74,7 +75,7 @@ const CONVERTER_FLAGS_IGNORE_BOM = 0x4; const empty = new Uint8Array(0); -const encodings = new Map([ +const encodings = new SafeMap([ ['unicode-1-1-utf-8', 'utf-8'], ['utf8', 'utf-8'], ['utf-8', 'utf-8'], @@ -309,7 +310,7 @@ function trimAsciiWhitespace(label) { label[e - 1] === '\u0020')) { e--; } - return label.slice(s, e); + return StringPrototypeSlice(label, s, e); } function getEncodingFromLabel(label) { @@ -504,7 +505,7 @@ function makeTextDecoderJS() { // If the very first result in the stream is a BOM, and we are not // explicitly told to ignore it, then we discard it. if (result[0] === '\ufeff') { - result = result.slice(1); + result = StringPrototypeSlice(result, 1); } this[kBOMSeen] = true; }