Skip to content

Commit 5584cc5

Browse files
committed
fs: remove IIFE in glob
PR-URL: #58418 Refs: #58419 Reviewed-By: Zeyu "Alex" Yang <[email protected]> Reviewed-By: Ethan Arrowood <[email protected]>
1 parent ef2e084 commit 5584cc5

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

lib/fs.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const {
3434
ObjectDefineProperties,
3535
ObjectDefineProperty,
3636
Promise,
37+
PromisePrototypeThen,
3738
PromiseResolve,
3839
ReflectApply,
3940
SafeMap,
@@ -3171,15 +3172,11 @@ function glob(pattern, options, callback) {
31713172
callback = makeCallback(callback);
31723173

31733174
const Glob = lazyGlob();
3174-
// TODO: Use iterator helpers when available
3175-
(async () => {
3176-
try {
3177-
const res = await ArrayFromAsync(new Glob(pattern, options).glob());
3178-
callback(null, res);
3179-
} catch (err) {
3180-
callback(err);
3181-
}
3182-
})();
3175+
PromisePrototypeThen(
3176+
ArrayFromAsync(new Glob(pattern, options).glob()),
3177+
(res) => callback(null, res),
3178+
callback,
3179+
);
31833180
}
31843181

31853182
function globSync(pattern, options) {

test/parallel/test-fs-glob-throw.mjs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { mustCall } from '../common/index.mjs';
2+
import { glob } from 'node:fs';
3+
import process from 'node:process';
4+
import { strictEqual } from 'node:assert';
5+
6+
// One uncaught error is expected
7+
process.on('uncaughtException', mustCall((err) => {
8+
strictEqual(err.message, 'blep');
9+
}));
10+
11+
{
12+
// Test that if callback throws, it's not getting called again
13+
glob('a/b/c', mustCall(() => {
14+
throw new Error('blep');
15+
}));
16+
}

0 commit comments

Comments
 (0)