Flush stdout after printing the d8 prompt

Previously, the d8 prompt was printed without flushing stdout. This
relies on the platform's libc to flush stdout when reading from stdin.
This behavior is not portable and breaks the prompt on some platforms.

Change-Id: Ieddf7ec5a6eab15796e69742bb4c9546ceb54c37
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3752006
Reviewed-by: Clemens Backes <clemensb@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Reviewed-by: Marja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81634}
This commit is contained in:
Pedro Falcato 2022-07-11 11:48:36 +01:00 committed by V8 LUCI CQ
parent 00282d7d10
commit 0573a07901
2 changed files with 4 additions and 0 deletions

View File

@ -197,6 +197,7 @@ Paolo Giarrusso <p.giarrusso@gmail.com>
Patrick Gansterer <paroga@paroga.com>
Paul Lind <plind44@gmail.com>
Pavel Medvedev <pmedvedev@gmail.com>
Pedro Falcato <pedro.falcato@gmail.com>
Peng Fei <pfgenyun@gmail.com>
Peng Wu <peng.w@rioslab.org>
Peng-Yu Chen <pengyu@libstarrify.so>

View File

@ -2438,6 +2438,9 @@ Local<String> Shell::ReadFromStdin(Isolate* isolate) {
char buffer[kBufferSize];
Local<String> accumulator = String::NewFromUtf8Literal(isolate, "");
int length;
// Flush stdout before reading stdin, as stdout isn't guaranteed to be flushed
// automatically.
fflush(stdout);
while (true) {
// Continue reading if the line ends with an escape '\\' or the line has
// not been fully read into the buffer yet (does not end with '\n').