@@ -1169,25 +1169,29 @@ static void ReadDir(const FunctionCallbackInfo<Value>& args) {
11691169
11701170static void Open (const FunctionCallbackInfo<Value>& args) {
11711171 Environment* env = Environment::GetCurrent (args);
1172- Local<Context> context = env->context ();
11731172
1174- CHECK_GE (args.Length (), 3 );
1175- CHECK (args[1 ]->IsInt32 ());
1176- CHECK (args[2 ]->IsInt32 ());
1173+ const int argc = args.Length ();
1174+ CHECK_GE (argc, 3 );
11771175
11781176 BufferValue path (env->isolate (), args[0 ]);
11791177 CHECK_NE (*path, nullptr );
11801178
1181- int flags = args[1 ]->Int32Value (context).ToChecked ();
1182- int mode = args[2 ]->Int32Value (context).ToChecked ();
1179+ CHECK (args[1 ]->IsInt32 ());
1180+ const int flags = args[1 ].As <Int32>()->Value ();
1181+
1182+ CHECK (args[2 ]->IsInt32 ());
1183+ const int mode = args[2 ].As <Int32>()->Value ();
11831184
11841185 FSReqBase* req_wrap = GetReqWrap (env, args[3 ]);
1185- if (req_wrap != nullptr ) {
1186+ if (req_wrap != nullptr ) { // open(path, flags, mode, req)
11861187 AsyncCall (env, req_wrap, args, " open" , UTF8, AfterInteger,
11871188 uv_fs_open, *path, flags, mode);
1188- } else {
1189- SYNC_CALL (open, *path, *path, flags, mode)
1190- args.GetReturnValue ().Set (SYNC_RESULT);
1189+ } else { // open(path, flags, mode, undefined, ctx)
1190+ CHECK_EQ (argc, 5 );
1191+ fs_req_wrap req_wrap;
1192+ int result = SyncCall (env, args[4 ], &req_wrap, " open" ,
1193+ uv_fs_open, *path, flags, mode);
1194+ args.GetReturnValue ().Set (result);
11911195 }
11921196}
11931197
0 commit comments