OLD | NEW |
1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 virtual bool Process(HttpRequest* req) = 0; | 70 virtual bool Process(HttpRequest* req) = 0; |
71 | 71 |
72 static void Log(const char* event); | 72 static void Log(const char* event); |
73 }; | 73 }; |
74 | 74 |
75 /** | 75 /** |
76 * An http request processor that is scriptable using JavaScript. | 76 * An http request processor that is scriptable using JavaScript. |
77 */ | 77 */ |
78 class JsHttpRequestProcessor : public HttpRequestProcessor { | 78 class JsHttpRequestProcessor : public HttpRequestProcessor { |
79 public: | 79 public: |
80 | |
81 // Creates a new processor that processes requests by invoking the | 80 // Creates a new processor that processes requests by invoking the |
82 // Process function of the JavaScript script given as an argument. | 81 // Process function of the JavaScript script given as an argument. |
83 explicit JsHttpRequestProcessor(Handle<String> script) : script_(script) { } | 82 explicit JsHttpRequestProcessor(Handle<String> script) : script_(script) { } |
84 virtual ~JsHttpRequestProcessor(); | 83 virtual ~JsHttpRequestProcessor(); |
85 | 84 |
86 virtual bool Initialize(map<string, string>* opts, | 85 virtual bool Initialize(map<string, string>* opts, |
87 map<string, string>* output); | 86 map<string, string>* output); |
88 virtual bool Process(HttpRequest* req); | 87 virtual bool Process(HttpRequest* req); |
89 | 88 |
90 private: | 89 private: |
91 | |
92 // Execute the script associated with this processor and extract the | 90 // Execute the script associated with this processor and extract the |
93 // Process function. Returns true if this succeeded, otherwise false. | 91 // Process function. Returns true if this succeeded, otherwise false. |
94 bool ExecuteScript(Handle<String> script); | 92 bool ExecuteScript(Handle<String> script); |
95 | 93 |
96 // Wrap the options and output map in a JavaScript objects and | 94 // Wrap the options and output map in a JavaScript objects and |
97 // install it in the global namespace as 'options' and 'output'. | 95 // install it in the global namespace as 'options' and 'output'. |
98 bool InstallMaps(map<string, string>* opts, map<string, string>* output); | 96 bool InstallMaps(map<string, string>* opts, map<string, string>* output); |
99 | 97 |
100 // Constructs the template that describes the JavaScript wrapper | 98 // Constructs the template that describes the JavaScript wrapper |
101 // type for requests. | 99 // type for requests. |
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
615 JsHttpRequestProcessor processor(source); | 613 JsHttpRequestProcessor processor(source); |
616 map<string, string> output; | 614 map<string, string> output; |
617 if (!processor.Initialize(&options, &output)) { | 615 if (!processor.Initialize(&options, &output)) { |
618 fprintf(stderr, "Error initializing processor.\n"); | 616 fprintf(stderr, "Error initializing processor.\n"); |
619 return 1; | 617 return 1; |
620 } | 618 } |
621 if (!ProcessEntries(&processor, kSampleSize, kSampleRequests)) | 619 if (!ProcessEntries(&processor, kSampleSize, kSampleRequests)) |
622 return 1; | 620 return 1; |
623 PrintMap(&output); | 621 PrintMap(&output); |
624 } | 622 } |
OLD | NEW |