| Index: src/d8.cc
|
| ===================================================================
|
| --- src/d8.cc (revision 2625)
|
| +++ src/d8.cc (working copy)
|
| @@ -164,9 +164,6 @@
|
|
|
|
|
| Handle<Value> Shell::Read(const Arguments& args) {
|
| - if (args.Length() != 1) {
|
| - return ThrowException(String::New("Bad parameters"));
|
| - }
|
| String::Utf8Value file(args[0]);
|
| if (*file == NULL) {
|
| return ThrowException(String::New("Error loading file"));
|
| @@ -179,6 +176,19 @@
|
| }
|
|
|
|
|
| +Handle<Value> Shell::ReadLine(const Arguments& args) {
|
| + char line_buf[256];
|
| + if (fgets(line_buf, sizeof(line_buf), stdin) == NULL) {
|
| + return ThrowException(String::New("Error reading line"));
|
| + }
|
| + int len = strlen(line_buf);
|
| + if (line_buf[len - 1] == '\n') {
|
| + --len;
|
| + }
|
| + return String::New(line_buf, len);
|
| +}
|
| +
|
| +
|
| Handle<Value> Shell::Load(const Arguments& args) {
|
| for (int i = 0; i < args.Length(); i++) {
|
| HandleScope handle_scope;
|
| @@ -400,6 +410,8 @@
|
| Handle<ObjectTemplate> global_template = ObjectTemplate::New();
|
| global_template->Set(String::New("print"), FunctionTemplate::New(Print));
|
| global_template->Set(String::New("read"), FunctionTemplate::New(Read));
|
| + global_template->Set(String::New("readline"),
|
| + FunctionTemplate::New(ReadLine));
|
| global_template->Set(String::New("load"), FunctionTemplate::New(Load));
|
| global_template->Set(String::New("quit"), FunctionTemplate::New(Quit));
|
| global_template->Set(String::New("version"), FunctionTemplate::New(Version));
|
| @@ -590,6 +602,8 @@
|
| FunctionTemplate::New(Shell::Print));
|
| global_template->Set(String::New("read"),
|
| FunctionTemplate::New(Shell::Read));
|
| + global_template->Set(String::New("readline"),
|
| + FunctionTemplate::New(Shell::ReadLine));
|
| global_template->Set(String::New("load"),
|
| FunctionTemplate::New(Shell::Load));
|
| global_template->Set(String::New("yield"),
|
|
|