OLD | NEW |
1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
524 return; | 524 return; |
525 } | 525 } |
526 | 526 |
527 args.GetReturnValue().Set(accumulator); | 527 args.GetReturnValue().Set(accumulator); |
528 } | 528 } |
529 | 529 |
530 | 530 |
531 void Shell::ChangeDirectory(const v8::FunctionCallbackInfo<v8::Value>& args) { | 531 void Shell::ChangeDirectory(const v8::FunctionCallbackInfo<v8::Value>& args) { |
532 if (args.Length() != 1) { | 532 if (args.Length() != 1) { |
533 const char* message = "chdir() takes one argument"; | 533 const char* message = "chdir() takes one argument"; |
534 ThrowException(String::New(message)); | 534 ThrowException(args.GetIsolate(), String::New(message)); |
535 return; | 535 return; |
536 } | 536 } |
537 String::Utf8Value directory(args[0]); | 537 String::Utf8Value directory(args[0]); |
538 if (*directory == NULL) { | 538 if (*directory == NULL) { |
539 const char* message = "os.chdir(): String conversion of argument failed."; | 539 const char* message = "os.chdir(): String conversion of argument failed."; |
540 ThrowException(String::New(message)); | 540 ThrowException(args.GetIsolate(), String::New(message)); |
541 return; | 541 return; |
542 } | 542 } |
543 if (chdir(*directory) != 0) { | 543 if (chdir(*directory) != 0) { |
544 ThrowException(String::New(strerror(errno))); | 544 ThrowException(args.GetIsolate(), String::New(strerror(errno))); |
545 return; | 545 return; |
546 } | 546 } |
547 } | 547 } |
548 | 548 |
549 | 549 |
550 void Shell::SetUMask(const v8::FunctionCallbackInfo<v8::Value>& args) { | 550 void Shell::SetUMask(const v8::FunctionCallbackInfo<v8::Value>& args) { |
551 if (args.Length() != 1) { | 551 if (args.Length() != 1) { |
552 const char* message = "umask() takes one argument"; | 552 const char* message = "umask() takes one argument"; |
553 ThrowException(String::New(message)); | 553 ThrowException(args.GetIsolate(), String::New(message)); |
554 return; | 554 return; |
555 } | 555 } |
556 if (args[0]->IsNumber()) { | 556 if (args[0]->IsNumber()) { |
557 mode_t mask = args[0]->Int32Value(); | 557 mode_t mask = args[0]->Int32Value(); |
558 int previous = umask(mask); | 558 int previous = umask(mask); |
559 args.GetReturnValue().Set(previous); | 559 args.GetReturnValue().Set(previous); |
560 return; | 560 return; |
561 } else { | 561 } else { |
562 const char* message = "umask() argument must be numeric"; | 562 const char* message = "umask() argument must be numeric"; |
563 ThrowException(String::New(message)); | 563 ThrowException(args.GetIsolate(), String::New(message)); |
564 return; | 564 return; |
565 } | 565 } |
566 } | 566 } |
567 | 567 |
568 | 568 |
569 static bool CheckItsADirectory(char* directory) { | 569 static bool CheckItsADirectory(char* directory) { |
570 struct stat stat_buf; | 570 struct stat stat_buf; |
571 int stat_result = stat(directory, &stat_buf); | 571 int stat_result = stat(directory, &stat_buf); |
572 if (stat_result != 0) { | 572 if (stat_result != 0) { |
573 ThrowException(String::New(strerror(errno))); | 573 ThrowException(String::New(strerror(errno))); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
609 } | 609 } |
610 | 610 |
611 | 611 |
612 void Shell::MakeDirectory(const v8::FunctionCallbackInfo<v8::Value>& args) { | 612 void Shell::MakeDirectory(const v8::FunctionCallbackInfo<v8::Value>& args) { |
613 mode_t mask = 0777; | 613 mode_t mask = 0777; |
614 if (args.Length() == 2) { | 614 if (args.Length() == 2) { |
615 if (args[1]->IsNumber()) { | 615 if (args[1]->IsNumber()) { |
616 mask = args[1]->Int32Value(); | 616 mask = args[1]->Int32Value(); |
617 } else { | 617 } else { |
618 const char* message = "mkdirp() second argument must be numeric"; | 618 const char* message = "mkdirp() second argument must be numeric"; |
619 ThrowException(String::New(message)); | 619 ThrowException(args.GetIsolate(), String::New(message)); |
620 return; | 620 return; |
621 } | 621 } |
622 } else if (args.Length() != 1) { | 622 } else if (args.Length() != 1) { |
623 const char* message = "mkdirp() takes one or two arguments"; | 623 const char* message = "mkdirp() takes one or two arguments"; |
624 ThrowException(String::New(message)); | 624 ThrowException(args.GetIsolate(), String::New(message)); |
625 return; | 625 return; |
626 } | 626 } |
627 String::Utf8Value directory(args[0]); | 627 String::Utf8Value directory(args[0]); |
628 if (*directory == NULL) { | 628 if (*directory == NULL) { |
629 const char* message = "os.mkdirp(): String conversion of argument failed."; | 629 const char* message = "os.mkdirp(): String conversion of argument failed."; |
630 ThrowException(String::New(message)); | 630 ThrowException(args.GetIsolate(), String::New(message)); |
631 return; | 631 return; |
632 } | 632 } |
633 mkdirp(*directory, mask); | 633 mkdirp(*directory, mask); |
634 } | 634 } |
635 | 635 |
636 | 636 |
637 void Shell::RemoveDirectory(const v8::FunctionCallbackInfo<v8::Value>& args) { | 637 void Shell::RemoveDirectory(const v8::FunctionCallbackInfo<v8::Value>& args) { |
638 if (args.Length() != 1) { | 638 if (args.Length() != 1) { |
639 const char* message = "rmdir() takes one or two arguments"; | 639 const char* message = "rmdir() takes one or two arguments"; |
640 ThrowException(String::New(message)); | 640 ThrowException(args.GetIsolate(), String::New(message)); |
641 return; | 641 return; |
642 } | 642 } |
643 String::Utf8Value directory(args[0]); | 643 String::Utf8Value directory(args[0]); |
644 if (*directory == NULL) { | 644 if (*directory == NULL) { |
645 const char* message = "os.rmdir(): String conversion of argument failed."; | 645 const char* message = "os.rmdir(): String conversion of argument failed."; |
646 ThrowException(String::New(message)); | 646 ThrowException(args.GetIsolate(), String::New(message)); |
647 return; | 647 return; |
648 } | 648 } |
649 rmdir(*directory); | 649 rmdir(*directory); |
650 } | 650 } |
651 | 651 |
652 | 652 |
653 void Shell::SetEnvironment(const v8::FunctionCallbackInfo<v8::Value>& args) { | 653 void Shell::SetEnvironment(const v8::FunctionCallbackInfo<v8::Value>& args) { |
654 if (args.Length() != 2) { | 654 if (args.Length() != 2) { |
655 const char* message = "setenv() takes two arguments"; | 655 const char* message = "setenv() takes two arguments"; |
656 ThrowException(String::New(message)); | 656 ThrowException(args.GetIsolate(), String::New(message)); |
657 return; | 657 return; |
658 } | 658 } |
659 String::Utf8Value var(args[0]); | 659 String::Utf8Value var(args[0]); |
660 String::Utf8Value value(args[1]); | 660 String::Utf8Value value(args[1]); |
661 if (*var == NULL) { | 661 if (*var == NULL) { |
662 const char* message = | 662 const char* message = |
663 "os.setenv(): String conversion of variable name failed."; | 663 "os.setenv(): String conversion of variable name failed."; |
664 ThrowException(String::New(message)); | 664 ThrowException(args.GetIsolate(), String::New(message)); |
665 return; | 665 return; |
666 } | 666 } |
667 if (*value == NULL) { | 667 if (*value == NULL) { |
668 const char* message = | 668 const char* message = |
669 "os.setenv(): String conversion of variable contents failed."; | 669 "os.setenv(): String conversion of variable contents failed."; |
670 ThrowException(String::New(message)); | 670 ThrowException(args.GetIsolate(), String::New(message)); |
671 return; | 671 return; |
672 } | 672 } |
673 setenv(*var, *value, 1); | 673 setenv(*var, *value, 1); |
674 } | 674 } |
675 | 675 |
676 | 676 |
677 void Shell::UnsetEnvironment(const v8::FunctionCallbackInfo<v8::Value>& args) { | 677 void Shell::UnsetEnvironment(const v8::FunctionCallbackInfo<v8::Value>& args) { |
678 if (args.Length() != 1) { | 678 if (args.Length() != 1) { |
679 const char* message = "unsetenv() takes one argument"; | 679 const char* message = "unsetenv() takes one argument"; |
680 ThrowException(String::New(message)); | 680 ThrowException(args.GetIsolate(), String::New(message)); |
681 return; | 681 return; |
682 } | 682 } |
683 String::Utf8Value var(args[0]); | 683 String::Utf8Value var(args[0]); |
684 if (*var == NULL) { | 684 if (*var == NULL) { |
685 const char* message = | 685 const char* message = |
686 "os.setenv(): String conversion of variable name failed."; | 686 "os.setenv(): String conversion of variable name failed."; |
687 ThrowException(String::New(message)); | 687 ThrowException(args.GetIsolate(), String::New(message)); |
688 return; | 688 return; |
689 } | 689 } |
690 unsetenv(*var); | 690 unsetenv(*var); |
691 } | 691 } |
692 | 692 |
693 | 693 |
694 void Shell::AddOSMethods(Handle<ObjectTemplate> os_templ) { | 694 void Shell::AddOSMethods(Handle<ObjectTemplate> os_templ) { |
695 os_templ->Set(String::New("system"), FunctionTemplate::New(System)); | 695 os_templ->Set(String::New("system"), FunctionTemplate::New(System)); |
696 os_templ->Set(String::New("chdir"), FunctionTemplate::New(ChangeDirectory)); | 696 os_templ->Set(String::New("chdir"), FunctionTemplate::New(ChangeDirectory)); |
697 os_templ->Set(String::New("setenv"), FunctionTemplate::New(SetEnvironment)); | 697 os_templ->Set(String::New("setenv"), FunctionTemplate::New(SetEnvironment)); |
698 os_templ->Set(String::New("unsetenv"), | 698 os_templ->Set(String::New("unsetenv"), |
699 FunctionTemplate::New(UnsetEnvironment)); | 699 FunctionTemplate::New(UnsetEnvironment)); |
700 os_templ->Set(String::New("umask"), FunctionTemplate::New(SetUMask)); | 700 os_templ->Set(String::New("umask"), FunctionTemplate::New(SetUMask)); |
701 os_templ->Set(String::New("mkdirp"), FunctionTemplate::New(MakeDirectory)); | 701 os_templ->Set(String::New("mkdirp"), FunctionTemplate::New(MakeDirectory)); |
702 os_templ->Set(String::New("rmdir"), FunctionTemplate::New(RemoveDirectory)); | 702 os_templ->Set(String::New("rmdir"), FunctionTemplate::New(RemoveDirectory)); |
703 } | 703 } |
704 | 704 |
705 } // namespace v8 | 705 } // namespace v8 |
OLD | NEW |