Skip to content

Commit df7ddfc

Browse files
authored
fix(ext/node): use primordials in ext/node/polyfills/internal/url.ts (denoland#29146)
Towards denoland#24236.
1 parent 6395255 commit df7ddfc

File tree

1 file changed

+12
-6
lines changed
  • ext/node/polyfills/internal

1 file changed

+12
-6
lines changed

ext/node/polyfills/internal/url.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
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
5-
63
import { fileURLToPath } from "node:url";
74
import { Buffer } from "node:buffer";
5+
import { primordials } from "ext:core/mod.js";
6+
const {
7+
Number,
8+
ObjectPrototypeIsPrototypeOf,
9+
StringPrototypeSlice,
10+
StringPrototypeStartsWith,
11+
Symbol,
12+
decodeURIComponent,
13+
} = primordials;
814

915
const searchParams = Symbol("query");
1016

1117
export function toPathIfFileURL(
1218
fileURLOrPath: string | Buffer | URL,
1319
): string | Buffer {
14-
if (!(fileURLOrPath instanceof URL)) {
20+
if (!(ObjectPrototypeIsPrototypeOf(URL.prototype, fileURLOrPath))) {
1521
return fileURLOrPath;
1622
}
1723
return fileURLToPath(fileURLOrPath);
@@ -26,8 +32,8 @@ export function urlToHttpOptions(url: any): any {
2632
const options: any = {
2733
protocol: url.protocol,
2834
hostname: typeof url.hostname === "string" &&
29-
url.hostname.startsWith("[")
30-
? url.hostname.slice(1, -1)
35+
StringPrototypeStartsWith(url.hostname, "[")
36+
? StringPrototypeSlice(url.hostname, 1, -1)
3137
: url.hostname,
3238
hash: url.hash,
3339
search: url.search,

0 commit comments

Comments
 (0)