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

Towards #24236. Replaces JS builtins with equivalent primordials.

<!--
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/tls.ts
patch: @@ -1,9 +1,6 @@
 // Copyright 2018-2026 the Deno authors. MIT license.
 // Copyright Joyent and Node contributors. All rights reserved. MIT license.
 
-// TODO(petamoriken): enable prefer-primordials for node polyfills
-// deno-lint-ignore-file prefer-primordials
-
 import { notImplemented } from "ext:deno_node/_utils.ts";
 import tlsCommon from "node:_tls_common";
 import tlsWrap from "node:_tls_wrap";
@@ -13,7 +10,25 @@ import {
 } from "ext:core/ops";
 import { primordials } from "ext:core/mod.js";
 
-const { ObjectFreeze } = primordials;
+const {
+  ArrayIsArray,
+  ArrayPrototypeForEach,
+  ArrayPrototypePush,
+  ObjectKeys,
+  ObjectFreeze,
+  Proxy,
+  ReflectDefineProperty,
+  ReflectDeleteProperty,
+  ReflectGet,
+  ReflectGetOwnPropertyDescriptor,
+  ReflectHas,
+  ReflectIsExtensible,
+  ReflectOwnKeys,
+  ReflectPreventExtensions,
+  ReflectSet,
+  StringPrototypeToLowerCase,
+  TypeError,
+} = primordials;
 
 // openssl -> rustls
 const cipherMap = {
@@ -34,7 +49,10 @@ const cipherMap = {
 
 export function getCiphers() {
   // TODO(bnoordhuis) Use locale-insensitive toLowerCase()
-  return Object.keys(cipherMap).map((name) => name.toLowerCase());
+  return ArrayPrototypeMap(
+    ObjectKeys(cipherMap),
+    (name) => StringPrototypeToLowerCase(name),
+  );
 }
 
 let lazyRootCertificates: string[] | null = null;
@@ -43,7 +61,10 @@ function ensureLazyRootCertificates(target: string[]) {
     lazyRootCertificates = op_get_root_certificates() as string[];
     // Clear target and repopulate
     target.length = 0;
-    lazyRootCertificates.forEach((v) => target.push(v));
+    ArrayPrototypeForEach(
+      lazyRootCertificates,
+      (v) => ArrayPrototypePush(target, v),
+    );
     ObjectFreeze(target);
   }
 }
@@ -52,39 +73,39 @@ export const rootCertificates = new Proxy([] as string[], {
   __proto__: null,
   get(target, prop) {
     ensureLazyRootCertificates(target);
-    return Reflect.get(target, prop);
+    return ReflectGet(target, prop);
   },
   ownKeys(target) {
     ensureLazyRootCertificates(target);
-    return Reflect.ownKeys(target);
+    return ReflectOwnKeys(target);
   },
   has(target, prop) {
     ensureLazyRootCertificates(target);
-    return Reflect.has(target, prop);
+    return ReflectHas(target, prop);
   },
   getOwnPropertyDescriptor(target, prop) {
     ensureLazyRootCertificates(target);
-    return Reflect.getOwnPropertyDescriptor(target, prop);
+    return ReflectGetOwnPropertyDescriptor(target, prop);
   },
   set(target, prop, value) {
     ensureLazyRootCertificates(target);
-    return Reflect.set(target, prop, value);
+    return ReflectSet(target, prop, value);
   },
   defineProperty(target, prop, descriptor) {
     ensureLazyRootCertificates(target);
-    return Reflect.defineProperty(target, prop, descriptor);
+    return ReflectDefineProperty(target, prop, descriptor);
   },
   deleteProperty(target, prop) {
     ensureLazyRootCertificates(target);
-    return Reflect.deleteProperty(target, prop);
+    return ReflectDeleteProperty(target, prop);
   },
   isExtensible(target) {
     ensureLazyRootCertificates(target);
-    return Reflect.isExtensible(target);
+    return ReflectIsExtensible(target);
   },
   preventExtensions(target) {
     ensureLazyRootCertificates(target);
-    return Reflect.preventExtensions(target);
+    return ReflectPreventExtensions(target);
   },
   setPrototypeOf() {
     return false;
@@ -102,13 +123,14 @@ export class SecurePair {}
 export const Server = tlsWrap.Server;
 
 export function setDefaultCACertificates(certs: string[]) {
-  if (!Array.isArray(certs)) {
+  if (!ArrayIsArray(certs)) {
     throw new TypeError(
       "The argument 'certs' must be an array of strings",
     );
   }
 
-  for (const cert of certs) {
+  for (let i = 0; i < certs.length; ++i) {
+    const cert = certs[i];
     if (typeof cert !== "string") {
       throw new TypeError(
         "Each certificate in 'certs' must be a string",