Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(201)

Side by Side Diff: src/d8.cc

Issue 7565005: Version 3.5.3 (Closed) Base URL: https://v8.googlecode.com/svn/trunk
Patch Set: Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/code-stubs.h ('k') | src/hydrogen.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 return ThrowException(String::New("Error loading file")); 219 return ThrowException(String::New("Error loading file"));
220 } 220 }
221 return source; 221 return source;
222 } 222 }
223 223
224 224
225 Handle<Value> Shell::ReadLine(const Arguments& args) { 225 Handle<Value> Shell::ReadLine(const Arguments& args) {
226 static const int kBufferSize = 256; 226 static const int kBufferSize = 256;
227 char buffer[kBufferSize]; 227 char buffer[kBufferSize];
228 Handle<String> accumulator = String::New(""); 228 Handle<String> accumulator = String::New("");
229 bool linebreak;
230 int length; 229 int length;
231 do { // Repeat if the line ends with an escape '\'. 230 while (true) {
232 // fgets got an error. Just give up. 231 // Continue reading if the line ends with an escape '\\' or the line has
232 // not been fully read into the buffer yet (does not end with '\n').
233 // If fgets gets an error, just give up.
233 if (fgets(buffer, kBufferSize, stdin) == NULL) return Null(); 234 if (fgets(buffer, kBufferSize, stdin) == NULL) return Null();
234 length = static_cast<int>(strlen(buffer)); 235 length = static_cast<int>(strlen(buffer));
235 linebreak = (length > 1 && buffer[length-2] == '\\'); 236 if (length == 0) {
236 if (linebreak) buffer[length-2] = '\n'; 237 return accumulator;
237 accumulator = String::Concat(accumulator, String::New(buffer, length-1)); 238 } else if (buffer[length-1] != '\n') {
238 } while (linebreak); 239 accumulator = String::Concat(accumulator, String::New(buffer, length));
239 return accumulator; 240 } else if (length > 1 && buffer[length-2] == '\\') {
241 buffer[length-2] = '\n';
242 accumulator = String::Concat(accumulator, String::New(buffer, length-1));
243 } else {
244 return String::Concat(accumulator, String::New(buffer, length-1));
245 }
246 }
240 } 247 }
241 248
242 249
243 Handle<Value> Shell::Load(const Arguments& args) { 250 Handle<Value> Shell::Load(const Arguments& args) {
244 for (int i = 0; i < args.Length(); i++) { 251 for (int i = 0; i < args.Length(); i++) {
245 HandleScope handle_scope; 252 HandleScope handle_scope;
246 String::Utf8Value file(args[i]); 253 String::Utf8Value file(args[i]);
247 if (*file == NULL) { 254 if (*file == NULL) {
248 return ThrowException(String::New("Error loading file")); 255 return ThrowException(String::New("Error loading file"));
249 } 256 }
(...skipping 1034 matching lines...) Expand 10 before | Expand all | Expand 10 after
1284 } 1291 }
1285 1292
1286 } // namespace v8 1293 } // namespace v8
1287 1294
1288 1295
1289 #ifndef GOOGLE3 1296 #ifndef GOOGLE3
1290 int main(int argc, char* argv[]) { 1297 int main(int argc, char* argv[]) {
1291 return v8::Shell::Main(argc, argv); 1298 return v8::Shell::Main(argc, argv);
1292 } 1299 }
1293 #endif 1300 #endif
OLDNEW
« no previous file with comments | « src/code-stubs.h ('k') | src/hydrogen.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698