Skip to content

Commit 527c740

Browse files
authored
fix(ext/node): use primordials in ext/node/polyfills/internal/normalize_encoding.mjs (denoland#29283)
Towards denoland#24236. Replaces the `.toLowerCase` method with its equivalent primordial method.
1 parent 658489e commit 527c740

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

ext/node/polyfills/internal/normalize_encoding.mjs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2018-2025 the Deno authors. MIT license.
22

3-
// TODO(petamoriken): enable prefer-primordials for node polyfills
4-
// deno-lint-ignore-file prefer-primordials
3+
import { primordials } from "ext:core/mod.js";
4+
const { StringPrototypeToLowerCase } = primordials;
55

66
export function normalizeEncoding(enc) {
77
if (enc == null || enc === "utf8" || enc === "utf-8") return "utf8";
@@ -13,14 +13,14 @@ export function slowCases(enc) {
1313
case 4:
1414
if (enc === "UTF8") return "utf8";
1515
if (enc === "ucs2" || enc === "UCS2") return "utf16le";
16-
enc = `${enc}`.toLowerCase();
16+
enc = StringPrototypeToLowerCase(`${enc}`);
1717
if (enc === "utf8") return "utf8";
1818
if (enc === "ucs2") return "utf16le";
1919
break;
2020
case 3:
2121
if (
2222
enc === "hex" || enc === "HEX" ||
23-
`${enc}`.toLowerCase() === "hex"
23+
StringPrototypeToLowerCase(`${enc}`) === "hex"
2424
) {
2525
return "hex";
2626
}
@@ -31,7 +31,7 @@ export function slowCases(enc) {
3131
if (enc === "UTF-8") return "utf8";
3232
if (enc === "ASCII") return "ascii";
3333
if (enc === "UCS-2") return "utf16le";
34-
enc = `${enc}`.toLowerCase();
34+
enc = StringPrototypeToLowerCase(`${enc}`);
3535
if (enc === "utf-8") return "utf8";
3636
if (enc === "ascii") return "ascii";
3737
if (enc === "ucs-2") return "utf16le";
@@ -41,30 +41,30 @@ export function slowCases(enc) {
4141
if (enc === "latin1" || enc === "binary") return "latin1";
4242
if (enc === "BASE64") return "base64";
4343
if (enc === "LATIN1" || enc === "BINARY") return "latin1";
44-
enc = `${enc}`.toLowerCase();
44+
enc = StringPrototypeToLowerCase(`${enc}`);
4545
if (enc === "base64") return "base64";
4646
if (enc === "latin1" || enc === "binary") return "latin1";
4747
break;
4848
case 7:
4949
if (
5050
enc === "utf16le" || enc === "UTF16LE" ||
51-
`${enc}`.toLowerCase() === "utf16le"
51+
StringPrototypeToLowerCase(`${enc}`) === "utf16le"
5252
) {
5353
return "utf16le";
5454
}
5555
break;
5656
case 8:
5757
if (
5858
enc === "utf-16le" || enc === "UTF-16LE" ||
59-
`${enc}`.toLowerCase() === "utf-16le"
59+
StringPrototypeToLowerCase(`${enc}`) === "utf-16le"
6060
) {
6161
return "utf16le";
6262
}
6363
break;
6464
case 9:
6565
if (
6666
enc === "base64url" || enc === "BASE64URL" ||
67-
`${enc}`.toLowerCase() === "base64url"
67+
StringPrototypeToLowerCase(`${enc}`) === "base64url"
6868
) {
6969
return "base64url";
7070
}

0 commit comments

Comments
 (0)