@@ -711,18 +711,24 @@ static void Rename(const FunctionCallbackInfo<Value>& args) {
711711static void FTruncate (const FunctionCallbackInfo<Value>& args) {
712712 Environment* env = Environment::GetCurrent (args);
713713
714+ const int argc = args.Length ();
715+ CHECK_GE (argc, 3 );
716+
714717 CHECK (args[0 ]->IsInt32 ());
715- CHECK ( args[1 ]-> IsNumber () );
718+ const int fd = args[0 ]. As <Int32>()-> Value ( );
716719
717- int fd = args[0 ]->Int32Value ( );
718- const int64_t len = args[1 ]-> IntegerValue ();
720+ CHECK ( args[1 ]->IsNumber () );
721+ const int64_t len = args[1 ]. As <Integer>()-> Value ();
719722
720- if (args[2 ]->IsObject ()) {
721- CHECK_EQ (args. Length () , 3 );
723+ if (args[2 ]->IsObject ()) { // ftruncate(fd, len, req)
724+ CHECK_EQ (argc , 3 );
722725 AsyncCall (env, args, " ftruncate" , UTF8, AfterNoArgs,
723726 uv_fs_ftruncate, fd, len);
724- } else {
725- SYNC_CALL (ftruncate, 0 , fd, len)
727+ } else { // ftruncate(fd, len, undefined, ctx)
728+ CHECK_EQ (argc, 4 );
729+ fs_req_wrap req_wrap;
730+ SyncCall (env, args[3 ], &req_wrap, " ftruncate" ,
731+ uv_fs_ftruncate, fd, len);
726732 }
727733}
728734
0 commit comments