Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
src: remove GetValidateFd()
  • Loading branch information
pluris
pluris committed Oct 2, 2023
commit bba51b3995fa40c6d9f57d8c611a47b352427f5c
1 change: 1 addition & 0 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1303,6 +1303,7 @@ function fdatasync(fd, callback) {
* @returns {void}
*/
function fdatasyncSync(fd) {
fd = getValidatedFd(fd);
return binding.fdatasync(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 @@ -1521,8 +1503,8 @@ static void Fdatasync(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) { // fdatasync(fd, req)
FSReqBase* req_wrap_async = GetReqWrap(args, 1);
Expand Down