| 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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 } | 173 } |
| 174 Handle<String> source = ReadFile(*file); | 174 Handle<String> source = ReadFile(*file); |
| 175 if (source.IsEmpty()) { | 175 if (source.IsEmpty()) { |
| 176 return ThrowException(String::New("Error loading file")); | 176 return ThrowException(String::New("Error loading file")); |
| 177 } | 177 } |
| 178 return source; | 178 return source; |
| 179 } | 179 } |
| 180 | 180 |
| 181 | 181 |
| 182 Handle<Value> Shell::ReadLine(const Arguments& args) { | 182 Handle<Value> Shell::ReadLine(const Arguments& args) { |
| 183 char line_buf[256]; | 183 i::SmartPointer<char> line(i::ReadLine("")); |
| 184 if (fgets(line_buf, sizeof(line_buf), stdin) == NULL) { | 184 if (*line == NULL) { |
| 185 return ThrowException(String::New("Error reading line")); | 185 return Null(); |
| 186 } | 186 } |
| 187 int len = strlen(line_buf); | 187 size_t len = strlen(*line); |
| 188 if (line_buf[len - 1] == '\n') { | 188 if (len > 0 && line[len - 1] == '\n') { |
| 189 --len; | 189 --len; |
| 190 } | 190 } |
| 191 return String::New(line_buf, len); | 191 return String::New(*line, len); |
| 192 } | 192 } |
| 193 | 193 |
| 194 | 194 |
| 195 Handle<Value> Shell::Load(const Arguments& args) { | 195 Handle<Value> Shell::Load(const Arguments& args) { |
| 196 for (int i = 0; i < args.Length(); i++) { | 196 for (int i = 0; i < args.Length(); i++) { |
| 197 HandleScope handle_scope; | 197 HandleScope handle_scope; |
| 198 String::Utf8Value file(args[i]); | 198 String::Utf8Value file(args[i]); |
| 199 if (*file == NULL) { | 199 if (*file == NULL) { |
| 200 return ThrowException(String::New("Error loading file")); | 200 return ThrowException(String::New("Error loading file")); |
| 201 } | 201 } |
| (...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 764 return 0; | 764 return 0; |
| 765 } | 765 } |
| 766 | 766 |
| 767 | 767 |
| 768 } // namespace v8 | 768 } // namespace v8 |
| 769 | 769 |
| 770 | 770 |
| 771 int main(int argc, char* argv[]) { | 771 int main(int argc, char* argv[]) { |
| 772 return v8::Shell::Main(argc, argv); | 772 return v8::Shell::Main(argc, argv); |
| 773 } | 773 } |
| OLD | NEW |