mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 00:20:08 +01:00
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:
parent
ef2e0848ba
commit
5584cc5038
15
lib/fs.js
15
lib/fs.js
|
|
@ -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) {
|
||||
|
|
|
|||
16
test/parallel/test-fs-glob-throw.mjs
Normal file
16
test/parallel/test-fs-glob-throw.mjs
Normal 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');
|
||||
}));
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user