summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2018-02-20 04:23:47 +0800
committerJoyee Cheung <joyeec9h3@gmail.com>2018-02-27 20:34:10 +0800
commit82523d3b6eb7905fc59f12a0d38026af996152fa (patch)
tree0c0090c4833cc5ce0e4cee2115c501160ef3e239 /src
parent8fb5a6cd81a893dc4929a290206ac0b10c068487 (diff)
downloadandroid-node-v8-82523d3b6eb7905fc59f12a0d38026af996152fa.tar.gz
android-node-v8-82523d3b6eb7905fc59f12a0d38026af996152fa.tar.bz2
android-node-v8-82523d3b6eb7905fc59f12a0d38026af996152fa.zip
fs: throw fs.utimesSync errors in JS land
PR-URL: https://github.com/nodejs/node/pull/18871 Refs: https://github.com/nodejs/node/issues/18106 Reviewed-By: Michaƫl Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'src')
-rw-r--r--src/node_file.cc21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/node_file.cc b/src/node_file.cc
index 6e23846d47..3152d2067c 100644
--- a/src/node_file.cc
+++ b/src/node_file.cc
@@ -1561,22 +1561,27 @@ static void FChown(const FunctionCallbackInfo<Value>& args) {
static void UTimes(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
- CHECK_GE(args.Length(), 3);
- CHECK(args[1]->IsNumber());
- CHECK(args[2]->IsNumber());
+ const int argc = args.Length();
+ CHECK_GE(argc, 3);
BufferValue path(env->isolate(), args[0]);
CHECK_NE(*path, nullptr);
- const double atime = static_cast<double>(args[1]->NumberValue());
- const double mtime = static_cast<double>(args[2]->NumberValue());
+ CHECK(args[1]->IsNumber());
+ const double atime = args[1].As<Number>()->Value();
+
+ CHECK(args[2]->IsNumber());
+ const double mtime = args[2].As<Number>()->Value();
FSReqBase* req_wrap = GetReqWrap(env, args[3]);
- if (req_wrap != nullptr) {
+ if (req_wrap != nullptr) { // utimes(path, atime, mtime, req)
AsyncCall(env, req_wrap, args, "utime", UTF8, AfterNoArgs,
uv_fs_utime, *path, atime, mtime);
- } else {
- SYNC_CALL(utime, *path, *path, atime, mtime);
+ } else { // utimes(path, atime, mtime, undefined, ctx)
+ CHECK_EQ(argc, 5);
+ fs_req_wrap req_wrap;
+ SyncCall(env, args[4], &req_wrap, "utime",
+ uv_fs_utime, *path, atime, mtime);
}
}