From 3513127eb9d07f916f0ef691a31b01ad5cad632a Mon Sep 17 00:00:00 2001 From: pluris Date: Tue, 26 Sep 2023 19:25:53 +0900 Subject: [PATCH 1/9] fs: improve error performance for `fsyncSync` --- benchmark/fs/bench-fsyncSync.js | 42 +++++++++++++++++++++++++++++++++ lib/fs.js | 5 +--- src/node_file.cc | 20 ++++++++++++++++ 3 files changed, 63 insertions(+), 4 deletions(-) create mode 100644 benchmark/fs/bench-fsyncSync.js diff --git a/benchmark/fs/bench-fsyncSync.js b/benchmark/fs/bench-fsyncSync.js new file mode 100644 index 00000000000000..0346230b72a605 --- /dev/null +++ b/benchmark/fs/bench-fsyncSync.js @@ -0,0 +1,42 @@ +'use strict'; + +const common = require('../common'); +const fs = require('fs'); +const tmpdir = require('../../test/common/tmpdir'); +tmpdir.refresh(); + +const tmpfile = tmpdir.resolve(`.existing-file-${process.pid}`); +fs.writeFileSync(tmpfile, 'this-is-for-a-benchmark', 'utf8'); + +const bench = common.createBenchmark(main, { + type: ['existing', 'non-existing'], + n: [1e4], +}); + +function main({ n, type }) { + let fd; + + switch (type) { + case 'existing': + fd = fs.openSync(tmpfile, 'r', 0o666); + break; + case 'non-existing': + fd = 0; + break; + default: + new Error('Invalid type'); + } + + bench.start(); + for (let i = 0; i < n; i++) { + try { + fs.fsyncSync(fd); + } catch { + // do nothing + } + } + + if (fd !== 0) fs.closeSync(fd); + + bench.end(n); +} diff --git a/lib/fs.js b/lib/fs.js index d682759d8b0a14..4ca1051066a4e7 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -1330,10 +1330,7 @@ function fsync(fd, callback) { * @returns {void} */ function fsyncSync(fd) { - fd = getValidatedFd(fd); - const ctx = {}; - binding.fsync(fd, undefined, ctx); - handleErrorFromBinding(ctx); + syncFs.fsync(fd); } /** diff --git a/src/node_file.cc b/src/node_file.cc index 9430aff5c29a37..3e8ab32ace0869 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -1543,6 +1543,24 @@ static void Fsync(const FunctionCallbackInfo& args) { } } +static void FsyncSync(const FunctionCallbackInfo& args) { + Environment* env = Environment::GetCurrent(args); + + const int argc = args.Length(); + CHECK_GE(argc, 1); + + CHECK(args[0]->IsInt32()); + const int fd = args[0].As()->Value(); + + uv_fs_t req; + FS_SYNC_TRACE_BEGIN(fsync); + int err = uv_fs_fsync(nullptr, &req, fd, nullptr); + FS_SYNC_TRACE_END(fsync); + if (err < 0) { + return env->ThrowUVException(err, "fsync", nullptr); + } +} + static void Unlink(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); @@ -3219,6 +3237,7 @@ static void CreatePerIsolateProperties(IsolateData* isolate_data, SetMethod(isolate, target, "readBuffers", ReadBuffers); SetMethod(isolate, target, "fdatasync", Fdatasync); SetMethod(isolate, target, "fsync", Fsync); + SetMethod(isolate, target, "fsyncSync", FsyncSync); SetMethod(isolate, target, "rename", Rename); SetMethod(isolate, target, "ftruncate", FTruncate); SetMethod(isolate, target, "rmdir", RMDir); @@ -3338,6 +3357,7 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) { registry->Register(ReadBuffers); registry->Register(Fdatasync); registry->Register(Fsync); + registry->Register(FsyncSync); registry->Register(Rename); registry->Register(FTruncate); registry->Register(RMDir); From 427d566857d1b420fb98af2bee25ac40a1ca6cee Mon Sep 17 00:00:00 2001 From: pluris Date: Wed, 27 Sep 2023 01:00:26 +0900 Subject: [PATCH 2/9] fixup! fs: improve error performance for `fsyncSync` --- benchmark/fs/bench-fsyncSync.js | 6 +++--- src/node_file.cc | 4 +++- typings/internalBinding/fs.d.ts | 8 +++++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/benchmark/fs/bench-fsyncSync.js b/benchmark/fs/bench-fsyncSync.js index 0346230b72a605..fc7ef29266790b 100644 --- a/benchmark/fs/bench-fsyncSync.js +++ b/benchmark/fs/bench-fsyncSync.js @@ -21,7 +21,7 @@ function main({ n, type }) { fd = fs.openSync(tmpfile, 'r', 0o666); break; case 'non-existing': - fd = 0; + fd = 1 << 30; break; default: new Error('Invalid type'); @@ -36,7 +36,7 @@ function main({ n, type }) { } } - if (fd !== 0) fs.closeSync(fd); - bench.end(n); + + if (type === 'existing') fs.closeSync(fd); } diff --git a/src/node_file.cc b/src/node_file.cc index 3e8ab32ace0869..06a5d75f98e269 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -1550,14 +1550,16 @@ static void FsyncSync(const FunctionCallbackInfo& args) { CHECK_GE(argc, 1); CHECK(args[0]->IsInt32()); + const int fd = args[0].As()->Value(); + CHECK_GE(fd, 0); uv_fs_t req; FS_SYNC_TRACE_BEGIN(fsync); int err = uv_fs_fsync(nullptr, &req, fd, nullptr); FS_SYNC_TRACE_END(fsync); if (err < 0) { - return env->ThrowUVException(err, "fsync", nullptr); + return env->ThrowUVException(err, "fsync"); } } diff --git a/typings/internalBinding/fs.d.ts b/typings/internalBinding/fs.d.ts index d87b326e42efc8..a4ea9987cd8198 100644 --- a/typings/internalBinding/fs.d.ts +++ b/typings/internalBinding/fs.d.ts @@ -94,10 +94,11 @@ declare namespace InternalFSBinding { function fstat(fd: number, useBigint: boolean, usePromises: typeof kUsePromises): Promise; function fstat(fd: number, useBigint: true, usePromises: typeof kUsePromises): Promise; function fstat(fd: number, useBigint: false, usePromises: typeof kUsePromises): Promise; + function fsync(fd: number): void; - function fsync(fd: number, req: FSReqCallback): void; - function fsync(fd: number, req: undefined, ctx: FSSyncContext): void; - function fsync(fd: number, usePromises: typeof kUsePromises): Promise; + function fsyncSync(fd: number, req: FSReqCallback): void; + function fsyncSync(fd: number, req: undefined, ctx: FSSyncContext): void; + function fsyncSync(fd: number, usePromises: typeof kUsePromises): Promise; function ftruncate(fd: number, len: number, req: FSReqCallback): void; function ftruncate(fd: number, len: number, req: undefined, ctx: FSSyncContext): void; @@ -243,6 +244,7 @@ export interface FsBinding { fdatasync: typeof InternalFSBinding.fdatasync; fstat: typeof InternalFSBinding.fstat; fsync: typeof InternalFSBinding.fsync; + fsyncSync: typeof InternalFSBinding.fsyncSync; ftruncate: typeof InternalFSBinding.ftruncate; futimes: typeof InternalFSBinding.futimes; internalModuleReadJSON: typeof InternalFSBinding.internalModuleReadJSON; From ec070f7cf3648e55e3a0b7302eb65bd6e8dfd3c7 Mon Sep 17 00:00:00 2001 From: pluris Date: Wed, 27 Sep 2023 01:16:18 +0900 Subject: [PATCH 3/9] fixup! fs: improve error performance fori `fsyncSync` --- typings/internalBinding/fs.d.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/typings/internalBinding/fs.d.ts b/typings/internalBinding/fs.d.ts index a4ea9987cd8198..9e91a72ea5794d 100644 --- a/typings/internalBinding/fs.d.ts +++ b/typings/internalBinding/fs.d.ts @@ -94,11 +94,11 @@ declare namespace InternalFSBinding { function fstat(fd: number, useBigint: boolean, usePromises: typeof kUsePromises): Promise; function fstat(fd: number, useBigint: true, usePromises: typeof kUsePromises): Promise; function fstat(fd: number, useBigint: false, usePromises: typeof kUsePromises): Promise; - function fsync(fd: number): void; - function fsyncSync(fd: number, req: FSReqCallback): void; - function fsyncSync(fd: number, req: undefined, ctx: FSSyncContext): void; - function fsyncSync(fd: number, usePromises: typeof kUsePromises): Promise; + function fsync(fd: number, req: FSReqCallback): void; + function fsync(fd: number, req: undefined, ctx: FSSyncContext): void; + function fsync(fd: number, usePromises: typeof kUsePromises): Promise; + function fsyncSync(fd: number): void; function ftruncate(fd: number, len: number, req: FSReqCallback): void; function ftruncate(fd: number, len: number, req: undefined, ctx: FSSyncContext): void; From aafb8313e786f0a47a467a44a26a4c38c685b5cc Mon Sep 17 00:00:00 2001 From: pluris Date: Wed, 27 Sep 2023 16:48:34 +0900 Subject: [PATCH 4/9] src: add `getValidateFd()` to `node_file` --- lib/internal/fs/sync.js | 111 ++++++++++++++++++++++++++++++++++++++++ src/node_file.cc | 24 +++++++-- 2 files changed, 131 insertions(+), 4 deletions(-) create mode 100644 lib/internal/fs/sync.js diff --git a/lib/internal/fs/sync.js b/lib/internal/fs/sync.js new file mode 100644 index 00000000000000..46ac2fbe58f0d6 --- /dev/null +++ b/lib/internal/fs/sync.js @@ -0,0 +1,111 @@ +'use strict'; + +const pathModule = require('path'); +const { + getValidatedPath, + stringToFlags, + getValidMode, + getStatsFromBinding, + getStatFsFromBinding, + getValidatedFd, +} = require('internal/fs/utils'); +const { parseFileMode, isInt32 } = require('internal/validators'); + +const binding = internalBinding('fs'); + +/** + * @param {string} path + * @param {number} flag + * @return {string} + */ +function readFileUtf8(path, flag) { + if (!isInt32(path)) { + path = pathModule.toNamespacedPath(getValidatedPath(path)); + } + return binding.readFileUtf8(path, stringToFlags(flag)); +} + +function exists(path) { + try { + path = getValidatedPath(path); + } catch { + return false; + } + + return binding.existsSync(pathModule.toNamespacedPath(path)); +} + +function access(path, mode) { + path = getValidatedPath(path); + mode = getValidMode(mode, 'access'); + + binding.accessSync(pathModule.toNamespacedPath(path), mode); +} + +function copyFile(src, dest, mode) { + src = getValidatedPath(src, 'src'); + dest = getValidatedPath(dest, 'dest'); + + binding.copyFileSync( + pathModule.toNamespacedPath(src), + pathModule.toNamespacedPath(dest), + getValidMode(mode, 'copyFile'), + ); +} + +function stat(path, options = { bigint: false, throwIfNoEntry: true }) { + path = getValidatedPath(path); + const stats = binding.statSync( + pathModule.toNamespacedPath(path), + options.bigint, + options.throwIfNoEntry, + ); + if (stats === undefined) { + return undefined; + } + return getStatsFromBinding(stats); +} + +function statfs(path, options = { bigint: false }) { + path = getValidatedPath(path); + const stats = binding.statfsSync(pathModule.toNamespacedPath(path), options.bigint); + return getStatFsFromBinding(stats); +} + +function open(path, flags, mode) { + path = getValidatedPath(path); + + return binding.openSync( + pathModule.toNamespacedPath(path), + stringToFlags(flags), + parseFileMode(mode, 'mode', 0o666), + ); +} + +function close(fd) { + fd = getValidatedFd(fd); + + return binding.closeSync(fd); +} + +function unlink(path) { + path = pathModule.toNamespacedPath(getValidatedPath(path)); + return binding.unlinkSync(path); +} + +function fsync(fd) { + return binding.fsyncSync(fd); +} + +module.exports = { + readFileUtf8, + exists, + access, + copyFile, + stat, + statfs, + open, + close, + unlink, + fsync, +}; diff --git a/src/node_file.cc b/src/node_file.cc index 06a5d75f98e269..3f973d14822356 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -116,6 +116,24 @@ inline int64_t GetOffset(Local value) { return IsSafeJsInt(value) ? value.As()->Value() : -1; } +inline int GetValidatedFd(Environment* env, Local value) { + if (!value->IsInt32()) { + env->isolate()->ThrowException(ERR_INVALID_ARG_TYPE( + env->isolate(), "Invalid argument. The fd must be int32.")); + return 1 << 30; + } + + const int fd = value.As()->Value(); + + if (fd < 0 || fd > INT32_MAX) { + env->isolate()->ThrowException(ERR_OUT_OF_RANGE( + env->isolate(), "It must be >= 0 && <= INT32_MAX. Received %d", fd)); + return 1 << 30; + } + + return fd; +} + static const char* get_fs_func_name_by_type(uv_fs_type req_type) { switch (req_type) { #define FS_TYPE_TO_NAME(type, name) \ @@ -1549,10 +1567,8 @@ static void FsyncSync(const FunctionCallbackInfo& args) { const int argc = args.Length(); CHECK_GE(argc, 1); - CHECK(args[0]->IsInt32()); - - const int fd = args[0].As()->Value(); - CHECK_GE(fd, 0); + const int fd = GetValidatedFd(env, args[0]); + if (fd == (1 << 30)) return; uv_fs_t req; FS_SYNC_TRACE_BEGIN(fsync); From 94b638c14b95bb3a90b4863404778d3e999ef58b Mon Sep 17 00:00:00 2001 From: pluris Date: Wed, 27 Sep 2023 23:11:06 +0900 Subject: [PATCH 5/9] src: modify CHECK_GE to CHECK_EQ --- src/node_file.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/node_file.cc b/src/node_file.cc index 3f973d14822356..d97f0e40a415c8 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -1564,8 +1564,7 @@ static void Fsync(const FunctionCallbackInfo& args) { static void FsyncSync(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); - const int argc = args.Length(); - CHECK_GE(argc, 1); + CHECK_EQ(args.Length(), 1); const int fd = GetValidatedFd(env, args[0]); if (fd == (1 << 30)) return; From f7de22f19616e329c07dbb1fb19ae105743f757e Mon Sep 17 00:00:00 2001 From: pluris Date: Thu, 28 Sep 2023 00:26:52 +0900 Subject: [PATCH 6/9] src: add missing OnScopeLeave --- lib/internal/fs/sync.js | 111 ---------------------------------------- src/node_file.cc | 1 + 2 files changed, 1 insertion(+), 111 deletions(-) delete mode 100644 lib/internal/fs/sync.js diff --git a/lib/internal/fs/sync.js b/lib/internal/fs/sync.js deleted file mode 100644 index 46ac2fbe58f0d6..00000000000000 --- a/lib/internal/fs/sync.js +++ /dev/null @@ -1,111 +0,0 @@ -'use strict'; - -const pathModule = require('path'); -const { - getValidatedPath, - stringToFlags, - getValidMode, - getStatsFromBinding, - getStatFsFromBinding, - getValidatedFd, -} = require('internal/fs/utils'); -const { parseFileMode, isInt32 } = require('internal/validators'); - -const binding = internalBinding('fs'); - -/** - * @param {string} path - * @param {number} flag - * @return {string} - */ -function readFileUtf8(path, flag) { - if (!isInt32(path)) { - path = pathModule.toNamespacedPath(getValidatedPath(path)); - } - return binding.readFileUtf8(path, stringToFlags(flag)); -} - -function exists(path) { - try { - path = getValidatedPath(path); - } catch { - return false; - } - - return binding.existsSync(pathModule.toNamespacedPath(path)); -} - -function access(path, mode) { - path = getValidatedPath(path); - mode = getValidMode(mode, 'access'); - - binding.accessSync(pathModule.toNamespacedPath(path), mode); -} - -function copyFile(src, dest, mode) { - src = getValidatedPath(src, 'src'); - dest = getValidatedPath(dest, 'dest'); - - binding.copyFileSync( - pathModule.toNamespacedPath(src), - pathModule.toNamespacedPath(dest), - getValidMode(mode, 'copyFile'), - ); -} - -function stat(path, options = { bigint: false, throwIfNoEntry: true }) { - path = getValidatedPath(path); - const stats = binding.statSync( - pathModule.toNamespacedPath(path), - options.bigint, - options.throwIfNoEntry, - ); - if (stats === undefined) { - return undefined; - } - return getStatsFromBinding(stats); -} - -function statfs(path, options = { bigint: false }) { - path = getValidatedPath(path); - const stats = binding.statfsSync(pathModule.toNamespacedPath(path), options.bigint); - return getStatFsFromBinding(stats); -} - -function open(path, flags, mode) { - path = getValidatedPath(path); - - return binding.openSync( - pathModule.toNamespacedPath(path), - stringToFlags(flags), - parseFileMode(mode, 'mode', 0o666), - ); -} - -function close(fd) { - fd = getValidatedFd(fd); - - return binding.closeSync(fd); -} - -function unlink(path) { - path = pathModule.toNamespacedPath(getValidatedPath(path)); - return binding.unlinkSync(path); -} - -function fsync(fd) { - return binding.fsyncSync(fd); -} - -module.exports = { - readFileUtf8, - exists, - access, - copyFile, - stat, - statfs, - open, - close, - unlink, - fsync, -}; diff --git a/src/node_file.cc b/src/node_file.cc index d97f0e40a415c8..f6a14a7b594ae1 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -1570,6 +1570,7 @@ static void FsyncSync(const FunctionCallbackInfo& args) { if (fd == (1 << 30)) return; uv_fs_t req; + auto make = OnScopeLeave([&req]() { uv_fs_req_cleanup(&req); }); FS_SYNC_TRACE_BEGIN(fsync); int err = uv_fs_fsync(nullptr, &req, fd, nullptr); FS_SYNC_TRACE_END(fsync); From 0828da3f03d945e8cd90d6a8056dbfab3193f05c Mon Sep 17 00:00:00 2001 From: pluris Date: Mon, 2 Oct 2023 01:34:19 +0900 Subject: [PATCH 7/9] apply #49913 --- lib/fs.js | 2 +- src/node_file.cc | 36 ++++++++------------------------- typings/internalBinding/fs.d.ts | 2 +- 3 files changed, 10 insertions(+), 30 deletions(-) diff --git a/lib/fs.js b/lib/fs.js index 4ca1051066a4e7..44ac1e4e7bb4fb 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -1330,7 +1330,7 @@ function fsync(fd, callback) { * @returns {void} */ function fsyncSync(fd) { - syncFs.fsync(fd); + return binding.fsync(fd); } /** diff --git a/src/node_file.cc b/src/node_file.cc index f6a14a7b594ae1..41e872ad6cb8d0 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -1542,43 +1542,25 @@ static void Fsync(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); const int argc = args.Length(); - CHECK_GE(argc, 2); + CHECK_GE(argc, 1); - CHECK(args[0]->IsInt32()); - const int fd = args[0].As()->Value(); + const int fd = GetValidatedFd(env, args[0]); + if (fd == (1 << 30)) return; - FSReqBase* req_wrap_async = GetReqWrap(args, 1); - if (req_wrap_async != nullptr) { + if (argc > 1) { + FSReqBase* req_wrap_async = GetReqWrap(args, 1); + CHECK_NOT_NULL(req_wrap_async); FS_ASYNC_TRACE_BEGIN0(UV_FS_FSYNC, req_wrap_async) AsyncCall(env, req_wrap_async, args, "fsync", UTF8, AfterNoArgs, uv_fs_fsync, fd); } else { - CHECK_EQ(argc, 3); - FSReqWrapSync req_wrap_sync; + FSReqWrapSync req_wrap_sync("fsync"); FS_SYNC_TRACE_BEGIN(fsync); - SyncCall(env, args[2], &req_wrap_sync, "fsync", uv_fs_fsync, fd); + SyncCallAndThrowOnError(env, &req_wrap_sync, uv_fs_fsync, fd); FS_SYNC_TRACE_END(fsync); } } -static void FsyncSync(const FunctionCallbackInfo& args) { - Environment* env = Environment::GetCurrent(args); - - CHECK_EQ(args.Length(), 1); - - const int fd = GetValidatedFd(env, args[0]); - if (fd == (1 << 30)) return; - - uv_fs_t req; - auto make = OnScopeLeave([&req]() { uv_fs_req_cleanup(&req); }); - FS_SYNC_TRACE_BEGIN(fsync); - int err = uv_fs_fsync(nullptr, &req, fd, nullptr); - FS_SYNC_TRACE_END(fsync); - if (err < 0) { - return env->ThrowUVException(err, "fsync"); - } -} - static void Unlink(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); @@ -3255,7 +3237,6 @@ static void CreatePerIsolateProperties(IsolateData* isolate_data, SetMethod(isolate, target, "readBuffers", ReadBuffers); SetMethod(isolate, target, "fdatasync", Fdatasync); SetMethod(isolate, target, "fsync", Fsync); - SetMethod(isolate, target, "fsyncSync", FsyncSync); SetMethod(isolate, target, "rename", Rename); SetMethod(isolate, target, "ftruncate", FTruncate); SetMethod(isolate, target, "rmdir", RMDir); @@ -3375,7 +3356,6 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) { registry->Register(ReadBuffers); registry->Register(Fdatasync); registry->Register(Fsync); - registry->Register(FsyncSync); registry->Register(Rename); registry->Register(FTruncate); registry->Register(RMDir); diff --git a/typings/internalBinding/fs.d.ts b/typings/internalBinding/fs.d.ts index 9e91a72ea5794d..2ec220ac796774 100644 --- a/typings/internalBinding/fs.d.ts +++ b/typings/internalBinding/fs.d.ts @@ -98,7 +98,7 @@ declare namespace InternalFSBinding { function fsync(fd: number, req: FSReqCallback): void; function fsync(fd: number, req: undefined, ctx: FSSyncContext): void; function fsync(fd: number, usePromises: typeof kUsePromises): Promise; - function fsyncSync(fd: number): void; + function fsync(fd: number): void; function ftruncate(fd: number, len: number, req: FSReqCallback): void; function ftruncate(fd: number, len: number, req: undefined, ctx: FSSyncContext): void; From fcffde8ea6d7ebe39a130c13ede7b4156d2ca177 Mon Sep 17 00:00:00 2001 From: pluris Date: Mon, 2 Oct 2023 22:52:23 +0900 Subject: [PATCH 8/9] src: remove `GetValidatedFd` --- lib/fs.js | 1 + src/node_file.cc | 22 ++-------------------- typings/internalBinding/fs.d.ts | 1 - 3 files changed, 3 insertions(+), 21 deletions(-) diff --git a/lib/fs.js b/lib/fs.js index 44ac1e4e7bb4fb..319a048b61bbae 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -1330,6 +1330,7 @@ function fsync(fd, callback) { * @returns {void} */ function fsyncSync(fd) { + fd = getValidatedFd(fd); return binding.fsync(fd); } diff --git a/src/node_file.cc b/src/node_file.cc index 41e872ad6cb8d0..9eb42b3a261f83 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -116,24 +116,6 @@ inline int64_t GetOffset(Local value) { return IsSafeJsInt(value) ? value.As()->Value() : -1; } -inline int GetValidatedFd(Environment* env, Local value) { - if (!value->IsInt32()) { - env->isolate()->ThrowException(ERR_INVALID_ARG_TYPE( - env->isolate(), "Invalid argument. The fd must be int32.")); - return 1 << 30; - } - - const int fd = value.As()->Value(); - - if (fd < 0 || fd > INT32_MAX) { - env->isolate()->ThrowException(ERR_OUT_OF_RANGE( - env->isolate(), "It must be >= 0 && <= INT32_MAX. Received %d", fd)); - return 1 << 30; - } - - return fd; -} - static const char* get_fs_func_name_by_type(uv_fs_type req_type) { switch (req_type) { #define FS_TYPE_TO_NAME(type, name) \ @@ -1544,8 +1526,8 @@ static void Fsync(const FunctionCallbackInfo& args) { const int argc = args.Length(); CHECK_GE(argc, 1); - const int fd = GetValidatedFd(env, args[0]); - if (fd == (1 << 30)) return; + CHECK(args[0]->IsInt32()); + const int fd = args[0].As()->Value(); if (argc > 1) { FSReqBase* req_wrap_async = GetReqWrap(args, 1); diff --git a/typings/internalBinding/fs.d.ts b/typings/internalBinding/fs.d.ts index 2ec220ac796774..2df8bed60d74db 100644 --- a/typings/internalBinding/fs.d.ts +++ b/typings/internalBinding/fs.d.ts @@ -244,7 +244,6 @@ export interface FsBinding { fdatasync: typeof InternalFSBinding.fdatasync; fstat: typeof InternalFSBinding.fstat; fsync: typeof InternalFSBinding.fsync; - fsyncSync: typeof InternalFSBinding.fsyncSync; ftruncate: typeof InternalFSBinding.ftruncate; futimes: typeof InternalFSBinding.futimes; internalModuleReadJSON: typeof InternalFSBinding.internalModuleReadJSON; From 6396e80ae2252b2aecadb2d4a803d53bb8c94a90 Mon Sep 17 00:00:00 2001 From: Jungku Lee Date: Wed, 4 Oct 2023 23:43:25 +0900 Subject: [PATCH 9/9] Update typings/internalBinding/fs.d.ts Co-authored-by: Joyee Cheung --- typings/internalBinding/fs.d.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/typings/internalBinding/fs.d.ts b/typings/internalBinding/fs.d.ts index 2df8bed60d74db..b001e15a9971a8 100644 --- a/typings/internalBinding/fs.d.ts +++ b/typings/internalBinding/fs.d.ts @@ -96,7 +96,6 @@ declare namespace InternalFSBinding { function fstat(fd: number, useBigint: false, usePromises: typeof kUsePromises): Promise; function fsync(fd: number, req: FSReqCallback): void; - function fsync(fd: number, req: undefined, ctx: FSSyncContext): void; function fsync(fd: number, usePromises: typeof kUsePromises): Promise; function fsync(fd: number): void;