fs: remove IIFE in glob

PR-URL: https://github.com/nodejs/node/pull/58418
Refs: https://github.com/nodejs/node/issues/58419
Reviewed-By: Zeyu "Alex" Yang <himself65@outlook.com>
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
This commit is contained in:
LiviaMedeiros 2025-05-21 20:49:42 +08:00
parent ef2e0848ba
commit 5584cc5038
No known key found for this signature in database
GPG Key ID: 691C0F6AF4A67582
2 changed files with 22 additions and 9 deletions

View File

@ -34,6 +34,7 @@ const {
ObjectDefineProperties,
ObjectDefineProperty,
Promise,
PromisePrototypeThen,
PromiseResolve,
ReflectApply,
SafeMap,
@ -3171,15 +3172,11 @@ function glob(pattern, options, callback) {
callback = makeCallback(callback);
const Glob = lazyGlob();
// TODO: Use iterator helpers when available
(async () => {
try {
const res = await ArrayFromAsync(new Glob(pattern, options).glob());
callback(null, res);
} catch (err) {
callback(err);
}
})();
PromisePrototypeThen(
ArrayFromAsync(new Glob(pattern, options).glob()),
(res) => callback(null, res),
callback,
);
}
function globSync(pattern, options) {

View File

@ -0,0 +1,16 @@
import { mustCall } from '../common/index.mjs';
import { glob } from 'node:fs';
import process from 'node:process';
import { strictEqual } from 'node:assert';
// One uncaught error is expected
process.on('uncaughtException', mustCall((err) => {
strictEqual(err.message, 'blep');
}));
{
// Test that if callback throws, it's not getting called again
glob('a/b/c', mustCall(() => {
throw new Error('blep');
}));
}