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 cfd9354
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 20 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

0 comments on commit cfd9354

Please sign in to comment.