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;