| OLD | NEW |
| 1 // Copyright 2008 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 |
| 11 // with the distribution. | 11 // with the distribution. |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 string key = ObjectToString(name); | 344 string key = ObjectToString(name); |
| 345 | 345 |
| 346 // Look up the value if it exists using the standard STL ideom. | 346 // Look up the value if it exists using the standard STL ideom. |
| 347 map<string, string>::iterator iter = obj->find(key); | 347 map<string, string>::iterator iter = obj->find(key); |
| 348 | 348 |
| 349 // If the key is not present return an empty handle as signal | 349 // If the key is not present return an empty handle as signal |
| 350 if (iter == obj->end()) return Handle<Value>(); | 350 if (iter == obj->end()) return Handle<Value>(); |
| 351 | 351 |
| 352 // Otherwise fetch the value and wrap it in a JavaScript string | 352 // Otherwise fetch the value and wrap it in a JavaScript string |
| 353 const string& value = (*iter).second; | 353 const string& value = (*iter).second; |
| 354 return String::New(value.c_str(), value.length()); | 354 return String::New(value.c_str(), static_cast<int>(value.length())); |
| 355 } | 355 } |
| 356 | 356 |
| 357 | 357 |
| 358 Handle<Value> JsHttpRequestProcessor::MapSet(Local<String> name, | 358 Handle<Value> JsHttpRequestProcessor::MapSet(Local<String> name, |
| 359 Local<Value> value_obj, | 359 Local<Value> value_obj, |
| 360 const AccessorInfo& info) { | 360 const AccessorInfo& info) { |
| 361 // Fetch the map wrapped by this object. | 361 // Fetch the map wrapped by this object. |
| 362 map<string, string>* obj = UnwrapMap(info.Holder()); | 362 map<string, string>* obj = UnwrapMap(info.Holder()); |
| 363 | 363 |
| 364 // Convert the key and value to std::strings. | 364 // Convert the key and value to std::strings. |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 | 436 |
| 437 Handle<Value> JsHttpRequestProcessor::GetPath(Local<String> name, | 437 Handle<Value> JsHttpRequestProcessor::GetPath(Local<String> name, |
| 438 const AccessorInfo& info) { | 438 const AccessorInfo& info) { |
| 439 // Extract the C++ request object from the JavaScript wrapper. | 439 // Extract the C++ request object from the JavaScript wrapper. |
| 440 HttpRequest* request = UnwrapRequest(info.Holder()); | 440 HttpRequest* request = UnwrapRequest(info.Holder()); |
| 441 | 441 |
| 442 // Fetch the path. | 442 // Fetch the path. |
| 443 const string& path = request->Path(); | 443 const string& path = request->Path(); |
| 444 | 444 |
| 445 // Wrap the result in a JavaScript string and return it. | 445 // Wrap the result in a JavaScript string and return it. |
| 446 return String::New(path.c_str(), path.length()); | 446 return String::New(path.c_str(), static_cast<int>(path.length())); |
| 447 } | 447 } |
| 448 | 448 |
| 449 | 449 |
| 450 Handle<Value> JsHttpRequestProcessor::GetReferrer(Local<String> name, | 450 Handle<Value> JsHttpRequestProcessor::GetReferrer(Local<String> name, |
| 451 const AccessorInfo& info) { | 451 const AccessorInfo& info) { |
| 452 HttpRequest* request = UnwrapRequest(info.Holder()); | 452 HttpRequest* request = UnwrapRequest(info.Holder()); |
| 453 const string& path = request->Referrer(); | 453 const string& path = request->Referrer(); |
| 454 return String::New(path.c_str(), path.length()); | 454 return String::New(path.c_str(), static_cast<int>(path.length())); |
| 455 } | 455 } |
| 456 | 456 |
| 457 | 457 |
| 458 Handle<Value> JsHttpRequestProcessor::GetHost(Local<String> name, | 458 Handle<Value> JsHttpRequestProcessor::GetHost(Local<String> name, |
| 459 const AccessorInfo& info) { | 459 const AccessorInfo& info) { |
| 460 HttpRequest* request = UnwrapRequest(info.Holder()); | 460 HttpRequest* request = UnwrapRequest(info.Holder()); |
| 461 const string& path = request->Host(); | 461 const string& path = request->Host(); |
| 462 return String::New(path.c_str(), path.length()); | 462 return String::New(path.c_str(), static_cast<int>(path.length())); |
| 463 } | 463 } |
| 464 | 464 |
| 465 | 465 |
| 466 Handle<Value> JsHttpRequestProcessor::GetUserAgent(Local<String> name, | 466 Handle<Value> JsHttpRequestProcessor::GetUserAgent(Local<String> name, |
| 467 const AccessorInfo& info) { | 467 const AccessorInfo& info) { |
| 468 HttpRequest* request = UnwrapRequest(info.Holder()); | 468 HttpRequest* request = UnwrapRequest(info.Holder()); |
| 469 const string& path = request->UserAgent(); | 469 const string& path = request->UserAgent(); |
| 470 return String::New(path.c_str(), path.length()); | 470 return String::New(path.c_str(), static_cast<int>(path.length())); |
| 471 } | 471 } |
| 472 | 472 |
| 473 | 473 |
| 474 Handle<ObjectTemplate> JsHttpRequestProcessor::MakeRequestTemplate() { | 474 Handle<ObjectTemplate> JsHttpRequestProcessor::MakeRequestTemplate() { |
| 475 HandleScope handle_scope; | 475 HandleScope handle_scope; |
| 476 | 476 |
| 477 Handle<ObjectTemplate> result = ObjectTemplate::New(); | 477 Handle<ObjectTemplate> result = ObjectTemplate::New(); |
| 478 result->SetInternalFieldCount(1); | 478 result->SetInternalFieldCount(1); |
| 479 | 479 |
| 480 // Add accessors for each of the fields of the request. | 480 // Add accessors for each of the fields of the request. |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 FILE* file = fopen(name.c_str(), "rb"); | 550 FILE* file = fopen(name.c_str(), "rb"); |
| 551 if (file == NULL) return Handle<String>(); | 551 if (file == NULL) return Handle<String>(); |
| 552 | 552 |
| 553 fseek(file, 0, SEEK_END); | 553 fseek(file, 0, SEEK_END); |
| 554 int size = ftell(file); | 554 int size = ftell(file); |
| 555 rewind(file); | 555 rewind(file); |
| 556 | 556 |
| 557 char* chars = new char[size + 1]; | 557 char* chars = new char[size + 1]; |
| 558 chars[size] = '\0'; | 558 chars[size] = '\0'; |
| 559 for (int i = 0; i < size;) { | 559 for (int i = 0; i < size;) { |
| 560 int read = fread(&chars[i], 1, size - i, file); | 560 int read = static_cast<int>(fread(&chars[i], 1, size - i, file)); |
| 561 i += read; | 561 i += read; |
| 562 } | 562 } |
| 563 fclose(file); | 563 fclose(file); |
| 564 Handle<String> result = String::New(chars, size); | 564 Handle<String> result = String::New(chars, size); |
| 565 delete[] chars; | 565 delete[] chars; |
| 566 return result; | 566 return result; |
| 567 } | 567 } |
| 568 | 568 |
| 569 | 569 |
| 570 const int kSampleSize = 6; | 570 const int kSampleSize = 6; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 JsHttpRequestProcessor processor(source); | 613 JsHttpRequestProcessor processor(source); |
| 614 map<string, string> output; | 614 map<string, string> output; |
| 615 if (!processor.Initialize(&options, &output)) { | 615 if (!processor.Initialize(&options, &output)) { |
| 616 fprintf(stderr, "Error initializing processor.\n"); | 616 fprintf(stderr, "Error initializing processor.\n"); |
| 617 return 1; | 617 return 1; |
| 618 } | 618 } |
| 619 if (!ProcessEntries(&processor, kSampleSize, kSampleRequests)) | 619 if (!ProcessEntries(&processor, kSampleSize, kSampleRequests)) |
| 620 return 1; | 620 return 1; |
| 621 PrintMap(&output); | 621 PrintMap(&output); |
| 622 } | 622 } |
| OLD | NEW |