Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(633)

Side by Side Diff: samples/process.cc

Issue 12033011: Add Isolate parameter to Persistent class. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Added explicit Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « samples/lineprocessor.cc ('k') | samples/shell.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 const AccessorInfo& info); 109 const AccessorInfo& info);
110 110
111 // Callbacks that access maps 111 // Callbacks that access maps
112 static Handle<Value> MapGet(Local<String> name, const AccessorInfo& info); 112 static Handle<Value> MapGet(Local<String> name, const AccessorInfo& info);
113 static Handle<Value> MapSet(Local<String> name, 113 static Handle<Value> MapSet(Local<String> name,
114 Local<Value> value, 114 Local<Value> value,
115 const AccessorInfo& info); 115 const AccessorInfo& info);
116 116
117 // Utility methods for wrapping C++ objects as JavaScript objects, 117 // Utility methods for wrapping C++ objects as JavaScript objects,
118 // and going back again. 118 // and going back again.
119 static Handle<Object> WrapMap(map<string, string>* obj); 119 Handle<Object> WrapMap(map<string, string>* obj);
120 static map<string, string>* UnwrapMap(Handle<Object> obj); 120 static map<string, string>* UnwrapMap(Handle<Object> obj);
121 static Handle<Object> WrapRequest(HttpRequest* obj); 121 Handle<Object> WrapRequest(HttpRequest* obj);
122 static HttpRequest* UnwrapRequest(Handle<Object> obj); 122 static HttpRequest* UnwrapRequest(Handle<Object> obj);
123 123
124 Isolate* GetIsolate() { return context_->GetIsolate(); }
125
124 Handle<String> script_; 126 Handle<String> script_;
125 Persistent<Context> context_; 127 Persistent<Context> context_;
126 Persistent<Function> process_; 128 Persistent<Function> process_;
127 static Persistent<ObjectTemplate> request_template_; 129 static Persistent<ObjectTemplate> request_template_;
128 static Persistent<ObjectTemplate> map_template_; 130 static Persistent<ObjectTemplate> map_template_;
129 }; 131 };
130 132
131 // ------------------------- 133 // -------------------------
132 // --- P r o c e s s o r --- 134 // --- P r o c e s s o r ---
133 // ------------------------- 135 // -------------------------
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 182
181 // If there is no Process function, or if it is not a function, 183 // If there is no Process function, or if it is not a function,
182 // bail out 184 // bail out
183 if (!process_val->IsFunction()) return false; 185 if (!process_val->IsFunction()) return false;
184 186
185 // It is a function; cast it to a Function 187 // It is a function; cast it to a Function
186 Handle<Function> process_fun = Handle<Function>::Cast(process_val); 188 Handle<Function> process_fun = Handle<Function>::Cast(process_val);
187 189
188 // Store the function in a Persistent handle, since we also want 190 // Store the function in a Persistent handle, since we also want
189 // that to remain after this call returns 191 // that to remain after this call returns
190 process_ = Persistent<Function>::New(process_fun); 192 process_ = Persistent<Function>::New(GetIsolate(), process_fun);
191 193
192 // All done; all went well 194 // All done; all went well
193 return true; 195 return true;
194 } 196 }
195 197
196 198
197 bool JsHttpRequestProcessor::ExecuteScript(Handle<String> script) { 199 bool JsHttpRequestProcessor::ExecuteScript(Handle<String> script) {
198 HandleScope handle_scope; 200 HandleScope handle_scope;
199 201
200 // We're just about to compile the script; set up an error handler to 202 // We're just about to compile the script; set up an error handler to
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 } else { 268 } else {
267 return true; 269 return true;
268 } 270 }
269 } 271 }
270 272
271 273
272 JsHttpRequestProcessor::~JsHttpRequestProcessor() { 274 JsHttpRequestProcessor::~JsHttpRequestProcessor() {
273 // Dispose the persistent handles. When noone else has any 275 // Dispose the persistent handles. When noone else has any
274 // references to the objects stored in the handles they will be 276 // references to the objects stored in the handles they will be
275 // automatically reclaimed. 277 // automatically reclaimed.
276 context_.Dispose(); 278 v8::Isolate* isolate = GetIsolate();
277 process_.Dispose(); 279 context_.Dispose(isolate);
280 process_.Dispose(isolate);
278 } 281 }
279 282
280 283
281 Persistent<ObjectTemplate> JsHttpRequestProcessor::request_template_; 284 Persistent<ObjectTemplate> JsHttpRequestProcessor::request_template_;
282 Persistent<ObjectTemplate> JsHttpRequestProcessor::map_template_; 285 Persistent<ObjectTemplate> JsHttpRequestProcessor::map_template_;
283 286
284 287
285 // ----------------------------------- 288 // -----------------------------------
286 // --- A c c e s s i n g M a p s --- 289 // --- A c c e s s i n g M a p s ---
287 // ----------------------------------- 290 // -----------------------------------
288 291
289 // Utility function that wraps a C++ http request object in a 292 // Utility function that wraps a C++ http request object in a
290 // JavaScript object. 293 // JavaScript object.
291 Handle<Object> JsHttpRequestProcessor::WrapMap(map<string, string>* obj) { 294 Handle<Object> JsHttpRequestProcessor::WrapMap(map<string, string>* obj) {
292 // Handle scope for temporary handles. 295 // Handle scope for temporary handles.
293 HandleScope handle_scope; 296 HandleScope handle_scope;
294 297
295 // Fetch the template for creating JavaScript map wrappers. 298 // Fetch the template for creating JavaScript map wrappers.
296 // It only has to be created once, which we do on demand. 299 // It only has to be created once, which we do on demand.
297 if (map_template_.IsEmpty()) { 300 if (map_template_.IsEmpty()) {
298 Handle<ObjectTemplate> raw_template = MakeMapTemplate(); 301 Handle<ObjectTemplate> raw_template = MakeMapTemplate();
299 map_template_ = Persistent<ObjectTemplate>::New(raw_template); 302 map_template_ = Persistent<ObjectTemplate>::New(GetIsolate(), raw_template);
300 } 303 }
301 Handle<ObjectTemplate> templ = map_template_; 304 Handle<ObjectTemplate> templ = map_template_;
302 305
303 // Create an empty map wrapper. 306 // Create an empty map wrapper.
304 Handle<Object> result = templ->NewInstance(); 307 Handle<Object> result = templ->NewInstance();
305 308
306 // Wrap the raw C++ pointer in an External so it can be referenced 309 // Wrap the raw C++ pointer in an External so it can be referenced
307 // from within JavaScript. 310 // from within JavaScript.
308 Handle<External> map_ptr = External::New(obj); 311 Handle<External> map_ptr = External::New(obj);
309 312
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 * JavaScript object. 397 * JavaScript object.
395 */ 398 */
396 Handle<Object> JsHttpRequestProcessor::WrapRequest(HttpRequest* request) { 399 Handle<Object> JsHttpRequestProcessor::WrapRequest(HttpRequest* request) {
397 // Handle scope for temporary handles. 400 // Handle scope for temporary handles.
398 HandleScope handle_scope; 401 HandleScope handle_scope;
399 402
400 // Fetch the template for creating JavaScript http request wrappers. 403 // Fetch the template for creating JavaScript http request wrappers.
401 // It only has to be created once, which we do on demand. 404 // It only has to be created once, which we do on demand.
402 if (request_template_.IsEmpty()) { 405 if (request_template_.IsEmpty()) {
403 Handle<ObjectTemplate> raw_template = MakeRequestTemplate(); 406 Handle<ObjectTemplate> raw_template = MakeRequestTemplate();
404 request_template_ = Persistent<ObjectTemplate>::New(raw_template); 407 request_template_ =
408 Persistent<ObjectTemplate>::New(GetIsolate(), raw_template);
405 } 409 }
406 Handle<ObjectTemplate> templ = request_template_; 410 Handle<ObjectTemplate> templ = request_template_;
407 411
408 // Create an empty http request wrapper. 412 // Create an empty http request wrapper.
409 Handle<Object> result = templ->NewInstance(); 413 Handle<Object> result = templ->NewInstance();
410 414
411 // Wrap the raw C++ pointer in an External so it can be referenced 415 // Wrap the raw C++ pointer in an External so it can be referenced
412 // from within JavaScript. 416 // from within JavaScript.
413 Handle<External> request_ptr = External::New(request); 417 Handle<External> request_ptr = External::New(request);
414 418
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 JsHttpRequestProcessor processor(source); 617 JsHttpRequestProcessor processor(source);
614 map<string, string> output; 618 map<string, string> output;
615 if (!processor.Initialize(&options, &output)) { 619 if (!processor.Initialize(&options, &output)) {
616 fprintf(stderr, "Error initializing processor.\n"); 620 fprintf(stderr, "Error initializing processor.\n");
617 return 1; 621 return 1;
618 } 622 }
619 if (!ProcessEntries(&processor, kSampleSize, kSampleRequests)) 623 if (!ProcessEntries(&processor, kSampleSize, kSampleRequests))
620 return 1; 624 return 1;
621 PrintMap(&output); 625 PrintMap(&output);
622 } 626 }
OLDNEW
« no previous file with comments | « samples/lineprocessor.cc ('k') | samples/shell.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698