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

Towards #24236. This PR replaces JS built-ins, `String` and `Array`, with the primordial versions.

<!--
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/idna.ts
patch: @@ -43,9 +43,6 @@
 
 // Adapted from https://github.com/mathiasbynens/punycode.js
 
-// TODO(petamoriken): enable prefer-primordials for node polyfills
-// deno-lint-ignore-file prefer-primordials
-
 // TODO(cmorten): migrate punycode logic to "icu" internal binding and/or "url"
 // internal module so there can be re-use within the "url" module etc.
 
@@ -55,6 +52,13 @@ import {
   op_node_idna_domain_to_ascii,
   op_node_idna_domain_to_unicode,
 } from "ext:core/ops";
+import { primordials } from "ext:core/mod.js";
+const {
+  ArrayPrototypePush,
+  SafeArrayIterator,
+  StringFromCodePoint,
+  StringPrototypeCharCodeAt,
+} = primordials;
 
 /**
  * Creates an array containing the numeric code points of each Unicode
@@ -72,22 +76,25 @@ function ucs2decode(str: string) {
   const length = str.length;
 
   while (counter < length) {
-    const value = str.charCodeAt(counter++);
+    const value = StringPrototypeCharCodeAt(str, counter++);
 
     if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
       // It's a high surrogate, and there is a next character.
-      const extra = str.charCodeAt(counter++);
+      const extra = StringPrototypeCharCodeAt(str, counter++);
 
       if ((extra & 0xFC00) == 0xDC00) { // Low surrogate.
-        output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
+        ArrayPrototypePush(
+          output,
+          ((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000,
+        );
       } else {
         // It's an unmatched surrogate; only append this code unit, in case the
         // next code unit is the high surrogate of a surrogate pair.
-        output.push(value);
+        ArrayPrototypePush(output, value);
         counter--;
       }
     } else {
-      output.push(value);
+      ArrayPrototypePush(output, value);
     }
   }
 
@@ -103,7 +110,7 @@ function ucs2decode(str: string) {
  * @returns The new Unicode string (UCS-2).
  */
 function ucs2encode(array: number[]) {
-  return String.fromCodePoint(...array);
+  return StringFromCodePoint(...new SafeArrayIterator(array));
 }
 
 export const ucs2 = {