From 37b5cac78dae8a6503a07f062ea71f0071e743fa Mon Sep 17 00:00:00 2001 From: theanarkh Date: Tue, 26 Nov 2024 23:44:18 +0800 Subject: [PATCH] src: fix check fd --- src/util.cc | 10 ++++++++++ test/parallel/test-fs-stat.js | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/util.cc b/src/util.cc index a372eb4d88ca1da..8bf239db6e47d49 100644 --- a/src/util.cc +++ b/src/util.cc @@ -782,6 +782,16 @@ std::string DetermineSpecificErrorType(Environment* env, input.As()->GetConstructorName(); Utf8Value name(env->isolate(), constructor_name); return SPrintF("an instance of %s", name.out()); + } else if (input->IsSymbol()) { + v8::MaybeLocal str = + input.As()->ToDetailString(env->context()); + v8::Local js_str; + if (!str.ToLocal(&js_str)) { + return "Symbol"; + } + Utf8Value name(env->isolate(), js_str); + // Symbol(xxx) + return name.out(); } Utf8Value utf8_value(env->isolate(), diff --git a/test/parallel/test-fs-stat.js b/test/parallel/test-fs-stat.js index 46874086d58dc71..6af5b69b8cfaf92 100644 --- a/test/parallel/test-fs-stat.js +++ b/test/parallel/test-fs-stat.js @@ -212,3 +212,14 @@ fs.lstat(__filename, undefined, common.mustCall()); assert.strictEqual(s.birthtime, 5); })); } + +{ + assert.throws( + () => fs.fstat(Symbol("test"), () => {}), + { + code: 'ERR_INVALID_ARG_TYPE', + name: 'TypeError', + message: 'The "fd" argument must be of type number. Received Symbol(test)', + } + ); +}