Chromium Code Reviews| 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 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 304 } | 304 } |
| 305 | 305 |
| 306 | 306 |
| 307 // Accumulates the output from the child in a string handle. Returns true if it | 307 // Accumulates the output from the child in a string handle. Returns true if it |
| 308 // succeeded or false if an exception was thrown. | 308 // succeeded or false if an exception was thrown. |
| 309 static Handle<Value> GetStdout(int child_fd, | 309 static Handle<Value> GetStdout(int child_fd, |
| 310 struct timeval& start_time, | 310 struct timeval& start_time, |
| 311 int read_timeout, | 311 int read_timeout, |
| 312 int total_timeout) { | 312 int total_timeout) { |
| 313 Handle<String> accumulator = String::Empty(); | 313 Handle<String> accumulator = String::Empty(); |
| 314 const char* source = "(function(a, b) { return a + b; })"; | |
| 315 Handle<Value> cons_as_obj(Script::Compile(String::New(source))->Run()); | |
| 316 Handle<Function> cons_function(Function::Cast(*cons_as_obj)); | |
| 317 Handle<Value> cons_args[2]; | |
| 318 | 314 |
| 319 int fullness = 0; | 315 int fullness = 0; |
| 320 static const int kStdoutReadBufferSize = 4096; | 316 static const int kStdoutReadBufferSize = 4096; |
| 321 char buffer[kStdoutReadBufferSize]; | 317 char buffer[kStdoutReadBufferSize]; |
| 322 | 318 |
| 323 if (fcntl(child_fd, F_SETFL, O_NONBLOCK) != 0) { | 319 if (fcntl(child_fd, F_SETFL, O_NONBLOCK) != 0) { |
| 324 return ThrowException(String::New(strerror(errno))); | 320 return ThrowException(String::New(strerror(errno))); |
| 325 } | 321 } |
| 326 | 322 |
| 327 int bytes_read; | 323 int bytes_read; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 343 continue; | 339 continue; |
| 344 } else { | 340 } else { |
| 345 break; | 341 break; |
| 346 } | 342 } |
| 347 } | 343 } |
| 348 if (bytes_read + fullness > 0) { | 344 if (bytes_read + fullness > 0) { |
| 349 int length = bytes_read == 0 ? | 345 int length = bytes_read == 0 ? |
| 350 bytes_read + fullness : | 346 bytes_read + fullness : |
| 351 LengthWithoutIncompleteUtf8(buffer, bytes_read + fullness); | 347 LengthWithoutIncompleteUtf8(buffer, bytes_read + fullness); |
| 352 Handle<String> addition = String::New(buffer, length); | 348 Handle<String> addition = String::New(buffer, length); |
| 353 cons_args[0] = accumulator; | 349 accumulator = String::Concat(accumulator, addition); |
|
Yang
2011/06/22 00:44:08
As you suggested, String::Concat instead of the de
| |
| 354 cons_args[1] = addition; | |
| 355 accumulator = Handle<String>::Cast(cons_function->Call( | |
| 356 Shell::utility_context()->Global(), | |
| 357 2, | |
| 358 cons_args)); | |
| 359 fullness = bytes_read + fullness - length; | 350 fullness = bytes_read + fullness - length; |
| 360 memcpy(buffer, buffer + length, fullness); | 351 memcpy(buffer, buffer + length, fullness); |
| 361 } | 352 } |
| 362 } while (bytes_read != 0); | 353 } while (bytes_read != 0); |
| 363 return accumulator; | 354 return accumulator; |
| 364 } | 355 } |
| 365 | 356 |
| 366 | 357 |
| 367 // Modern Linux has the waitid call, which is like waitpid, but more useful | 358 // Modern Linux has the waitid call, which is like waitpid, but more useful |
| 368 // if you want a timeout. If we don't have waitid we can't limit the time | 359 // if you want a timeout. If we don't have waitid we can't limit the time |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 686 os_templ->Set(String::New("chdir"), FunctionTemplate::New(ChangeDirectory)); | 677 os_templ->Set(String::New("chdir"), FunctionTemplate::New(ChangeDirectory)); |
| 687 os_templ->Set(String::New("setenv"), FunctionTemplate::New(SetEnvironment)); | 678 os_templ->Set(String::New("setenv"), FunctionTemplate::New(SetEnvironment)); |
| 688 os_templ->Set(String::New("unsetenv"), | 679 os_templ->Set(String::New("unsetenv"), |
| 689 FunctionTemplate::New(UnsetEnvironment)); | 680 FunctionTemplate::New(UnsetEnvironment)); |
| 690 os_templ->Set(String::New("umask"), FunctionTemplate::New(SetUMask)); | 681 os_templ->Set(String::New("umask"), FunctionTemplate::New(SetUMask)); |
| 691 os_templ->Set(String::New("mkdirp"), FunctionTemplate::New(MakeDirectory)); | 682 os_templ->Set(String::New("mkdirp"), FunctionTemplate::New(MakeDirectory)); |
| 692 os_templ->Set(String::New("rmdir"), FunctionTemplate::New(RemoveDirectory)); | 683 os_templ->Set(String::New("rmdir"), FunctionTemplate::New(RemoveDirectory)); |
| 693 } | 684 } |
| 694 | 685 |
| 695 } // namespace v8 | 686 } // namespace v8 |
| OLD | NEW |