@@ -66,6 +66,7 @@ using v8::HandleScope;
66
66
using v8::Int32;
67
67
using v8::Integer;
68
68
using v8::Isolate;
69
+ using v8::Just;
69
70
using v8::JustVoid;
70
71
using v8::Local;
71
72
using v8::Maybe;
@@ -89,6 +90,10 @@ constexpr char kPathSeparator = '/';
89
90
const char * const kPathSeparator = " \\ /" ;
90
91
#endif
91
92
93
+ #ifdef _WIN32
94
+ #include " uv.h"
95
+ #endif
96
+
92
97
// The access modes can be any of F_OK, R_OK, W_OK or X_OK. Some might not be
93
98
// available on specific systems. They can be used in combination as well
94
99
// (F_OK | R_OK | W_OK | X_OK).
@@ -872,41 +877,39 @@ void FromNamespacedPath(std::string* path) {
872
877
#endif
873
878
}
874
879
875
- static inline int GetValidMode (Environment* env,
876
- Local<Value> mode_v,
877
- std::string_view type) {
880
+ static inline Maybe< int > GetValidMode (Environment* env,
881
+ Local<Value> mode_v,
882
+ uv_fs_type type) {
878
883
if (!mode_v->IsInt32 () && !mode_v->IsNullOrUndefined ()) {
879
884
THROW_ERR_INVALID_ARG_TYPE (env, " mode must be int32 or null/undefined" );
880
- return - 1 ;
885
+ return Nothing< int >() ;
881
886
}
882
887
883
888
int min = kMinimumAccessMode ;
884
889
int max = kMaximumAccessMode ;
885
890
int def = F_OK;
886
891
887
- if (type == " copyFile" ) {
892
+ CHECK (type == UV_FS_ACCESS || type == UV_FS_COPYFILE);
893
+
894
+ if (type == UV_FS_COPYFILE) {
888
895
min = kMinimumCopyMode ;
889
896
max = kMaximumCopyMode ;
890
897
def = mode_v->IsNullOrUndefined () ? kDefaultCopyMode
891
898
: mode_v.As <Int32>()->Value ();
892
- } else if (type != " access" ) {
893
- THROW_ERR_INVALID_ARG_TYPE (
894
- env, " type must be equal to \" copyFile\" or \" access\" " );
895
- return -1 ;
896
899
}
897
900
898
901
if (mode_v->IsNullOrUndefined ()) {
899
- return def;
902
+ return Just ( def) ;
900
903
}
901
904
902
905
const int mode = mode_v.As <Int32>()->Value ();
903
906
if (mode < min || mode > max) {
904
907
THROW_ERR_OUT_OF_RANGE (
905
908
env, " mode is out of range: >= %d && <= %d" , min, max);
906
- return - 1 ;
909
+ return Nothing< int >() ;
907
910
}
908
911
909
- return mode;
912
+ return Just ( mode) ;
910
913
}
911
914
912
915
void AfterMkdirp (uv_fs_t * req) {
@@ -1028,8 +1031,8 @@ void Access(const FunctionCallbackInfo<Value>& args) {
1028
1031
const int argc = args.Length ();
1029
1032
CHECK_GE (argc, 2 );
1030
1033
1031
- int mode = GetValidMode (env, args[1 ], " access " );
1032
- if (mode == - 1 ) return ;
1034
+ Maybe< int > mode = GetValidMode (env, args[1 ], UV_FS_ACCESS );
1035
+ if (mode. IsNothing () ) return ;
1033
1036
1034
1037
BufferValue path (isolate, args[0 ]);
1035
1038
CHECK_NOT_NULL (*path);
@@ -1041,12 +1044,20 @@ void Access(const FunctionCallbackInfo<Value>& args) {
1041
1044
CHECK_NOT_NULL (req_wrap_async);
1042
1045
FS_ASYNC_TRACE_BEGIN1 (
1043
1046
UV_FS_ACCESS, req_wrap_async, " path" , TRACE_STR_COPY (*path))
1044
- AsyncCall (env, req_wrap_async, args, " access" , UTF8, AfterNoArgs,
1045
- uv_fs_access, *path, mode);
1047
+ AsyncCall (env,
1048
+ req_wrap_async,
1049
+ args,
1050
+ " access" ,
1051
+ UTF8,
1052
+ AfterNoArgs,
1053
+ uv_fs_access,
1054
+ *path,
1055
+ mode.FromJust ());
1046
1056
} else { // access(path, mode)
1047
1057
FSReqWrapSync req_wrap_sync (" access" , *path);
1048
1058
FS_SYNC_TRACE_BEGIN (access );
1049
- SyncCallAndThrowOnError (env, &req_wrap_sync, uv_fs_access, *path, mode);
1059
+ SyncCallAndThrowOnError (
1060
+ env, &req_wrap_sync, uv_fs_access, *path, mode.FromJust ());
1050
1061
FS_SYNC_TRACE_END (access );
1051
1062
}
1052
1063
}
@@ -2141,8 +2152,8 @@ static void CopyFile(const FunctionCallbackInfo<Value>& args) {
2141
2152
const int argc = args.Length ();
2142
2153
CHECK_GE (argc, 3 );
2143
2154
2144
- const int flags = GetValidMode (env, args[2 ], " copyFile " );
2145
- if (flags == - 1 ) return ;
2155
+ Maybe< int > flags = GetValidMode (env, args[2 ], UV_FS_COPYFILE );
2156
+ if (flags. IsNothing () ) return ;
2146
2157
2147
2158
BufferValue src (isolate, args[0 ]);
2148
2159
CHECK_NOT_NULL (*src);
@@ -2162,14 +2173,23 @@ static void CopyFile(const FunctionCallbackInfo<Value>& args) {
2162
2173
TRACE_STR_COPY (*src),
2163
2174
" dest" ,
2164
2175
TRACE_STR_COPY (*dest))
2165
- AsyncDestCall (env, req_wrap_async, args, " copyfile" ,
2166
- *dest, dest.length (), UTF8, AfterNoArgs,
2167
- uv_fs_copyfile, *src, *dest, flags);
2176
+ AsyncDestCall (env,
2177
+ req_wrap_async,
2178
+ args,
2179
+ " copyfile" ,
2180
+ *dest,
2181
+ dest.length (),
2182
+ UTF8,
2183
+ AfterNoArgs,
2184
+ uv_fs_copyfile,
2185
+ *src,
2186
+ *dest,
2187
+ flags.FromJust ());
2168
2188
} else { // copyFile(src, dest, flags)
2169
2189
FSReqWrapSync req_wrap_sync (" copyfile" , *src, *dest);
2170
2190
FS_SYNC_TRACE_BEGIN (copyfile);
2171
2191
SyncCallAndThrowOnError (
2172
- env, &req_wrap_sync, uv_fs_copyfile, *src, *dest, flags);
2192
+ env, &req_wrap_sync, uv_fs_copyfile, *src, *dest, flags. FromJust () );
2173
2193
FS_SYNC_TRACE_END (copyfile);
2174
2194
}
2175
2195
}
0 commit comments