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

Side by Side Diff: samples/process.cc

Issue 12729023: first step to remove unsafe handles (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: issue with debug build Created 7 years, 7 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
11 // with the distribution. 11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its 12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived 13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission. 14 // from this software without specific prior written permission.
15 // 15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 // TODO(dcarney): remove this
29 #define V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR
30 #define V8_ALLOW_ACCESS_TO_PERSISTENT_IMPLICIT
31 #define V8_ALLOW_ACCESS_TO_PERSISTENT_ARROW
32
28 #include <v8.h> 33 #include <v8.h>
29 34
30 #include <string> 35 #include <string>
31 #include <map> 36 #include <map>
32 37
33 #ifdef COMPRESS_STARTUP_DATA_BZ2 38 #ifdef COMPRESS_STARTUP_DATA_BZ2
34 #error Using compressed startup data is not supported for this sample 39 #error Using compressed startup data is not supported for this sample
35 #endif 40 #endif
36 41
37 using namespace std; 42 using namespace std;
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 165
161 // Each processor gets its own context so different processors don't 166 // Each processor gets its own context so different processors don't
162 // affect each other. Context::New returns a persistent handle which 167 // affect each other. Context::New returns a persistent handle which
163 // 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
164 // this method. That persistent handle has to be disposed in the 169 // this method. That persistent handle has to be disposed in the
165 // destructor. 170 // destructor.
166 context_ = Context::New(NULL, global); 171 context_ = Context::New(NULL, global);
167 172
168 // Enter the new context so all the following operations take place 173 // Enter the new context so all the following operations take place
169 // within it. 174 // within it.
170 Context::Scope context_scope(context_); 175 Context::Scope context_scope(GetIsolate(), context_);
171 176
172 // Make the options mapping available within the context 177 // Make the options mapping available within the context
173 if (!InstallMaps(opts, output)) 178 if (!InstallMaps(opts, output))
174 return false; 179 return false;
175 180
176 // Compile and run the script 181 // Compile and run the script
177 if (!ExecuteScript(script_)) 182 if (!ExecuteScript(script_))
178 return false; 183 return false;
179 184
180 // The script compiled and ran correctly. Now we fetch out the 185 // The script compiled and ran correctly. Now we fetch out the
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 return true; 248 return true;
244 } 249 }
245 250
246 251
247 bool JsHttpRequestProcessor::Process(HttpRequest* request) { 252 bool JsHttpRequestProcessor::Process(HttpRequest* request) {
248 // Create a handle scope to keep the temporary object references. 253 // Create a handle scope to keep the temporary object references.
249 HandleScope handle_scope(GetIsolate()); 254 HandleScope handle_scope(GetIsolate());
250 255
251 // Enter this processor's context so all the remaining operations 256 // Enter this processor's context so all the remaining operations
252 // take place there 257 // take place there
253 Context::Scope context_scope(context_); 258 Context::Scope context_scope(GetIsolate(), context_);
254 259
255 // Wrap the C++ request object in a JavaScript wrapper 260 // Wrap the C++ request object in a JavaScript wrapper
256 Handle<Object> request_obj = WrapRequest(request); 261 Handle<Object> request_obj = WrapRequest(request);
257 262
258 // Set up an exception handler before calling the Process function 263 // Set up an exception handler before calling the Process function
259 TryCatch try_catch; 264 TryCatch try_catch;
260 265
261 // Invoke the process function, giving the global object as 'this' 266 // Invoke the process function, giving the global object as 'this'
262 // and one argument, the request. 267 // and one argument, the request.
263 const int argc = 1; 268 const int argc = 1;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 Handle<Object> JsHttpRequestProcessor::WrapMap(map<string, string>* obj) { 301 Handle<Object> JsHttpRequestProcessor::WrapMap(map<string, string>* obj) {
297 // Handle scope for temporary handles. 302 // Handle scope for temporary handles.
298 HandleScope handle_scope(GetIsolate()); 303 HandleScope handle_scope(GetIsolate());
299 304
300 // Fetch the template for creating JavaScript map wrappers. 305 // Fetch the template for creating JavaScript map wrappers.
301 // It only has to be created once, which we do on demand. 306 // It only has to be created once, which we do on demand.
302 if (map_template_.IsEmpty()) { 307 if (map_template_.IsEmpty()) {
303 Handle<ObjectTemplate> raw_template = MakeMapTemplate(GetIsolate()); 308 Handle<ObjectTemplate> raw_template = MakeMapTemplate(GetIsolate());
304 map_template_ = Persistent<ObjectTemplate>::New(GetIsolate(), raw_template); 309 map_template_ = Persistent<ObjectTemplate>::New(GetIsolate(), raw_template);
305 } 310 }
306 Handle<ObjectTemplate> templ = map_template_; 311 Handle<ObjectTemplate> templ =
312 Local<ObjectTemplate>::New(GetIsolate(), map_template_);
307 313
308 // Create an empty map wrapper. 314 // Create an empty map wrapper.
309 Handle<Object> result = templ->NewInstance(); 315 Handle<Object> result = templ->NewInstance();
310 316
311 // Wrap the raw C++ pointer in an External so it can be referenced 317 // Wrap the raw C++ pointer in an External so it can be referenced
312 // from within JavaScript. 318 // from within JavaScript.
313 Handle<External> map_ptr = External::New(obj); 319 Handle<External> map_ptr = External::New(obj);
314 320
315 // Store the map pointer in the JavaScript wrapper. 321 // Store the map pointer in the JavaScript wrapper.
316 result->SetInternalField(0, map_ptr); 322 result->SetInternalField(0, map_ptr);
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 // Handle scope for temporary handles. 409 // Handle scope for temporary handles.
404 HandleScope handle_scope(GetIsolate()); 410 HandleScope handle_scope(GetIsolate());
405 411
406 // Fetch the template for creating JavaScript http request wrappers. 412 // Fetch the template for creating JavaScript http request wrappers.
407 // It only has to be created once, which we do on demand. 413 // It only has to be created once, which we do on demand.
408 if (request_template_.IsEmpty()) { 414 if (request_template_.IsEmpty()) {
409 Handle<ObjectTemplate> raw_template = MakeRequestTemplate(GetIsolate()); 415 Handle<ObjectTemplate> raw_template = MakeRequestTemplate(GetIsolate());
410 request_template_ = 416 request_template_ =
411 Persistent<ObjectTemplate>::New(GetIsolate(), raw_template); 417 Persistent<ObjectTemplate>::New(GetIsolate(), raw_template);
412 } 418 }
413 Handle<ObjectTemplate> templ = request_template_; 419 Handle<ObjectTemplate> templ =
420 Local<ObjectTemplate>::New(GetIsolate(), request_template_);
414 421
415 // Create an empty http request wrapper. 422 // Create an empty http request wrapper.
416 Handle<Object> result = templ->NewInstance(); 423 Handle<Object> result = templ->NewInstance();
417 424
418 // Wrap the raw C++ pointer in an External so it can be referenced 425 // Wrap the raw C++ pointer in an External so it can be referenced
419 // from within JavaScript. 426 // from within JavaScript.
420 Handle<External> request_ptr = External::New(request); 427 Handle<External> request_ptr = External::New(request);
421 428
422 // Store the request pointer in the JavaScript wrapper. 429 // Store the request pointer in the JavaScript wrapper.
423 result->SetInternalField(0, request_ptr); 430 result->SetInternalField(0, request_ptr);
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 JsHttpRequestProcessor processor(isolate, source); 629 JsHttpRequestProcessor processor(isolate, source);
623 map<string, string> output; 630 map<string, string> output;
624 if (!processor.Initialize(&options, &output)) { 631 if (!processor.Initialize(&options, &output)) {
625 fprintf(stderr, "Error initializing processor.\n"); 632 fprintf(stderr, "Error initializing processor.\n");
626 return 1; 633 return 1;
627 } 634 }
628 if (!ProcessEntries(&processor, kSampleSize, kSampleRequests)) 635 if (!ProcessEntries(&processor, kSampleSize, kSampleRequests))
629 return 1; 636 return 1;
630 PrintMap(&output); 637 PrintMap(&output);
631 } 638 }
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