@@ -1197,26 +1197,33 @@ static void Open(const FunctionCallbackInfo<Value>& args) {
11971197
11981198static void OpenFileHandle (const FunctionCallbackInfo<Value>& args) {
11991199 Environment* env = Environment::GetCurrent (args);
1200- Local<Context> context = env->context ();
12011200
1202- CHECK_GE (args.Length (), 3 );
1203- CHECK (args[1 ]->IsInt32 ());
1204- CHECK (args[2 ]->IsInt32 ());
1201+ const int argc = args.Length ();
1202+ CHECK_GE (argc, 3 );
12051203
12061204 BufferValue path (env->isolate (), args[0 ]);
12071205 CHECK_NE (*path, nullptr );
12081206
1209- int flags = args[1 ]->Int32Value (context).ToChecked ();
1210- int mode = args[2 ]->Int32Value (context).ToChecked ();
1207+ CHECK (args[1 ]->IsInt32 ());
1208+ const int flags = args[1 ].As <Int32>()->Value ();
1209+
1210+ CHECK (args[2 ]->IsInt32 ());
1211+ const int mode = args[2 ].As <Int32>()->Value ();
12111212
12121213 FSReqBase* req_wrap = GetReqWrap (env, args[3 ]);
1213- if (req_wrap != nullptr ) {
1214+ if (req_wrap != nullptr ) { // openFileHandle(path, flags, mode, req)
12141215 AsyncCall (env, req_wrap, args, " open" , UTF8, AfterOpenFileHandle,
12151216 uv_fs_open, *path, flags, mode);
1216- } else {
1217- SYNC_CALL (open, *path, *path, flags, mode)
1217+ } else { // openFileHandle(path, flags, mode, undefined, ctx)
1218+ CHECK_EQ (argc, 5 );
1219+ fs_req_wrap req_wrap;
1220+ int result = SyncCall (env, args[4 ], &req_wrap, " open" ,
1221+ uv_fs_open, *path, flags, mode);
1222+ if (result < 0 ) {
1223+ return ; // syscall failed, no need to continue, error info is in ctx
1224+ }
12181225 HandleScope scope (env->isolate ());
1219- FileHandle* fd = new FileHandle (env, SYNC_RESULT );
1226+ FileHandle* fd = new FileHandle (env, result );
12201227 args.GetReturnValue ().Set (fd->object ());
12211228 }
12221229}
0 commit comments