Skip to content

Commit

Permalink
src: remove GetValidatedFd
Browse files Browse the repository at this point in the history
  • Loading branch information
pluris committed Oct 2, 2023
1 parent 0828da3 commit fcffde8
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 21 deletions.
1 change: 1 addition & 0 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1330,6 +1330,7 @@ function fsync(fd, callback) {
* @returns {void}
*/
function fsyncSync(fd) {
fd = getValidatedFd(fd);
return binding.fsync(fd);
}

Expand Down
22 changes: 2 additions & 20 deletions src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,24 +116,6 @@ inline int64_t GetOffset(Local<Value> value) {
return IsSafeJsInt(value) ? value.As<Integer>()->Value() : -1;
}

inline int GetValidatedFd(Environment* env, Local<Value> 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<Int32>()->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) \
Expand Down Expand Up @@ -1544,8 +1526,8 @@ static void Fsync(const FunctionCallbackInfo<Value>& 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<Int32>()->Value();

if (argc > 1) {
FSReqBase* req_wrap_async = GetReqWrap(args, 1);
Expand Down
1 change: 0 additions & 1 deletion typings/internalBinding/fs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit fcffde8

Please sign in to comment.