Reviewers: Christian Plesner Hansen, Message: Hi Christian
Sorry, I had to redo the CLs as I'd lost my previous workspaces. In regards to Spidermonkey and JSC not having this function, apparently there is a way of controlling whether a new line is printed or not for them, but not for V8. Description: Add a write() command to d8. This is the same as the print() command, with the exception that it does not add a new-line to the end. This half of what is required to make the Debian Language Shootout code work correctly: http://code.google.com/p/v8/issues/detail?id=354 BUG=354 Please review this at http://codereview.chromium.org/160639 SVN Base: http://v8.googlecode.com/svn/branches/bleeding_edge/ Affected files: M src/d8.h M src/d8.cc Index: src/d8.cc =================================================================== --- src/d8.cc (revision 2626) +++ src/d8.cc (working copy) @@ -146,19 +146,22 @@ Handle<Value> Shell::Print(const Arguments& args) { - bool first = true; + Handle<Value> val = Write(args); + printf("\n"); + return val; +} + + +Handle<Value> Shell::Write(const Arguments& args) { for (int i = 0; i < args.Length(); i++) { HandleScope handle_scope; - if (first) { - first = false; - } else { + if (i != 0) { printf(" "); } v8::String::Utf8Value str(args[i]); const char* cstr = ToCString(str); printf("%s", cstr); } - printf("\n"); return Undefined(); } @@ -399,6 +402,7 @@ HandleScope scope; Handle<ObjectTemplate> global_template = ObjectTemplate::New(); global_template->Set(String::New("print"), FunctionTemplate::New(Print)); + global_template->Set(String::New("write"), FunctionTemplate::New(Write)); global_template->Set(String::New("read"), FunctionTemplate::New(Read)); global_template->Set(String::New("load"), FunctionTemplate::New(Load)); global_template->Set(String::New("quit"), FunctionTemplate::New(Quit)); @@ -588,6 +592,8 @@ Handle<ObjectTemplate> global_template = ObjectTemplate::New(); global_template->Set(String::New("print"), FunctionTemplate::New(Shell::Print)); + global_template->Set(String::New("write"), + FunctionTemplate::New(Shell::Write)); global_template->Set(String::New("read"), FunctionTemplate::New(Shell::Read)); global_template->Set(String::New("load"), Index: src/d8.h =================================================================== --- src/d8.h (revision 2626) +++ src/d8.h (working copy) @@ -138,6 +138,7 @@ #endif static Handle<Value> Print(const Arguments& args); + static Handle<Value> Write(const Arguments& args); static Handle<Value> Yield(const Arguments& args); static Handle<Value> Quit(const Arguments& args); static Handle<Value> Version(const Arguments& args); --~--~---------~--~----~------------~-------~--~----~ v8-dev mailing list [email protected] http://groups.google.com/group/v8-dev -~----------~----~----~----~------~----~------~--~---
