From 7555918a46415e53d28553bfcca6138d4800d453 Mon Sep 17 00:00:00 2001 From: James Bronder <36022278+jbronder@users.noreply.github.com> Date: Fri, 2 May 2025 17:23:36 -0700 Subject: [PATCH] fix(ext/node): use primordials in `ext/node/polyfills/internal/url.ts` --- ext/node/polyfills/internal/url.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/ext/node/polyfills/internal/url.ts b/ext/node/polyfills/internal/url.ts index 82d7a8b4bf1ab3..9e0df9c3c9822c 100644 --- a/ext/node/polyfills/internal/url.ts +++ b/ext/node/polyfills/internal/url.ts @@ -1,17 +1,23 @@ // Copyright 2018-2025 the Deno authors. MIT license. -// TODO(petamoriken): enable prefer-primordials for node polyfills -// deno-lint-ignore-file prefer-primordials - import { fileURLToPath } from "node:url"; import { Buffer } from "node:buffer"; +import { primordials } from "ext:core/mod.js"; +const { + Number, + ObjectPrototypeIsPrototypeOf, + StringPrototypeSlice, + StringPrototypeStartsWith, + Symbol, + decodeURIComponent, +} = primordials; const searchParams = Symbol("query"); export function toPathIfFileURL( fileURLOrPath: string | Buffer | URL, ): string | Buffer { - if (!(fileURLOrPath instanceof URL)) { + if (!(ObjectPrototypeIsPrototypeOf(URL.prototype, fileURLOrPath))) { return fileURLOrPath; } return fileURLToPath(fileURLOrPath); @@ -26,8 +32,8 @@ export function urlToHttpOptions(url: any): any { const options: any = { protocol: url.protocol, hostname: typeof url.hostname === "string" && - url.hostname.startsWith("[") - ? url.hostname.slice(1, -1) + StringPrototypeStartsWith(url.hostname, "[") + ? StringPrototypeSlice(url.hostname, 1, -1) : url.hostname, hash: url.hash, search: url.search,