Status: New
Owner: ----
New issue 249 by sgbeal: improvement for print() in shell.cc
http://code.google.com/p/v8/issues/detail?id=249
Hello!
Here's a suggested improvement for the Print() function in shell.cc: use
std::cout instead of printf(). The reason is that it is possible, using the
C++ streams API, to insert our own streambuffer into cout, such that we can
redirect all output send to cout to some custom output source. As an
example, my v8/ncurses bindings i have a routine which redirects std::cout
and std::cout to an ncurses Window of the client's choice. Because the
Print() implementation uses cout instead of printf(), JS code which uses
print() doesn't hose the ncurses screen (it gets redirected, via the
ncurses API, to a window). In other applications, print() might be sent to
some logging console or status bar.
Since the example applications will become the de facto copy/paste
implementations of common functions, it would be nice to improve the
flexibility of the basis from which we copy/paste :).
For completeness, here's the implementation:
{{{
v8::Handle<v8::Value> Print(const v8::Arguments& args) {
bool first = true;
for (int i = 0; i < args.Length(); i++) {
v8::HandleScope handle_scope;
if (first) {
first = false;
} else {
std::cout << ' ';
}
v8::String::Utf8Value str(args[i]);
const char* cstr = ToCString(str);
if( cstr ) std::cout << cstr;
}
std::cout << '\n';
return v8::Undefined();
}
}}}
--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings
--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---