mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 12:20:27 +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,
|
ObjectDefineProperties,
|
||||||
ObjectDefineProperty,
|
ObjectDefineProperty,
|
||||||
Promise,
|
Promise,
|
||||||
|
PromisePrototypeThen,
|
||||||
PromiseResolve,
|
PromiseResolve,
|
||||||
ReflectApply,
|
ReflectApply,
|
||||||
SafeMap,
|
SafeMap,
|
||||||
|
|
@ -3171,15 +3172,11 @@ function glob(pattern, options, callback) {
|
||||||
callback = makeCallback(callback);
|
callback = makeCallback(callback);
|
||||||
|
|
||||||
const Glob = lazyGlob();
|
const Glob = lazyGlob();
|
||||||
// TODO: Use iterator helpers when available
|
PromisePrototypeThen(
|
||||||
(async () => {
|
ArrayFromAsync(new Glob(pattern, options).glob()),
|
||||||
try {
|
(res) => callback(null, res),
|
||||||
const res = await ArrayFromAsync(new Glob(pattern, options).glob());
|
callback,
|
||||||
callback(null, res);
|
);
|
||||||
} catch (err) {
|
|
||||||
callback(err);
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function globSync(pattern, options) {
|
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