From b778a4fe46b0481b332424a49e084073a9ec4e6e Mon Sep 17 00:00:00 2001 From: theanarkh Date: Fri, 29 Nov 2024 00:26:17 +0800 Subject: [PATCH] src: fix check fd MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/56000 Fixes: https://github.com/nodejs/node/issues/55983 Reviewed-By: Yagiz Nizipli Reviewed-By: Antoine du Hamel Reviewed-By: Jason Zhang Reviewed-By: Juan José Arboleda --- src/util.cc | 10 ++++++++++ test/parallel/test-fs-stat.js | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/src/util.cc b/src/util.cc index a372eb4d88ca1d..8bf239db6e47d4 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 46874086d58dc7..b9d42b5b61bc83 100644 --- a/test/parallel/test-fs-stat.js +++ b/test/parallel/test-fs-stat.js @@ -212,3 +212,12 @@ fs.lstat(__filename, undefined, common.mustCall()); assert.strictEqual(s.birthtime, 5); })); } + +{ + assert.throws( + () => fs.fstat(Symbol('test'), () => {}), + { + code: 'ERR_INVALID_ARG_TYPE', + }, + ); +}