33 #ifdef COMPRESS_STARTUP_DATA_BZ2
34 #error Using compressed startup data is not supported for this sample
51 virtual const string& Path() = 0;
52 virtual const string& Referrer() = 0;
53 virtual const string& Host() = 0;
54 virtual const string& UserAgent() = 0;
66 virtual bool Initialize(map<string, string>* options,
67 map<string, string>* output) = 0;
72 static void Log(
const char* event);
85 virtual bool Initialize(map<string, string>* opts,
86 map<string, string>* output);
96 bool InstallMaps(map<string, string>* opts, map<string, string>* output);
148 map<string, string>* output) {
155 global->
Set(String::New(
"log"), FunctionTemplate::New(LogCallback));
162 context_ = Context::New(
NULL, global);
169 if (!InstallMaps(opts, output))
173 if (!ExecuteScript(script_))
179 Handle<Value> process_val = context_->Global()->Get(process_name);
197 bool JsHttpRequestProcessor::ExecuteScript(
Handle<String> script) {
206 if (compiled_script.
IsEmpty()) {
226 bool JsHttpRequestProcessor::InstallMaps(map<string, string>* opts,
227 map<string, string>* output) {
234 context_->Global()->Set(String::New(
"options"), opts_obj);
237 context_->Global()->Set(String::New(
"output"), output_obj);
261 Handle<Value> result = process_->Call(context_->Global(), argc, argv);
291 Handle<Object> JsHttpRequestProcessor::WrapMap(map<string, string>* obj) {
297 if (map_template_.IsEmpty()) {
317 return handle_scope.
Close(result);
323 map<string, string>* JsHttpRequestProcessor::UnwrapMap(
Handle<Object> obj) {
325 void* ptr = field->
Value();
326 return static_cast<map<string, string>*
>(ptr);
334 return string(*utf8_value);
341 map<string, string>* obj = UnwrapMap(info.
Holder());
347 map<string, string>::iterator iter = obj->find(key);
353 const string& value = (*iter).second;
354 return String::New(value.c_str(),
static_cast<int>(value.length()));
362 map<string, string>* obj = UnwrapMap(info.
Holder());
384 return handle_scope.
Close(result);
402 if (request_template_.IsEmpty()) {
422 return handle_scope.
Close(result);
432 void* ptr = field->
Value();
443 const string& path = request->
Path();
446 return String::New(path.c_str(),
static_cast<int>(path.length()));
453 const string& path = request->
Referrer();
454 return String::New(path.c_str(),
static_cast<int>(path.length()));
461 const string& path = request->
Host();
462 return String::New(path.c_str(),
static_cast<int>(path.length()));
469 const string& path = request->
UserAgent();
470 return String::New(path.c_str(),
static_cast<int>(path.length()));
481 result->
SetAccessor(String::NewSymbol(
"path"), GetPath);
482 result->
SetAccessor(String::NewSymbol(
"referrer"), GetReferrer);
483 result->
SetAccessor(String::NewSymbol(
"host"), GetHost);
484 result->
SetAccessor(String::NewSymbol(
"userAgent"), GetUserAgent);
487 return handle_scope.
Close(result);
495 printf(
"Logged: %s\n", event);
505 const string& referrer,
507 const string& user_agent);
508 virtual const string&
Path() {
return path_; }
509 virtual const string&
Referrer() {
return referrer_; }
510 virtual const string&
Host() {
return host_; }
511 virtual const string&
UserAgent() {
return user_agent_; }
521 const string& referrer,
523 const string& user_agent)
527 user_agent_(user_agent) { }
532 map<string, string>& options,
534 for (
int i = 1; i < argc; i++) {
535 string arg = argv[i];
536 size_t index = arg.find(
'=', 0);
537 if (index == string::npos) {
540 string key = arg.substr(0, index);
541 string value = arg.substr(index+1);
542 options[key] = value;
550 FILE* file = fopen(name.c_str(),
"rb");
553 fseek(file, 0, SEEK_END);
554 int size = ftell(file);
557 char* chars =
new char[size + 1];
559 for (
int i = 0; i < size;) {
560 int read =
static_cast<int>(fread(&chars[i], 1, size - i, file));
583 for (
int i = 0; i < count; i++) {
584 if (!processor->
Process(&reqs[i]))
592 for (map<string, string>::iterator i = m->begin(); i != m->end(); i++) {
593 pair<string, string> entry = *i;
594 printf(
"%s: %s\n", entry.first.c_str(), entry.second.c_str());
599 int main(
int argc,
char* argv[]) {
600 map<string, string> options;
604 fprintf(stderr,
"No script was specified.\n");
610 fprintf(stderr,
"Error reading '%s'.\n", file.c_str());
614 map<string, string> output;
615 if (!processor.
Initialize(&options, &output)) {
616 fprintf(stderr,
"Error initializing processor.\n");
virtual bool Process(HttpRequest *req)
Handle< String > ReadFile(const string &name)
bool ProcessEntries(HttpRequestProcessor *processor, int count, StringHttpRequest *reqs)
Local< Value > Exception() const
virtual const string & Referrer()
virtual ~HttpRequestProcessor()
Local< Object > NewInstance()
virtual const string & Path()=0
virtual ~JsHttpRequestProcessor()
string ObjectToString(Local< Value > value)
Local< Value > GetInternalField(int index)
void Set(Handle< String > name, Handle< Data > value, PropertyAttribute attributes=None)
virtual const string & UserAgent()=0
virtual const string & Path()
V8EXPORT void SetInternalField(int index, Handle< Value > value)
Local< Object > Holder() const
V8EXPORT void * Value() const
int main(int argc, char *argv[])
virtual bool Process(HttpRequest *req)=0
void SetAccessor(Handle< String > name, AccessorGetter getter, AccessorSetter setter=0, Handle< Value > data=Handle< Value >(), AccessControl settings=DEFAULT, PropertyAttribute attribute=None, Handle< AccessorSignature > signature=Handle< AccessorSignature >())
void SetInternalFieldCount(int value)
void PrintMap(map< string, string > *m)
virtual bool Initialize(map< string, string > *opts, map< string, string > *output)
void ParseOptions(int argc, char *argv[], map< string, string > &options, string *file)
static void Log(const char *event)
V8EXPORT bool IsFunction() const
virtual const string & Referrer()=0
void SetNamedPropertyHandler(NamedPropertyGetter getter, NamedPropertySetter setter=0, NamedPropertyQuery query=0, NamedPropertyDeleter deleter=0, NamedPropertyEnumerator enumerator=0, Handle< Value > data=Handle< Value >())
virtual const string & Host()
StringHttpRequest(const string &path, const string &referrer, const string &host, const string &user_agent)
virtual const string & Host()=0
activate correct semantics for inheriting readonliness enable harmony semantics for typeof enable harmony enable harmony proxies enable all harmony harmony_scoping harmony_proxies harmony_scoping tracks arrays with only smi values automatically unbox arrays of doubles use crankshaft use hydrogen range analysis use hydrogen global value numbering use function inlining maximum number of AST nodes considered for a single inlining loop invariant code motion print statistics for hydrogen trace generated IR for specified phases trace register allocator trace range analysis trace representation types environment for every instruction put a break point before deoptimizing polymorphic inlining perform array bounds checks elimination use dead code elimination trace on stack replacement optimize closures cache optimized code for closures functions with arguments object loop weight for representation inference allow uint32 values on optimize frames if they are used only in safe operations track parallel recompilation enable all profiler experiments number of stack frames inspected by the profiler call recompile stub directly when self optimizing trigger profiler ticks based on counting instead of timing weight back edges by jump distance for interrupt triggering percentage of ICs that must have type info to allow optimization watch_ic_patching retry_self_opt interrupt_at_exit extra verbose compilation tracing generate extra emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of SAHF instruction if enable use of VFP3 instructions if available this implies enabling ARMv7 and VFP2 enable use of VFP2 instructions if available enable use of SDIV and UDIV instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of MIPS FPU instructions if NULL
StringHttpRequest kSampleRequests[kSampleSize]
Local< T > Close(Handle< T > value)
Handle< Primitive > V8EXPORT Undefined()
virtual const string & UserAgent()
JsHttpRequestProcessor(Handle< String > script)