summaryrefslogtreecommitdiff
path: root/src/node_internals.h
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2018-03-31 04:02:57 +0800
committerJoyee Cheung <joyeec9h3@gmail.com>2018-04-04 15:25:59 +0800
commitf7049a20068dc8a7e904b7cdd3d5b307b595dd3a (patch)
tree2feea6b9e576299d541c2c57196ffc96399c2027 /src/node_internals.h
parent30fe55e248087664e91928794ef281fbf2ba8c8d (diff)
downloadandroid-node-v8-f7049a20068dc8a7e904b7cdd3d5b307b595dd3a.tar.gz
android-node-v8-f7049a20068dc8a7e904b7cdd3d5b307b595dd3a.tar.bz2
android-node-v8-f7049a20068dc8a7e904b7cdd3d5b307b595dd3a.zip
fs: refactor stats array to be more generic
- Pass kFsStatsFieldsLength between JS and C++ instead of using the magic number 14 - Pass the global stats array to the completion callback of asynchronous FSReqWrap similar to how the stats arrays are passed to the FSReqPromise resolvers - Abstract the stats converter and take an offset to compute the old stats in fs.watchFile - Use templates in node::FillStatsArray and FSReqPromise in preparation for BigInt intergration - Put the global stat array filler in node_internals.h because it is shared by node_file.cc and node_stat_watcher.cc PR-URL: https://github.com/nodejs/node/pull/19714 Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/node_internals.h')
-rw-r--r--src/node_internals.h44
1 files changed, 42 insertions, 2 deletions
diff --git a/src/node_internals.h b/src/node_internals.h
index 6439ccc7a2..8cc1aa1a8f 100644
--- a/src/node_internals.h
+++ b/src/node_internals.h
@@ -307,8 +307,48 @@ v8::Maybe<bool> ProcessEmitDeprecationWarning(Environment* env,
const char* warning,
const char* deprecation_code);
-void FillStatsArray(AliasedBuffer<double, v8::Float64Array>* fields_ptr,
- const uv_stat_t* s, int offset = 0);
+template <typename NativeT, typename V8T>
+void FillStatsArray(AliasedBuffer<NativeT, V8T>* fields_ptr,
+ const uv_stat_t* s, int offset = 0) {
+ AliasedBuffer<NativeT, V8T>& fields = *fields_ptr;
+ fields[offset + 0] = s->st_dev;
+ fields[offset + 1] = s->st_mode;
+ fields[offset + 2] = s->st_nlink;
+ fields[offset + 3] = s->st_uid;
+ fields[offset + 4] = s->st_gid;
+ fields[offset + 5] = s->st_rdev;
+#if defined(__POSIX__)
+ fields[offset + 6] = s->st_blksize;
+#else
+ fields[offset + 6] = -1;
+#endif
+ fields[offset + 7] = s->st_ino;
+ fields[offset + 8] = s->st_size;
+#if defined(__POSIX__)
+ fields[offset + 9] = s->st_blocks;
+#else
+ fields[offset + 9] = -1;
+#endif
+// Dates.
+// NO-LINT because the fields are 'long' and we just want to cast to `unsigned`
+#define X(idx, name) \
+ /* NOLINTNEXTLINE(runtime/int) */ \
+ fields[offset + idx] = ((unsigned long)(s->st_##name.tv_sec) * 1e3) + \
+ /* NOLINTNEXTLINE(runtime/int) */ \
+ ((unsigned long)(s->st_##name.tv_nsec) / 1e6); \
+
+ X(10, atim)
+ X(11, mtim)
+ X(12, ctim)
+ X(13, birthtim)
+#undef X
+}
+
+inline void FillGlobalStatsArray(Environment* env,
+ const uv_stat_t* s,
+ int offset = 0) {
+ node::FillStatsArray(env->fs_stats_field_array(), s, offset);
+}
void SetupProcessObject(Environment* env,
int argc,