mirror of
https://github.com/denoland/deno.git
synced 2025-09-27 04:39:10 +00:00
fix(ext/node): validate fs.close
callback function (#30679)
Towards #29972 Allows the [parallel/test-fs-close-errors.js](https://github.com/nodejs/node/blob/v24.2.0/test/parallel/test-fs-close-errors.js) test to pass, and also addresses the `prefer-primordials` lint rule #24236
This commit is contained in:
parent
c6adba1228
commit
9c871d0a57
1 changed files with 15 additions and 6 deletions
|
@ -1,14 +1,21 @@
|
||||||
// Copyright 2018-2025 the Deno authors. MIT license.
|
// Copyright 2018-2025 the Deno authors. MIT license.
|
||||||
|
|
||||||
// TODO(petamoriken): enable prefer-primordials for node polyfills
|
import {
|
||||||
// deno-lint-ignore-file prefer-primordials
|
type CallbackWithError,
|
||||||
|
makeCallback,
|
||||||
import type { CallbackWithError } from "ext:deno_node/_fs/_fs_common.ts";
|
} from "ext:deno_node/_fs/_fs_common.ts";
|
||||||
import { getValidatedFd } from "ext:deno_node/internal/fs/utils.mjs";
|
import { getValidatedFd } from "ext:deno_node/internal/fs/utils.mjs";
|
||||||
import { core } from "ext:core/mod.js";
|
import { core, primordials } from "ext:core/mod.js";
|
||||||
|
|
||||||
|
const {
|
||||||
|
Error,
|
||||||
|
ErrorPrototype,
|
||||||
|
ObjectPrototypeIsPrototypeOf,
|
||||||
|
} = primordials;
|
||||||
|
|
||||||
export function close(fd: number, callback: CallbackWithError) {
|
export function close(fd: number, callback: CallbackWithError) {
|
||||||
fd = getValidatedFd(fd);
|
fd = getValidatedFd(fd);
|
||||||
|
callback = makeCallback(callback);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
let error = null;
|
let error = null;
|
||||||
try {
|
try {
|
||||||
|
@ -16,7 +23,9 @@ export function close(fd: number, callback: CallbackWithError) {
|
||||||
// implementation detail and may change.
|
// implementation detail and may change.
|
||||||
core.close(fd);
|
core.close(fd);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
error = err instanceof Error ? err : new Error("[non-error thrown]");
|
error = ObjectPrototypeIsPrototypeOf(ErrorPrototype, err)
|
||||||
|
? err as Error
|
||||||
|
: new Error("[non-error thrown]");
|
||||||
}
|
}
|
||||||
callback(error);
|
callback(error);
|
||||||
}, 0);
|
}, 0);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue