@@ -1197,26 +1197,33 @@ static void Open(const FunctionCallbackInfo<Value>& args) {
1197
1197
1198
1198
static void OpenFileHandle (const FunctionCallbackInfo<Value>& args) {
1199
1199
Environment* env = Environment::GetCurrent (args);
1200
- Local<Context> context = env->context ();
1201
1200
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 );
1205
1203
1206
1204
BufferValue path (env->isolate (), args[0 ]);
1207
1205
CHECK_NE (*path, nullptr );
1208
1206
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 ();
1211
1212
1212
1213
FSReqBase* req_wrap = GetReqWrap (env, args[3 ]);
1213
- if (req_wrap != nullptr ) {
1214
+ if (req_wrap != nullptr ) { // openFileHandle(path, flags, mode, req)
1214
1215
AsyncCall (env, req_wrap, args, " open" , UTF8, AfterOpenFileHandle,
1215
1216
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
+ }
1218
1225
HandleScope scope (env->isolate ());
1219
- FileHandle* fd = new FileHandle (env, SYNC_RESULT );
1226
+ FileHandle* fd = new FileHandle (env, result );
1220
1227
args.GetReturnValue ().Set (fd->object ());
1221
1228
}
1222
1229
}
0 commit comments