| OLD | NEW |
| 1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <errno.h> | 5 #include <errno.h> |
| 6 #include <fcntl.h> | 6 #include <fcntl.h> |
| 7 #include <signal.h> | 7 #include <signal.h> |
| 8 #include <stdlib.h> | 8 #include <stdlib.h> |
| 9 #include <string.h> | 9 #include <string.h> |
| 10 #include <sys/select.h> |
| 10 #include <sys/stat.h> | 11 #include <sys/stat.h> |
| 11 #include <sys/time.h> | 12 #include <sys/time.h> |
| 12 #include <sys/types.h> | 13 #include <sys/types.h> |
| 13 #include <sys/wait.h> | 14 #include <sys/wait.h> |
| 14 #include <unistd.h> | 15 #include <unistd.h> |
| 15 | 16 |
| 16 #include "src/d8.h" | 17 #include "src/d8.h" |
| 17 | 18 |
| 18 #if !V8_OS_NACL | |
| 19 #include <sys/select.h> | |
| 20 #endif | |
| 21 | |
| 22 namespace v8 { | 19 namespace v8 { |
| 23 | 20 |
| 24 | 21 |
| 25 // If the buffer ends in the middle of a UTF-8 sequence then we return | 22 // If the buffer ends in the middle of a UTF-8 sequence then we return |
| 26 // the length of the string up to but not including the incomplete UTF-8 | 23 // the length of the string up to but not including the incomplete UTF-8 |
| 27 // sequence. If the buffer ends with a valid UTF-8 sequence then we | 24 // sequence. If the buffer ends with a valid UTF-8 sequence then we |
| 28 // return the whole buffer. | 25 // return the whole buffer. |
| 29 static int LengthWithoutIncompleteUtf8(char* buffer, int len) { | 26 static int LengthWithoutIncompleteUtf8(char* buffer, int len) { |
| 30 int answer = len; | 27 int answer = len; |
| 31 // 1-byte encoding. | 28 // 1-byte encoding. |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 FD_ZERO(&writefds); | 95 FD_ZERO(&writefds); |
| 99 FD_ZERO(&exceptfds); | 96 FD_ZERO(&exceptfds); |
| 100 FD_SET(fd, &readfds); | 97 FD_SET(fd, &readfds); |
| 101 FD_SET(fd, &exceptfds); | 98 FD_SET(fd, &exceptfds); |
| 102 if (read_timeout == -1 || | 99 if (read_timeout == -1 || |
| 103 (total_timeout != -1 && total_timeout - gone < read_timeout)) { | 100 (total_timeout != -1 && total_timeout - gone < read_timeout)) { |
| 104 read_timeout = total_timeout - gone; | 101 read_timeout = total_timeout - gone; |
| 105 } | 102 } |
| 106 timeout.tv_usec = (read_timeout % 1000) * 1000; | 103 timeout.tv_usec = (read_timeout % 1000) * 1000; |
| 107 timeout.tv_sec = read_timeout / 1000; | 104 timeout.tv_sec = read_timeout / 1000; |
| 108 #if V8_OS_NACL | |
| 109 // PNaCL has no support for select. | |
| 110 int number_of_fds_ready = -1; | |
| 111 #else | |
| 112 int number_of_fds_ready = select(fd + 1, | 105 int number_of_fds_ready = select(fd + 1, |
| 113 &readfds, | 106 &readfds, |
| 114 &writefds, | 107 &writefds, |
| 115 &exceptfds, | 108 &exceptfds, |
| 116 read_timeout != -1 ? &timeout : NULL); | 109 read_timeout != -1 ? &timeout : NULL); |
| 117 #endif | |
| 118 return number_of_fds_ready == 1; | 110 return number_of_fds_ready == 1; |
| 119 } | 111 } |
| 120 | 112 |
| 121 | 113 |
| 122 // Checks whether we ran out of time on the timeout. Returns true if we ran out | 114 // Checks whether we ran out of time on the timeout. Returns true if we ran out |
| 123 // of time, false if we still have time. | 115 // of time, false if we still have time. |
| 124 static bool TimeIsOut(const struct timeval& start_time, const int& total_time) { | 116 static bool TimeIsOut(const struct timeval& start_time, const int& total_time) { |
| 125 if (total_time == -1) return false; | 117 if (total_time == -1) return false; |
| 126 struct timeval time_now; | 118 struct timeval time_now; |
| 127 gettimeofday(&time_now, NULL); | 119 gettimeofday(&time_now, NULL); |
| (...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 | 570 |
| 579 void Shell::SetUMask(const v8::FunctionCallbackInfo<v8::Value>& args) { | 571 void Shell::SetUMask(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 580 if (args.Length() != 1) { | 572 if (args.Length() != 1) { |
| 581 const char* message = "umask() takes one argument"; | 573 const char* message = "umask() takes one argument"; |
| 582 args.GetIsolate()->ThrowException( | 574 args.GetIsolate()->ThrowException( |
| 583 String::NewFromUtf8(args.GetIsolate(), message, NewStringType::kNormal) | 575 String::NewFromUtf8(args.GetIsolate(), message, NewStringType::kNormal) |
| 584 .ToLocalChecked()); | 576 .ToLocalChecked()); |
| 585 return; | 577 return; |
| 586 } | 578 } |
| 587 if (args[0]->IsNumber()) { | 579 if (args[0]->IsNumber()) { |
| 588 #if V8_OS_NACL | |
| 589 // PNaCL has no support for umask. | |
| 590 int previous = 0; | |
| 591 #else | |
| 592 int previous = umask( | 580 int previous = umask( |
| 593 args[0]->Int32Value(args.GetIsolate()->GetCurrentContext()).FromJust()); | 581 args[0]->Int32Value(args.GetIsolate()->GetCurrentContext()).FromJust()); |
| 594 #endif | |
| 595 args.GetReturnValue().Set(previous); | 582 args.GetReturnValue().Set(previous); |
| 596 return; | 583 return; |
| 597 } else { | 584 } else { |
| 598 const char* message = "umask() argument must be numeric"; | 585 const char* message = "umask() argument must be numeric"; |
| 599 args.GetIsolate()->ThrowException( | 586 args.GetIsolate()->ThrowException( |
| 600 String::NewFromUtf8(args.GetIsolate(), message, NewStringType::kNormal) | 587 String::NewFromUtf8(args.GetIsolate(), message, NewStringType::kNormal) |
| 601 .ToLocalChecked()); | 588 .ToLocalChecked()); |
| 602 return; | 589 return; |
| 603 } | 590 } |
| 604 } | 591 } |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 779 FunctionTemplate::New(isolate, SetUMask)); | 766 FunctionTemplate::New(isolate, SetUMask)); |
| 780 os_templ->Set(String::NewFromUtf8(isolate, "mkdirp", NewStringType::kNormal) | 767 os_templ->Set(String::NewFromUtf8(isolate, "mkdirp", NewStringType::kNormal) |
| 781 .ToLocalChecked(), | 768 .ToLocalChecked(), |
| 782 FunctionTemplate::New(isolate, MakeDirectory)); | 769 FunctionTemplate::New(isolate, MakeDirectory)); |
| 783 os_templ->Set(String::NewFromUtf8(isolate, "rmdir", NewStringType::kNormal) | 770 os_templ->Set(String::NewFromUtf8(isolate, "rmdir", NewStringType::kNormal) |
| 784 .ToLocalChecked(), | 771 .ToLocalChecked(), |
| 785 FunctionTemplate::New(isolate, RemoveDirectory)); | 772 FunctionTemplate::New(isolate, RemoveDirectory)); |
| 786 } | 773 } |
| 787 | 774 |
| 788 } // namespace v8 | 775 } // namespace v8 |
| OLD | NEW |