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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 // Create a template for the global object where we set the | 161 // Create a template for the global object where we set the |
162 // built-in global functions. | 162 // built-in global functions. |
163 Handle<ObjectTemplate> global = ObjectTemplate::New(); | 163 Handle<ObjectTemplate> global = ObjectTemplate::New(); |
164 global->Set(String::New("log"), FunctionTemplate::New(LogCallback)); | 164 global->Set(String::New("log"), FunctionTemplate::New(LogCallback)); |
165 | 165 |
166 // Each processor gets its own context so different processors don't | 166 // Each processor gets its own context so different processors don't |
167 // affect each other. Context::New returns a persistent handle which | 167 // affect each other. Context::New returns a persistent handle which |
168 // is what we need for the reference to remain after we return from | 168 // is what we need for the reference to remain after we return from |
169 // this method. That persistent handle has to be disposed in the | 169 // this method. That persistent handle has to be disposed in the |
170 // destructor. | 170 // destructor. |
171 context_.Reset(GetIsolate(), Context::New(GetIsolate(), NULL, global)); | 171 v8::Handle<v8::Context> context = Context::New(GetIsolate(), NULL, global); |
| 172 context_.Reset(GetIsolate(), context); |
172 | 173 |
173 // Enter the new context so all the following operations take place | 174 // Enter the new context so all the following operations take place |
174 // within it. | 175 // within it. |
175 Context::Scope context_scope(GetIsolate(), context_); | 176 Context::Scope context_scope(context); |
176 | 177 |
177 // Make the options mapping available within the context | 178 // Make the options mapping available within the context |
178 if (!InstallMaps(opts, output)) | 179 if (!InstallMaps(opts, output)) |
179 return false; | 180 return false; |
180 | 181 |
181 // Compile and run the script | 182 // Compile and run the script |
182 if (!ExecuteScript(script_)) | 183 if (!ExecuteScript(script_)) |
183 return false; | 184 return false; |
184 | 185 |
185 // The script compiled and ran correctly. Now we fetch out the | 186 // The script compiled and ran correctly. Now we fetch out the |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 context_->Global()->Set(String::New("output"), output_obj); | 247 context_->Global()->Set(String::New("output"), output_obj); |
247 | 248 |
248 return true; | 249 return true; |
249 } | 250 } |
250 | 251 |
251 | 252 |
252 bool JsHttpRequestProcessor::Process(HttpRequest* request) { | 253 bool JsHttpRequestProcessor::Process(HttpRequest* request) { |
253 // Create a handle scope to keep the temporary object references. | 254 // Create a handle scope to keep the temporary object references. |
254 HandleScope handle_scope(GetIsolate()); | 255 HandleScope handle_scope(GetIsolate()); |
255 | 256 |
| 257 v8::Local<v8::Context> context = |
| 258 v8::Local<v8::Context>::New(GetIsolate(), context_); |
| 259 |
256 // Enter this processor's context so all the remaining operations | 260 // Enter this processor's context so all the remaining operations |
257 // take place there | 261 // take place there |
258 Context::Scope context_scope(GetIsolate(), context_); | 262 Context::Scope context_scope(context); |
259 | 263 |
260 // Wrap the C++ request object in a JavaScript wrapper | 264 // Wrap the C++ request object in a JavaScript wrapper |
261 Handle<Object> request_obj = WrapRequest(request); | 265 Handle<Object> request_obj = WrapRequest(request); |
262 | 266 |
263 // Set up an exception handler before calling the Process function | 267 // Set up an exception handler before calling the Process function |
264 TryCatch try_catch; | 268 TryCatch try_catch; |
265 | 269 |
266 // Invoke the process function, giving the global object as 'this' | 270 // Invoke the process function, giving the global object as 'this' |
267 // and one argument, the request. | 271 // and one argument, the request. |
268 const int argc = 1; | 272 const int argc = 1; |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 JsHttpRequestProcessor processor(isolate, source); | 633 JsHttpRequestProcessor processor(isolate, source); |
630 map<string, string> output; | 634 map<string, string> output; |
631 if (!processor.Initialize(&options, &output)) { | 635 if (!processor.Initialize(&options, &output)) { |
632 fprintf(stderr, "Error initializing processor.\n"); | 636 fprintf(stderr, "Error initializing processor.\n"); |
633 return 1; | 637 return 1; |
634 } | 638 } |
635 if (!ProcessEntries(&processor, kSampleSize, kSampleRequests)) | 639 if (!ProcessEntries(&processor, kSampleSize, kSampleRequests)) |
636 return 1; | 640 return 1; |
637 PrintMap(&output); | 641 PrintMap(&output); |
638 } | 642 } |
OLD | NEW |