27
27
namespace node {
28
28
29
29
using v8::Array;
30
+ using v8::ArrayBuffer;
30
31
using v8::Context;
31
32
using v8::EscapableHandleScope;
33
+ using v8::Float64Array;
32
34
using v8::Function;
33
35
using v8::FunctionCallbackInfo;
34
36
using v8::FunctionTemplate;
@@ -528,6 +530,37 @@ Local<Value> BuildStatsObject(Environment* env, const uv_stat_t* s) {
528
530
return handle_scope.Escape (stats);
529
531
}
530
532
533
+ void FillStatsArray (double * fields, const uv_stat_t * s) {
534
+ fields[0 ] = s->st_dev ;
535
+ fields[1 ] = s->st_mode ;
536
+ fields[2 ] = s->st_nlink ;
537
+ fields[3 ] = s->st_uid ;
538
+ fields[4 ] = s->st_gid ;
539
+ fields[5 ] = s->st_rdev ;
540
+ #if defined(__POSIX__)
541
+ fields[6 ] = s->st_blksize ;
542
+ #else
543
+ fields[6 ] = -1 ;
544
+ #endif
545
+ fields[7 ] = s->st_ino ;
546
+ fields[8 ] = s->st_size ;
547
+ #if defined(__POSIX__)
548
+ fields[9 ] = s->st_blocks ;
549
+ #else
550
+ fields[9 ] = -1 ;
551
+ #endif
552
+ // Dates.
553
+ #define X (idx, name ) \
554
+ fields[idx] = (static_cast <double >(s->st_ ##name.tv_sec ) * 1000 ) + \
555
+ (static_cast <double >(s->st_ ##name.tv_nsec / 1000000 )); \
556
+
557
+ X (10 , atim)
558
+ X (11 , mtim)
559
+ X (12 , ctim)
560
+ X (13 , birthtim)
561
+ #undef X
562
+ }
563
+
531
564
// Used to speed up module loading. Returns the contents of the file as
532
565
// a string or undefined when the file cannot be opened. The speedup
533
566
// comes from not creating Error objects on failure.
@@ -612,12 +645,15 @@ static void Stat(const FunctionCallbackInfo<Value>& args) {
612
645
BufferValue path (env->isolate (), args[0 ]);
613
646
ASSERT_PATH (path)
614
647
615
- if (args[1 ]->IsObject ()) {
616
- ASYNC_CALL (stat, args[1 ], UTF8, *path)
617
- } else {
648
+ if (args[1 ]->IsFloat64Array ()) {
649
+ Local<Float64Array> array = args[1 ].As <Float64Array>();
650
+ CHECK_EQ (array->Length (), 14 );
651
+ Local<ArrayBuffer> ab = array->Buffer ();
652
+ double * fields = static_cast <double *>(ab->GetContents ().Data ());
618
653
SYNC_CALL (stat, *path, *path)
619
- args.GetReturnValue ().Set (
620
- BuildStatsObject (env, static_cast <const uv_stat_t *>(SYNC_REQ.ptr )));
654
+ FillStatsArray (fields, static_cast <const uv_stat_t *>(SYNC_REQ.ptr ));
655
+ } else if (args[1 ]->IsObject ()) {
656
+ ASYNC_CALL (stat, args[1 ], UTF8, *path)
621
657
}
622
658
}
623
659
@@ -630,12 +666,15 @@ static void LStat(const FunctionCallbackInfo<Value>& args) {
630
666
BufferValue path (env->isolate (), args[0 ]);
631
667
ASSERT_PATH (path)
632
668
633
- if (args[1 ]->IsObject ()) {
634
- ASYNC_CALL (lstat, args[1 ], UTF8, *path)
635
- } else {
669
+ if (args[1 ]->IsFloat64Array ()) {
670
+ Local<Float64Array> array = args[1 ].As <Float64Array>();
671
+ CHECK_EQ (array->Length (), 14 );
672
+ Local<ArrayBuffer> ab = array->Buffer ();
673
+ double * fields = static_cast <double *>(ab->GetContents ().Data ());
636
674
SYNC_CALL (lstat, *path, *path)
637
- args.GetReturnValue ().Set (
638
- BuildStatsObject (env, static_cast <const uv_stat_t *>(SYNC_REQ.ptr )));
675
+ FillStatsArray (fields, static_cast <const uv_stat_t *>(SYNC_REQ.ptr ));
676
+ } else if (args[1 ]->IsObject ()) {
677
+ ASYNC_CALL (lstat, args[1 ], UTF8, *path)
639
678
}
640
679
}
641
680
@@ -649,12 +688,15 @@ static void FStat(const FunctionCallbackInfo<Value>& args) {
649
688
650
689
int fd = args[0 ]->Int32Value ();
651
690
652
- if (args[1 ]->IsObject ()) {
653
- ASYNC_CALL (fstat, args[1 ], UTF8, fd)
654
- } else {
691
+ if (args[1 ]->IsFloat64Array ()) {
692
+ Local<Float64Array> array = args[1 ].As <Float64Array>();
693
+ CHECK_EQ (array->Length (), 14 );
694
+ Local<ArrayBuffer> ab = array->Buffer ();
695
+ double * fields = static_cast <double *>(ab->GetContents ().Data ());
655
696
SYNC_CALL (fstat, 0 , fd)
656
- args.GetReturnValue ().Set (
657
- BuildStatsObject (env, static_cast <const uv_stat_t *>(SYNC_REQ.ptr )));
697
+ FillStatsArray (fields, static_cast <const uv_stat_t *>(SYNC_REQ.ptr ));
698
+ } else if (args[1 ]->IsObject ()) {
699
+ ASYNC_CALL (fstat, args[1 ], UTF8, fd)
658
700
}
659
701
}
660
702
0 commit comments