Skip to content

Commit fcffde8

Browse files
author
pluris
committed
src: remove GetValidatedFd
1 parent 0828da3 commit fcffde8

File tree

3 files changed

+3
-21
lines changed

3 files changed

+3
-21
lines changed

lib/fs.js

+1
Original file line numberDiff line numberDiff line change
@@ -1330,6 +1330,7 @@ function fsync(fd, callback) {
13301330
* @returns {void}
13311331
*/
13321332
function fsyncSync(fd) {
1333+
fd = getValidatedFd(fd);
13331334
return binding.fsync(fd);
13341335
}
13351336

src/node_file.cc

+2-20
Original file line numberDiff line numberDiff line change
@@ -116,24 +116,6 @@ inline int64_t GetOffset(Local<Value> value) {
116116
return IsSafeJsInt(value) ? value.As<Integer>()->Value() : -1;
117117
}
118118

119-
inline int GetValidatedFd(Environment* env, Local<Value> value) {
120-
if (!value->IsInt32()) {
121-
env->isolate()->ThrowException(ERR_INVALID_ARG_TYPE(
122-
env->isolate(), "Invalid argument. The fd must be int32."));
123-
return 1 << 30;
124-
}
125-
126-
const int fd = value.As<Int32>()->Value();
127-
128-
if (fd < 0 || fd > INT32_MAX) {
129-
env->isolate()->ThrowException(ERR_OUT_OF_RANGE(
130-
env->isolate(), "It must be >= 0 && <= INT32_MAX. Received %d", fd));
131-
return 1 << 30;
132-
}
133-
134-
return fd;
135-
}
136-
137119
static const char* get_fs_func_name_by_type(uv_fs_type req_type) {
138120
switch (req_type) {
139121
#define FS_TYPE_TO_NAME(type, name) \
@@ -1544,8 +1526,8 @@ static void Fsync(const FunctionCallbackInfo<Value>& args) {
15441526
const int argc = args.Length();
15451527
CHECK_GE(argc, 1);
15461528

1547-
const int fd = GetValidatedFd(env, args[0]);
1548-
if (fd == (1 << 30)) return;
1529+
CHECK(args[0]->IsInt32());
1530+
const int fd = args[0].As<Int32>()->Value();
15491531

15501532
if (argc > 1) {
15511533
FSReqBase* req_wrap_async = GetReqWrap(args, 1);

typings/internalBinding/fs.d.ts

-1
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,6 @@ export interface FsBinding {
244244
fdatasync: typeof InternalFSBinding.fdatasync;
245245
fstat: typeof InternalFSBinding.fstat;
246246
fsync: typeof InternalFSBinding.fsync;
247-
fsyncSync: typeof InternalFSBinding.fsyncSync;
248247
ftruncate: typeof InternalFSBinding.ftruncate;
249248
futimes: typeof InternalFSBinding.futimes;
250249
internalModuleReadJSON: typeof InternalFSBinding.internalModuleReadJSON;

0 commit comments

Comments
 (0)