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> | |
11 #include <sys/stat.h> | 10 #include <sys/stat.h> |
12 #include <sys/time.h> | 11 #include <sys/time.h> |
13 #include <sys/types.h> | 12 #include <sys/types.h> |
14 #include <sys/wait.h> | 13 #include <sys/wait.h> |
15 #include <unistd.h> | 14 #include <unistd.h> |
16 | 15 |
17 #include "src/d8.h" | 16 #include "src/d8.h" |
18 | 17 |
| 18 #if !V8_OS_NACL |
| 19 #include <sys/select.h> |
| 20 #endif |
19 | 21 |
20 namespace v8 { | 22 namespace v8 { |
21 | 23 |
22 | 24 |
23 // If the buffer ends in the middle of a UTF-8 sequence then we return | 25 // If the buffer ends in the middle of a UTF-8 sequence then we return |
24 // the length of the string up to but not including the incomplete UTF-8 | 26 // the length of the string up to but not including the incomplete UTF-8 |
25 // sequence. If the buffer ends with a valid UTF-8 sequence then we | 27 // sequence. If the buffer ends with a valid UTF-8 sequence then we |
26 // return the whole buffer. | 28 // return the whole buffer. |
27 static int LengthWithoutIncompleteUtf8(char* buffer, int len) { | 29 static int LengthWithoutIncompleteUtf8(char* buffer, int len) { |
28 int answer = len; | 30 int answer = len; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 FD_ZERO(&writefds); | 97 FD_ZERO(&writefds); |
96 FD_ZERO(&exceptfds); | 98 FD_ZERO(&exceptfds); |
97 FD_SET(fd, &readfds); | 99 FD_SET(fd, &readfds); |
98 FD_SET(fd, &exceptfds); | 100 FD_SET(fd, &exceptfds); |
99 if (read_timeout == -1 || | 101 if (read_timeout == -1 || |
100 (total_timeout != -1 && total_timeout - gone < read_timeout)) { | 102 (total_timeout != -1 && total_timeout - gone < read_timeout)) { |
101 read_timeout = total_timeout - gone; | 103 read_timeout = total_timeout - gone; |
102 } | 104 } |
103 timeout.tv_usec = (read_timeout % 1000) * 1000; | 105 timeout.tv_usec = (read_timeout % 1000) * 1000; |
104 timeout.tv_sec = read_timeout / 1000; | 106 timeout.tv_sec = read_timeout / 1000; |
| 107 #if V8_OS_NACL |
| 108 // PNaCL has no support for select. |
| 109 int number_of_fds_ready = -1; |
| 110 #else |
105 int number_of_fds_ready = select(fd + 1, | 111 int number_of_fds_ready = select(fd + 1, |
106 &readfds, | 112 &readfds, |
107 &writefds, | 113 &writefds, |
108 &exceptfds, | 114 &exceptfds, |
109 read_timeout != -1 ? &timeout : NULL); | 115 read_timeout != -1 ? &timeout : NULL); |
| 116 #endif |
110 return number_of_fds_ready == 1; | 117 return number_of_fds_ready == 1; |
111 } | 118 } |
112 | 119 |
113 | 120 |
114 // Checks whether we ran out of time on the timeout. Returns true if we ran out | 121 // Checks whether we ran out of time on the timeout. Returns true if we ran out |
115 // of time, false if we still have time. | 122 // of time, false if we still have time. |
116 static bool TimeIsOut(const struct timeval& start_time, const int& total_time) { | 123 static bool TimeIsOut(const struct timeval& start_time, const int& total_time) { |
117 if (total_time == -1) return false; | 124 if (total_time == -1) return false; |
118 struct timeval time_now; | 125 struct timeval time_now; |
119 gettimeofday(&time_now, NULL); | 126 gettimeofday(&time_now, NULL); |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 | 547 |
541 | 548 |
542 void Shell::SetUMask(const v8::FunctionCallbackInfo<v8::Value>& args) { | 549 void Shell::SetUMask(const v8::FunctionCallbackInfo<v8::Value>& args) { |
543 if (args.Length() != 1) { | 550 if (args.Length() != 1) { |
544 const char* message = "umask() takes one argument"; | 551 const char* message = "umask() takes one argument"; |
545 args.GetIsolate()->ThrowException( | 552 args.GetIsolate()->ThrowException( |
546 String::NewFromUtf8(args.GetIsolate(), message)); | 553 String::NewFromUtf8(args.GetIsolate(), message)); |
547 return; | 554 return; |
548 } | 555 } |
549 if (args[0]->IsNumber()) { | 556 if (args[0]->IsNumber()) { |
550 mode_t mask = args[0]->Int32Value(); | 557 #if V8_OS_NACL |
551 int previous = umask(mask); | 558 // PNaCL has no support for umask. |
| 559 int previous = 0; |
| 560 #else |
| 561 int previous = umask(args[0]->Int32Value()); |
| 562 #endif |
552 args.GetReturnValue().Set(previous); | 563 args.GetReturnValue().Set(previous); |
553 return; | 564 return; |
554 } else { | 565 } else { |
555 const char* message = "umask() argument must be numeric"; | 566 const char* message = "umask() argument must be numeric"; |
556 args.GetIsolate()->ThrowException( | 567 args.GetIsolate()->ThrowException( |
557 String::NewFromUtf8(args.GetIsolate(), message)); | 568 String::NewFromUtf8(args.GetIsolate(), message)); |
558 return; | 569 return; |
559 } | 570 } |
560 } | 571 } |
561 | 572 |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
706 FunctionTemplate::New(isolate, UnsetEnvironment)); | 717 FunctionTemplate::New(isolate, UnsetEnvironment)); |
707 os_templ->Set(String::NewFromUtf8(isolate, "umask"), | 718 os_templ->Set(String::NewFromUtf8(isolate, "umask"), |
708 FunctionTemplate::New(isolate, SetUMask)); | 719 FunctionTemplate::New(isolate, SetUMask)); |
709 os_templ->Set(String::NewFromUtf8(isolate, "mkdirp"), | 720 os_templ->Set(String::NewFromUtf8(isolate, "mkdirp"), |
710 FunctionTemplate::New(isolate, MakeDirectory)); | 721 FunctionTemplate::New(isolate, MakeDirectory)); |
711 os_templ->Set(String::NewFromUtf8(isolate, "rmdir"), | 722 os_templ->Set(String::NewFromUtf8(isolate, "rmdir"), |
712 FunctionTemplate::New(isolate, RemoveDirectory)); | 723 FunctionTemplate::New(isolate, RemoveDirectory)); |
713 } | 724 } |
714 | 725 |
715 } // namespace v8 | 726 } // namespace v8 |
OLD | NEW |