@@ -47,8 +47,6 @@ using v8::Value;
47
47
48
48
#define TYPE_ERROR (msg ) env->ThrowTypeError (msg)
49
49
50
- #define THROW_BAD_ARGS TYPE_ERROR (" Bad argument" )
51
-
52
50
#define GET_OFFSET (a ) ((a)->IsNumber () ? (a)->IntegerValue() : -1)
53
51
54
52
class FSReqWrap: public ReqWrap<uv_fs_t> {
@@ -306,7 +304,7 @@ static void Access(const FunctionCallbackInfo<Value>& args) {
306
304
HandleScope scope (env->isolate ());
307
305
308
306
if (args.Length () < 2 )
309
- return THROW_BAD_ARGS ;
307
+ return TYPE_ERROR ( " path and mode are required " ) ;
310
308
if (!args[0 ]->IsString ())
311
309
return TYPE_ERROR (" path must be a string" );
312
310
if (!args[1 ]->IsInt32 ())
@@ -326,9 +324,10 @@ static void Access(const FunctionCallbackInfo<Value>& args) {
326
324
static void Close (const FunctionCallbackInfo<Value>& args) {
327
325
Environment* env = Environment::GetCurrent (args);
328
326
329
- if (args.Length () < 1 || !args[0 ]->IsInt32 ()) {
330
- return THROW_BAD_ARGS;
331
- }
327
+ if (args.Length () < 1 )
328
+ return TYPE_ERROR (" fd is required" );
329
+ if (!args[0 ]->IsInt32 ())
330
+ return TYPE_ERROR (" fd must be a file descriptor" );
332
331
333
332
int fd = args[0 ]->Int32Value ();
334
333
@@ -559,9 +558,10 @@ static void LStat(const FunctionCallbackInfo<Value>& args) {
559
558
static void FStat (const FunctionCallbackInfo<Value>& args) {
560
559
Environment* env = Environment::GetCurrent (args);
561
560
562
- if (args.Length () < 1 || !args[0 ]->IsInt32 ()) {
563
- return THROW_BAD_ARGS;
564
- }
561
+ if (args.Length () < 1 )
562
+ return TYPE_ERROR (" fd is required" );
563
+ if (!args[0 ]->IsInt32 ())
564
+ return TYPE_ERROR (" fd must be a file descriptor" );
565
565
566
566
int fd = args[0 ]->Int32Value ();
567
567
@@ -678,9 +678,10 @@ static void Rename(const FunctionCallbackInfo<Value>& args) {
678
678
static void FTruncate (const FunctionCallbackInfo<Value>& args) {
679
679
Environment* env = Environment::GetCurrent (args);
680
680
681
- if (args.Length () < 2 || !args[0 ]->IsInt32 ()) {
682
- return THROW_BAD_ARGS;
683
- }
681
+ if (args.Length () < 2 )
682
+ return TYPE_ERROR (" fd and length are required" );
683
+ if (!args[0 ]->IsInt32 ())
684
+ return TYPE_ERROR (" fd must be a file descriptor" );
684
685
685
686
int fd = args[0 ]->Int32Value ();
686
687
@@ -706,9 +707,10 @@ static void FTruncate(const FunctionCallbackInfo<Value>& args) {
706
707
static void Fdatasync (const FunctionCallbackInfo<Value>& args) {
707
708
Environment* env = Environment::GetCurrent (args);
708
709
709
- if (args.Length () < 1 || !args[0 ]->IsInt32 ()) {
710
- return THROW_BAD_ARGS;
711
- }
710
+ if (args.Length () < 1 )
711
+ return TYPE_ERROR (" fd is required" );
712
+ if (!args[0 ]->IsInt32 ())
713
+ return TYPE_ERROR (" fd must be a file descriptor" );
712
714
713
715
int fd = args[0 ]->Int32Value ();
714
716
@@ -722,9 +724,10 @@ static void Fdatasync(const FunctionCallbackInfo<Value>& args) {
722
724
static void Fsync (const FunctionCallbackInfo<Value>& args) {
723
725
Environment* env = Environment::GetCurrent (args);
724
726
725
- if (args.Length () < 1 || !args[0 ]->IsInt32 ()) {
726
- return THROW_BAD_ARGS;
727
- }
727
+ if (args.Length () < 1 )
728
+ return TYPE_ERROR (" fd is required" );
729
+ if (!args[0 ]->IsInt32 ())
730
+ return TYPE_ERROR (" fd must be a file descriptor" );
728
731
729
732
int fd = args[0 ]->Int32Value ();
730
733
@@ -772,9 +775,12 @@ static void RMDir(const FunctionCallbackInfo<Value>& args) {
772
775
static void MKDir (const FunctionCallbackInfo<Value>& args) {
773
776
Environment* env = Environment::GetCurrent (args);
774
777
775
- if (args.Length () < 2 || !args[0 ]->IsString () || !args[1 ]->IsInt32 ()) {
776
- return THROW_BAD_ARGS;
777
- }
778
+ if (args.Length () < 2 )
779
+ return TYPE_ERROR (" path and mode are required" );
780
+ if (!args[0 ]->IsString ())
781
+ return TYPE_ERROR (" path must be a string" );
782
+ if (!args[1 ]->IsInt32 ())
783
+ return TYPE_ERROR (" mode must be an integer" );
778
784
779
785
node::Utf8Value path (env->isolate (), args[0 ]);
780
786
int mode = static_cast <int >(args[1 ]->Int32Value ());
@@ -990,9 +996,12 @@ static void WriteString(const FunctionCallbackInfo<Value>& args) {
990
996
static void Read (const FunctionCallbackInfo<Value>& args) {
991
997
Environment* env = Environment::GetCurrent (args);
992
998
993
- if (args.Length () < 2 || !args[0 ]->IsInt32 ()) {
994
- return THROW_BAD_ARGS;
995
- }
999
+ if (args.Length () < 2 )
1000
+ return TYPE_ERROR (" fd and buffer are required" );
1001
+ if (!args[0 ]->IsInt32 ())
1002
+ return TYPE_ERROR (" fd must be a file descriptor" );
1003
+ if (!Buffer::HasInstance (args[1 ]))
1004
+ return TYPE_ERROR (" Second argument needs to be a buffer" );
996
1005
997
1006
int fd = args[0 ]->Int32Value ();
998
1007
@@ -1003,10 +1012,6 @@ static void Read(const FunctionCallbackInfo<Value>& args) {
1003
1012
1004
1013
char * buf = nullptr ;
1005
1014
1006
- if (!Buffer::HasInstance (args[1 ])) {
1007
- return env->ThrowError (" Second argument needs to be a buffer" );
1008
- }
1009
-
1010
1015
Local<Object> buffer_obj = args[1 ]->ToObject (env->isolate ());
1011
1016
char *buffer_data = Buffer::Data (buffer_obj);
1012
1017
size_t buffer_length = Buffer::Length (buffer_obj);
@@ -1043,9 +1048,13 @@ static void Read(const FunctionCallbackInfo<Value>& args) {
1043
1048
static void Chmod (const FunctionCallbackInfo<Value>& args) {
1044
1049
Environment* env = Environment::GetCurrent (args);
1045
1050
1046
- if (args.Length () < 2 || !args[0 ]->IsString () || !args[1 ]->IsInt32 ()) {
1047
- return THROW_BAD_ARGS;
1048
- }
1051
+ if (args.Length () < 2 )
1052
+ return TYPE_ERROR (" path and mode are required" );
1053
+ if (!args[0 ]->IsString ())
1054
+ return TYPE_ERROR (" path must be a string" );
1055
+ if (!args[1 ]->IsInt32 ())
1056
+ return TYPE_ERROR (" mode must be an integer" );
1057
+
1049
1058
node::Utf8Value path (env->isolate (), args[0 ]);
1050
1059
int mode = static_cast <int >(args[1 ]->Int32Value ());
1051
1060
@@ -1063,9 +1072,13 @@ static void Chmod(const FunctionCallbackInfo<Value>& args) {
1063
1072
static void FChmod (const FunctionCallbackInfo<Value>& args) {
1064
1073
Environment* env = Environment::GetCurrent (args);
1065
1074
1066
- if (args.Length () < 2 || !args[0 ]->IsInt32 () || !args[1 ]->IsInt32 ()) {
1067
- return THROW_BAD_ARGS;
1068
- }
1075
+ if (args.Length () < 2 )
1076
+ return TYPE_ERROR (" fd and mode are required" );
1077
+ if (!args[0 ]->IsInt32 ())
1078
+ return TYPE_ERROR (" fd must be a file descriptor" );
1079
+ if (!args[1 ]->IsInt32 ())
1080
+ return TYPE_ERROR (" mode must be an integer" );
1081
+
1069
1082
int fd = args[0 ]->Int32Value ();
1070
1083
int mode = static_cast <int >(args[1 ]->Int32Value ());
1071
1084
0 commit comments