From fe6738aec0be913c08b8c56df2d04f25c59a2a47 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 34263cc9f3dc06..3e9dfb4392fb3e 100644 --- a/src/util.cc +++ b/src/util.cc @@ -760,6 +760,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', + }, + ); +}