@@ -87,6 +87,7 @@ using v8::Function;
87
87
using v8::FunctionCallbackInfo;
88
88
using v8::FunctionTemplate;
89
89
using v8::HandleScope;
90
+ using v8::Int32;
90
91
using v8::Integer;
91
92
using v8::Isolate;
92
93
using v8::Local;
@@ -351,14 +352,15 @@ inline FSReqWrap* AsyncCall(Environment* env,
351
352
// Template counterpart of SYNC_CALL, except that it only puts
352
353
// the error number and the syscall in the context instead of
353
354
// creating an error in the C++ land.
355
+ // ctx must be checked using value->IsObject() before being passed.
354
356
template <typename Func, typename ... Args>
355
357
inline int SyncCall (Environment* env, Local<Value> ctx, fs_req_wrap* req_wrap,
356
358
const char * syscall, Func fn, Args... args) {
357
359
env->PrintSyncTrace ();
358
360
int err = fn (env->event_loop (), &(req_wrap->req ), args..., nullptr );
359
361
if (err < 0 ) {
360
362
Local<Context> context = env->context ();
361
- Local<Object> ctx_obj = ctx-> ToObject (context). ToLocalChecked ();
363
+ Local<Object> ctx_obj = ctx. As <Object> ();
362
364
Isolate *isolate = env->isolate ();
363
365
ctx_obj->Set (context,
364
366
env->errno_string (),
@@ -391,19 +393,22 @@ inline int SyncCall(Environment* env, Local<Value> ctx, fs_req_wrap* req_wrap,
391
393
void Access (const FunctionCallbackInfo<Value>& args) {
392
394
Environment* env = Environment::GetCurrent (args.GetIsolate ());
393
395
HandleScope scope (env->isolate ());
394
- Local<Context> context = env->context ();
395
- CHECK_GE (args.Length (), 2 );
396
+
397
+ const int argc = args.Length ();
398
+ CHECK_GE (argc, 2 );
399
+
396
400
CHECK (args[1 ]->IsInt32 ());
401
+ int mode = args[1 ].As <Int32>()->Value ();
397
402
398
403
BufferValue path (env->isolate (), args[0 ]);
399
- int mode = static_cast < int >(args[ 1 ]-> Int32Value (context). FromJust () );
404
+ CHECK_NE (*path, nullptr );
400
405
401
406
if (args[2 ]->IsObject ()) { // access(path, mode, req)
402
- CHECK_EQ (args. Length () , 3 );
407
+ CHECK_EQ (argc , 3 );
403
408
AsyncCall (env, args, " access" , UTF8, AfterNoArgs,
404
409
uv_fs_access, *path, mode);
405
410
} else { // access(path, mode, undefined, ctx)
406
- CHECK_EQ (args. Length () , 4 );
411
+ CHECK_EQ (argc , 4 );
407
412
fs_req_wrap req_wrap;
408
413
SyncCall (env, args[3 ], &req_wrap, " access" , uv_fs_access, *path, mode);
409
414
}
@@ -412,20 +417,19 @@ void Access(const FunctionCallbackInfo<Value>& args) {
412
417
413
418
void Close (const FunctionCallbackInfo<Value>& args) {
414
419
Environment* env = Environment::GetCurrent (args);
415
- Local<Context> context = env->context ();
416
420
417
- int length = args.Length ();
418
- CHECK_GE (length, 2 );
419
- CHECK (args[0 ]->IsInt32 ());
421
+ const int argc = args.Length ();
422
+ CHECK_GE (argc, 2 );
420
423
421
- int fd = static_cast <int >(args[0 ]->Int32Value (context).FromJust ());
424
+ CHECK (args[0 ]->IsInt32 ());
425
+ int fd = args[0 ].As <Int32>()->Value ();
422
426
423
427
if (args[1 ]->IsObject ()) { // close(fd, req)
424
- CHECK_EQ (args. Length () , 2 );
428
+ CHECK_EQ (argc , 2 );
425
429
AsyncCall (env, args, " close" , UTF8, AfterNoArgs,
426
430
uv_fs_close, fd);
427
431
} else { // close(fd, undefined, ctx)
428
- CHECK_EQ (args. Length () , 3 );
432
+ CHECK_EQ (argc , 3 );
429
433
fs_req_wrap req_wrap;
430
434
SyncCall (env, args[2 ], &req_wrap, " close" , uv_fs_close, fd);
431
435
}
@@ -519,17 +523,18 @@ static void InternalModuleStat(const FunctionCallbackInfo<Value>& args) {
519
523
static void Stat (const FunctionCallbackInfo<Value>& args) {
520
524
Environment* env = Environment::GetCurrent (args);
521
525
522
- CHECK_GE (args.Length (), 1 );
526
+ const int argc = args.Length ();
527
+ CHECK_GE (argc, 1 );
523
528
524
529
BufferValue path (env->isolate (), args[0 ]);
525
530
CHECK_NE (*path, nullptr );
526
531
527
532
if (args[1 ]->IsObject ()) { // stat(path, req)
528
- CHECK_EQ (args. Length () , 2 );
533
+ CHECK_EQ (argc , 2 );
529
534
AsyncCall (env, args, " stat" , UTF8, AfterStat,
530
535
uv_fs_stat, *path);
531
536
} else { // stat(path, undefined, ctx)
532
- CHECK_EQ (args. Length () , 3 );
537
+ CHECK_EQ (argc , 3 );
533
538
fs_req_wrap req_wrap;
534
539
int err = SyncCall (env, args[2 ], &req_wrap, " stat" , uv_fs_stat, *path);
535
540
if (err == 0 ) {
@@ -542,17 +547,18 @@ static void Stat(const FunctionCallbackInfo<Value>& args) {
542
547
static void LStat (const FunctionCallbackInfo<Value>& args) {
543
548
Environment* env = Environment::GetCurrent (args);
544
549
545
- CHECK_GE (args.Length (), 1 );
550
+ const int argc = args.Length ();
551
+ CHECK_GE (argc, 1 );
546
552
547
553
BufferValue path (env->isolate (), args[0 ]);
548
554
CHECK_NE (*path, nullptr );
549
555
550
556
if (args[1 ]->IsObject ()) { // lstat(path, req)
551
- CHECK_EQ (args. Length () , 2 );
557
+ CHECK_EQ (argc , 2 );
552
558
AsyncCall (env, args, " lstat" , UTF8, AfterStat,
553
559
uv_fs_lstat, *path);
554
560
} else { // lstat(path, undefined, ctx)
555
- CHECK_EQ (args. Length () , 3 );
561
+ CHECK_EQ (argc , 3 );
556
562
fs_req_wrap req_wrap;
557
563
int err = SyncCall (env, args[2 ], &req_wrap, " lstat" , uv_fs_lstat, *path);
558
564
if (err == 0 ) {
@@ -564,18 +570,19 @@ static void LStat(const FunctionCallbackInfo<Value>& args) {
564
570
565
571
static void FStat (const FunctionCallbackInfo<Value>& args) {
566
572
Environment* env = Environment::GetCurrent (args);
567
- Local<Context> context = env->context ();
568
573
569
- CHECK (args[0 ]->IsInt32 ());
574
+ const int argc = args.Length ();
575
+ CHECK_GE (argc, 1 );
570
576
571
- int fd = static_cast <int >(args[0 ]->Int32Value (context).FromJust ());
577
+ CHECK (args[0 ]->IsInt32 ());
578
+ int fd = args[0 ].As <Int32>()->Value ();
572
579
573
580
if (args[1 ]->IsObject ()) { // fstat(fd, req)
574
- CHECK_EQ (args. Length () , 2 );
581
+ CHECK_EQ (argc , 2 );
575
582
AsyncCall (env, args, " fstat" , UTF8, AfterStat,
576
583
uv_fs_fstat, fd);
577
584
} else { // fstat(fd, undefined, ctx)
578
- CHECK_EQ (args. Length () , 3 );
585
+ CHECK_EQ (argc , 3 );
579
586
fs_req_wrap req_wrap;
580
587
int err = SyncCall (env, args[2 ], &req_wrap, " fstat" , uv_fs_fstat, fd);
581
588
if (err == 0 ) {
0 commit comments