@@ -1169,25 +1169,29 @@ static void ReadDir(const FunctionCallbackInfo<Value>& args) {
1169
1169
1170
1170
static void Open (const FunctionCallbackInfo<Value>& args) {
1171
1171
Environment* env = Environment::GetCurrent (args);
1172
- Local<Context> context = env->context ();
1173
1172
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 );
1177
1175
1178
1176
BufferValue path (env->isolate (), args[0 ]);
1179
1177
CHECK_NE (*path, nullptr );
1180
1178
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 ();
1183
1184
1184
1185
FSReqBase* req_wrap = GetReqWrap (env, args[3 ]);
1185
- if (req_wrap != nullptr ) {
1186
+ if (req_wrap != nullptr ) { // open(path, flags, mode, req)
1186
1187
AsyncCall (env, req_wrap, args, " open" , UTF8, AfterInteger,
1187
1188
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);
1191
1195
}
1192
1196
}
1193
1197
0 commit comments