| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 v8::String::NewFromUtf8(args.GetIsolate(), v8::V8::GetVersion())); | 231 v8::String::NewFromUtf8(args.GetIsolate(), v8::V8::GetVersion())); |
| 232 } | 232 } |
| 233 | 233 |
| 234 | 234 |
| 235 // Reads a file into a v8 string. | 235 // Reads a file into a v8 string. |
| 236 v8::Handle<v8::String> ReadFile(v8::Isolate* isolate, const char* name) { | 236 v8::Handle<v8::String> ReadFile(v8::Isolate* isolate, const char* name) { |
| 237 FILE* file = fopen(name, "rb"); | 237 FILE* file = fopen(name, "rb"); |
| 238 if (file == NULL) return v8::Handle<v8::String>(); | 238 if (file == NULL) return v8::Handle<v8::String>(); |
| 239 | 239 |
| 240 fseek(file, 0, SEEK_END); | 240 fseek(file, 0, SEEK_END); |
| 241 int size = ftell(file); | 241 size_t size = ftell(file); |
| 242 rewind(file); | 242 rewind(file); |
| 243 | 243 |
| 244 char* chars = new char[size + 1]; | 244 char* chars = new char[size + 1]; |
| 245 chars[size] = '\0'; | 245 chars[size] = '\0'; |
| 246 for (int i = 0; i < size;) { | 246 for (size_t i = 0; i < size;) { |
| 247 int read = static_cast<int>(fread(&chars[i], 1, size - i, file)); | 247 i += fread(&chars[i], 1, size - i, file); |
| 248 i += read; | 248 if (ferror(file)) { |
| 249 fclose(file); |
| 250 return v8::Handle<v8::String>(); |
| 251 } |
| 249 } | 252 } |
| 250 fclose(file); | 253 fclose(file); |
| 251 v8::Handle<v8::String> result = | 254 v8::Handle<v8::String> result = v8::String::NewFromUtf8( |
| 252 v8::String::NewFromUtf8(isolate, chars, v8::String::kNormalString, size); | 255 isolate, chars, v8::String::kNormalString, static_cast<int>(size)); |
| 253 delete[] chars; | 256 delete[] chars; |
| 254 return result; | 257 return result; |
| 255 } | 258 } |
| 256 | 259 |
| 257 | 260 |
| 258 // Process remaining command line arguments and execute files | 261 // Process remaining command line arguments and execute files |
| 259 int RunMain(v8::Isolate* isolate, int argc, char* argv[]) { | 262 int RunMain(v8::Isolate* isolate, int argc, char* argv[]) { |
| 260 for (int i = 1; i < argc; i++) { | 263 for (int i = 1; i < argc; i++) { |
| 261 const char* str = argv[i]; | 264 const char* str = argv[i]; |
| 262 if (strcmp(str, "--shell") == 0) { | 265 if (strcmp(str, "--shell") == 0) { |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 fprintf(stderr, "^"); | 384 fprintf(stderr, "^"); |
| 382 } | 385 } |
| 383 fprintf(stderr, "\n"); | 386 fprintf(stderr, "\n"); |
| 384 v8::String::Utf8Value stack_trace(try_catch->StackTrace()); | 387 v8::String::Utf8Value stack_trace(try_catch->StackTrace()); |
| 385 if (stack_trace.length() > 0) { | 388 if (stack_trace.length() > 0) { |
| 386 const char* stack_trace_string = ToCString(stack_trace); | 389 const char* stack_trace_string = ToCString(stack_trace); |
| 387 fprintf(stderr, "%s\n", stack_trace_string); | 390 fprintf(stderr, "%s\n", stack_trace_string); |
| 388 } | 391 } |
| 389 } | 392 } |
| 390 } | 393 } |
| OLD | NEW |