summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2018-02-14 11:29:05 -0800
committerJoyee Cheung <joyeec9h3@gmail.com>2018-02-27 20:33:57 +0800
commite8ec898a7d8169bed73378b5cd4e677adbec16c8 (patch)
treecbc8627aab0a210ab1e243827d09ed9da15c1937 /src
parentfea5dda1d1ee4ebc2883fc9b4019c254176cc2c6 (diff)
downloadandroid-node-v8-e8ec898a7d8169bed73378b5cd4e677adbec16c8.tar.gz
android-node-v8-e8ec898a7d8169bed73378b5cd4e677adbec16c8.tar.bz2
android-node-v8-e8ec898a7d8169bed73378b5cd4e677adbec16c8.zip
fs: use SyncCall in OpenFileHandle
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.cc27
1 files changed, 17 insertions, 10 deletions
diff --git a/src/node_file.cc b/src/node_file.cc
index 8f9b71a238..5e8f9ee168 100644
--- a/src/node_file.cc
+++ b/src/node_file.cc
@@ -1197,26 +1197,33 @@ static void Open(const FunctionCallbackInfo<Value>& args) {
static void OpenFileHandle(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
- Local<Context> context = env->context();
- CHECK_GE(args.Length(), 3);
- CHECK(args[1]->IsInt32());
- CHECK(args[2]->IsInt32());
+ const int argc = args.Length();
+ CHECK_GE(argc, 3);
BufferValue path(env->isolate(), args[0]);
CHECK_NE(*path, nullptr);
- int flags = args[1]->Int32Value(context).ToChecked();
- int mode = args[2]->Int32Value(context).ToChecked();
+ CHECK(args[1]->IsInt32());
+ const int flags = args[1].As<Int32>()->Value();
+
+ CHECK(args[2]->IsInt32());
+ const int mode = args[2].As<Int32>()->Value();
FSReqBase* req_wrap = GetReqWrap(env, args[3]);
- if (req_wrap != nullptr) {
+ if (req_wrap != nullptr) { // openFileHandle(path, flags, mode, req)
AsyncCall(env, req_wrap, args, "open", UTF8, AfterOpenFileHandle,
uv_fs_open, *path, flags, mode);
- } else {
- SYNC_CALL(open, *path, *path, flags, mode)
+ } else { // openFileHandle(path, flags, mode, undefined, ctx)
+ CHECK_EQ(argc, 5);
+ fs_req_wrap req_wrap;
+ int result = SyncCall(env, args[4], &req_wrap, "open",
+ uv_fs_open, *path, flags, mode);
+ if (result < 0) {
+ return; // syscall failed, no need to continue, error info is in ctx
+ }
HandleScope scope(env->isolate());
- FileHandle* fd = new FileHandle(env, SYNC_RESULT);
+ FileHandle* fd = new FileHandle(env, result);
args.GetReturnValue().Set(fd->object());
}
}