Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ext/node): use primordials in ext/node/polyfills/_fs_common.ts #27589

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions ext/node/polyfills/_fs/_fs_common.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
// 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,
ArrayPrototypeIncludes,
ReflectApply,
Error,
} = primordials;
import {
O_APPEND,
O_CREAT,
Expand Down Expand Up @@ -85,8 +89,10 @@ export function getEncoding(
export function checkEncoding(encoding: Encodings | null): Encodings | null {
if (!encoding) return null;

encoding = encoding.toLowerCase() as Encodings;
if (["utf8", "hex", "base64", "ascii"].includes(encoding)) return encoding;
encoding = StringPrototypeToLowerCase(encoding) as Encodings;
if (ArrayPrototypeIncludes(["utf8", "hex", "base64", "ascii"], encoding)) {
return encoding;
}

if (encoding === "utf-8") {
return "utf8";
Expand All @@ -99,7 +105,7 @@ export function checkEncoding(encoding: Encodings | null): Encodings | null {

const notImplementedEncodings = ["utf16le", "latin1", "ucs2"];

if (notImplementedEncodings.includes(encoding as string)) {
if (ArrayPrototypeIncludes(notImplementedEncodings, encoding as string)) {
notImplemented(`"${encoding}" encoding`);
}

Expand Down Expand Up @@ -241,5 +247,5 @@ export function makeCallback(
) {
validateFunction(cb, "cb");

return (...args: unknown[]) => Reflect.apply(cb!, this, args);
return (...args: unknown[]) => ReflectApply(cb!, this, args);
}
Loading