| 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 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 } | 588 } |
| 589 } | 589 } |
| 590 | 590 |
| 591 | 591 |
| 592 // Reads a file into a v8 string. | 592 // Reads a file into a v8 string. |
| 593 Handle<String> ReadFile(Isolate* isolate, const string& name) { | 593 Handle<String> ReadFile(Isolate* isolate, const string& name) { |
| 594 FILE* file = fopen(name.c_str(), "rb"); | 594 FILE* file = fopen(name.c_str(), "rb"); |
| 595 if (file == NULL) return Handle<String>(); | 595 if (file == NULL) return Handle<String>(); |
| 596 | 596 |
| 597 fseek(file, 0, SEEK_END); | 597 fseek(file, 0, SEEK_END); |
| 598 int size = ftell(file); | 598 size_t size = ftell(file); |
| 599 rewind(file); | 599 rewind(file); |
| 600 | 600 |
| 601 char* chars = new char[size + 1]; | 601 char* chars = new char[size + 1]; |
| 602 chars[size] = '\0'; | 602 chars[size] = '\0'; |
| 603 for (int i = 0; i < size;) { | 603 for (size_t i = 0; i < size;) { |
| 604 int read = static_cast<int>(fread(&chars[i], 1, size - i, file)); | 604 i += fread(&chars[i], 1, size - i, file); |
| 605 i += read; | 605 if (ferror(file)) { |
| 606 fclose(file); |
| 607 return Handle<String>(); |
| 608 } |
| 606 } | 609 } |
| 607 fclose(file); | 610 fclose(file); |
| 608 Handle<String> result = | 611 Handle<String> result = String::NewFromUtf8( |
| 609 String::NewFromUtf8(isolate, chars, String::kNormalString, size); | 612 isolate, chars, String::kNormalString, static_cast<int>(size)); |
| 610 delete[] chars; | 613 delete[] chars; |
| 611 return result; | 614 return result; |
| 612 } | 615 } |
| 613 | 616 |
| 614 | 617 |
| 615 const int kSampleSize = 6; | 618 const int kSampleSize = 6; |
| 616 StringHttpRequest kSampleRequests[kSampleSize] = { | 619 StringHttpRequest kSampleRequests[kSampleSize] = { |
| 617 StringHttpRequest("/process.cc", "localhost", "google.com", "firefox"), | 620 StringHttpRequest("/process.cc", "localhost", "google.com", "firefox"), |
| 618 StringHttpRequest("/", "localhost", "google.net", "firefox"), | 621 StringHttpRequest("/", "localhost", "google.net", "firefox"), |
| 619 StringHttpRequest("/", "localhost", "google.org", "safari"), | 622 StringHttpRequest("/", "localhost", "google.org", "safari"), |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 664 JsHttpRequestProcessor processor(isolate, source); | 667 JsHttpRequestProcessor processor(isolate, source); |
| 665 map<string, string> output; | 668 map<string, string> output; |
| 666 if (!processor.Initialize(&options, &output)) { | 669 if (!processor.Initialize(&options, &output)) { |
| 667 fprintf(stderr, "Error initializing processor.\n"); | 670 fprintf(stderr, "Error initializing processor.\n"); |
| 668 return 1; | 671 return 1; |
| 669 } | 672 } |
| 670 if (!ProcessEntries(&processor, kSampleSize, kSampleRequests)) | 673 if (!ProcessEntries(&processor, kSampleSize, kSampleRequests)) |
| 671 return 1; | 674 return 1; |
| 672 PrintMap(&output); | 675 PrintMap(&output); |
| 673 } | 676 } |
| OLD | NEW |