Repository: denoland/deno
Pull request: fix(ext/node): use primordials in `ext/node/polyfills/internal/normalize_encoding.mjs`

Towards #24236. Replaces the `.toLowerCase` method with its equivalent primordial method.

<!--
Before submitting a PR, please read https://docs.deno.com/runtime/manual/references/contributing

1. Give the PR a descriptive title.

  Examples of good title:
    - fix(std/http): Fix race condition in server
    - docs(console): Update docstrings
    - feat(doc): Handle nested reexports

  Examples of bad title:
    - fix #7123
    - update docs
    - fix bugs

2. Ensure there is a related issue and it is referenced in the PR text.
3. Ensure there are tests that cover the changes.
4. Ensure `cargo test` passes.
5. Ensure `./tools/format.js` passes without changing files.
6. Ensure `./tools/lint.js` passes.
7. Open as a draft PR if your work is still in progress. The CI won't run
   all steps, but you can add '[ci]' to a commit message to force it to.
8. If you would like to run the benchmarks on the CI, add the 'ci-bench' label.
-->


Changed files:
filename: ext/node/polyfills/internal/normalize_encoding.mjs
patch: @@ -1,7 +1,7 @@
 // Copyright 2018-2025 the Deno authors. MIT license.
 
-// TODO(petamoriken): enable prefer-primordials for node polyfills
-// deno-lint-ignore-file prefer-primordials
+import { primordials } from "ext:core/mod.js";
+const { StringPrototypeToLowerCase } = primordials;
 
 export function normalizeEncoding(enc) {
   if (enc == null || enc === "utf8" || enc === "utf-8") return "utf8";
@@ -13,14 +13,14 @@ export function slowCases(enc) {
     case 4:
       if (enc === "UTF8") return "utf8";
       if (enc === "ucs2" || enc === "UCS2") return "utf16le";
-      enc = `${enc}`.toLowerCase();
+      enc = StringPrototypeToLowerCase(`${enc}`);
       if (enc === "utf8") return "utf8";
       if (enc === "ucs2") return "utf16le";
       break;
     case 3:
       if (
         enc === "hex" || enc === "HEX" ||
-        `${enc}`.toLowerCase() === "hex"
+        StringPrototypeToLowerCase(`${enc}`) === "hex"
       ) {
         return "hex";
       }
@@ -31,7 +31,7 @@ export function slowCases(enc) {
       if (enc === "UTF-8") return "utf8";
       if (enc === "ASCII") return "ascii";
       if (enc === "UCS-2") return "utf16le";
-      enc = `${enc}`.toLowerCase();
+      enc = StringPrototypeToLowerCase(`${enc}`);
       if (enc === "utf-8") return "utf8";
       if (enc === "ascii") return "ascii";
       if (enc === "ucs-2") return "utf16le";
@@ -41,30 +41,30 @@ export function slowCases(enc) {
       if (enc === "latin1" || enc === "binary") return "latin1";
       if (enc === "BASE64") return "base64";
       if (enc === "LATIN1" || enc === "BINARY") return "latin1";
-      enc = `${enc}`.toLowerCase();
+      enc = StringPrototypeToLowerCase(`${enc}`);
       if (enc === "base64") return "base64";
       if (enc === "latin1" || enc === "binary") return "latin1";
       break;
     case 7:
       if (
         enc === "utf16le" || enc === "UTF16LE" ||
-        `${enc}`.toLowerCase() === "utf16le"
+        StringPrototypeToLowerCase(`${enc}`) === "utf16le"
       ) {
         return "utf16le";
       }
       break;
     case 8:
       if (
         enc === "utf-16le" || enc === "UTF-16LE" ||
-        `${enc}`.toLowerCase() === "utf-16le"
+        StringPrototypeToLowerCase(`${enc}`) === "utf-16le"
       ) {
         return "utf16le";
       }
       break;
     case 9:
       if (
         enc === "base64url" || enc === "BASE64URL" ||
-        `${enc}`.toLowerCase() === "base64url"
+        StringPrototypeToLowerCase(`${enc}`) === "base64url"
       ) {
         return "base64url";
       }