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

Side by Side Diff: samples/process.cc

Issue 2741683004: [rename] Rename internal field to embedder field. (Closed)
Patch Set: DEPRECATE_SOON(GetInternalField) Created 3 years, 9 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
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 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 338
339 // Create an empty map wrapper. 339 // Create an empty map wrapper.
340 Local<Object> result = 340 Local<Object> result =
341 templ->NewInstance(GetIsolate()->GetCurrentContext()).ToLocalChecked(); 341 templ->NewInstance(GetIsolate()->GetCurrentContext()).ToLocalChecked();
342 342
343 // Wrap the raw C++ pointer in an External so it can be referenced 343 // Wrap the raw C++ pointer in an External so it can be referenced
344 // from within JavaScript. 344 // from within JavaScript.
345 Local<External> map_ptr = External::New(GetIsolate(), obj); 345 Local<External> map_ptr = External::New(GetIsolate(), obj);
346 346
347 // Store the map pointer in the JavaScript wrapper. 347 // Store the map pointer in the JavaScript wrapper.
348 result->SetInternalField(0, map_ptr); 348 result->SetEmbedderField(0, map_ptr);
349 349
350 // Return the result through the current handle scope. Since each 350 // Return the result through the current handle scope. Since each
351 // of these handles will go away when the handle scope is deleted 351 // of these handles will go away when the handle scope is deleted
352 // we need to call Close to let one, the result, escape into the 352 // we need to call Close to let one, the result, escape into the
353 // outer handle scope. 353 // outer handle scope.
354 return handle_scope.Escape(result); 354 return handle_scope.Escape(result);
355 } 355 }
356 356
357 357
358 // Utility function that extracts the C++ map pointer from a wrapper 358 // Utility function that extracts the C++ map pointer from a wrapper
359 // object. 359 // object.
360 map<string, string>* JsHttpRequestProcessor::UnwrapMap(Local<Object> obj) { 360 map<string, string>* JsHttpRequestProcessor::UnwrapMap(Local<Object> obj) {
361 Local<External> field = Local<External>::Cast(obj->GetInternalField(0)); 361 Local<External> field = Local<External>::Cast(obj->GetEmbedderField(0));
362 void* ptr = field->Value(); 362 void* ptr = field->Value();
363 return static_cast<map<string, string>*>(ptr); 363 return static_cast<map<string, string>*>(ptr);
364 } 364 }
365 365
366 366
367 // Convert a JavaScript string to a std::string. To not bother too 367 // Convert a JavaScript string to a std::string. To not bother too
368 // much with string encodings we just use ascii. 368 // much with string encodings we just use ascii.
369 string ObjectToString(Local<Value> value) { 369 string ObjectToString(Local<Value> value) {
370 String::Utf8Value utf8_value(value); 370 String::Utf8Value utf8_value(value);
371 return string(*utf8_value); 371 return string(*utf8_value);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 // Return the value; any non-empty handle will work. 414 // Return the value; any non-empty handle will work.
415 info.GetReturnValue().Set(value_obj); 415 info.GetReturnValue().Set(value_obj);
416 } 416 }
417 417
418 418
419 Local<ObjectTemplate> JsHttpRequestProcessor::MakeMapTemplate( 419 Local<ObjectTemplate> JsHttpRequestProcessor::MakeMapTemplate(
420 Isolate* isolate) { 420 Isolate* isolate) {
421 EscapableHandleScope handle_scope(isolate); 421 EscapableHandleScope handle_scope(isolate);
422 422
423 Local<ObjectTemplate> result = ObjectTemplate::New(isolate); 423 Local<ObjectTemplate> result = ObjectTemplate::New(isolate);
424 result->SetInternalFieldCount(1); 424 result->SetEmbedderFieldCount(1);
425 result->SetHandler(NamedPropertyHandlerConfiguration(MapGet, MapSet)); 425 result->SetHandler(NamedPropertyHandlerConfiguration(MapGet, MapSet));
426 426
427 // Again, return the result through the current handle scope. 427 // Again, return the result through the current handle scope.
428 return handle_scope.Escape(result); 428 return handle_scope.Escape(result);
429 } 429 }
430 430
431 431
432 // ------------------------------------------- 432 // -------------------------------------------
433 // --- A c c e s s i n g R e q u e s t s --- 433 // --- A c c e s s i n g R e q u e s t s ---
434 // ------------------------------------------- 434 // -------------------------------------------
(...skipping 17 matching lines...) Expand all
452 452
453 // Create an empty http request wrapper. 453 // Create an empty http request wrapper.
454 Local<Object> result = 454 Local<Object> result =
455 templ->NewInstance(GetIsolate()->GetCurrentContext()).ToLocalChecked(); 455 templ->NewInstance(GetIsolate()->GetCurrentContext()).ToLocalChecked();
456 456
457 // Wrap the raw C++ pointer in an External so it can be referenced 457 // Wrap the raw C++ pointer in an External so it can be referenced
458 // from within JavaScript. 458 // from within JavaScript.
459 Local<External> request_ptr = External::New(GetIsolate(), request); 459 Local<External> request_ptr = External::New(GetIsolate(), request);
460 460
461 // Store the request pointer in the JavaScript wrapper. 461 // Store the request pointer in the JavaScript wrapper.
462 result->SetInternalField(0, request_ptr); 462 result->SetEmbedderField(0, request_ptr);
463 463
464 // Return the result through the current handle scope. Since each 464 // Return the result through the current handle scope. Since each
465 // of these handles will go away when the handle scope is deleted 465 // of these handles will go away when the handle scope is deleted
466 // we need to call Close to let one, the result, escape into the 466 // we need to call Close to let one, the result, escape into the
467 // outer handle scope. 467 // outer handle scope.
468 return handle_scope.Escape(result); 468 return handle_scope.Escape(result);
469 } 469 }
470 470
471 471
472 /** 472 /**
473 * Utility function that extracts the C++ http request object from a 473 * Utility function that extracts the C++ http request object from a
474 * wrapper object. 474 * wrapper object.
475 */ 475 */
476 HttpRequest* JsHttpRequestProcessor::UnwrapRequest(Local<Object> obj) { 476 HttpRequest* JsHttpRequestProcessor::UnwrapRequest(Local<Object> obj) {
477 Local<External> field = Local<External>::Cast(obj->GetInternalField(0)); 477 Local<External> field = Local<External>::Cast(obj->GetEmbedderField(0));
478 void* ptr = field->Value(); 478 void* ptr = field->Value();
479 return static_cast<HttpRequest*>(ptr); 479 return static_cast<HttpRequest*>(ptr);
480 } 480 }
481 481
482 482
483 void JsHttpRequestProcessor::GetPath(Local<String> name, 483 void JsHttpRequestProcessor::GetPath(Local<String> name,
484 const PropertyCallbackInfo<Value>& info) { 484 const PropertyCallbackInfo<Value>& info) {
485 // Extract the C++ request object from the JavaScript wrapper. 485 // Extract the C++ request object from the JavaScript wrapper.
486 HttpRequest* request = UnwrapRequest(info.Holder()); 486 HttpRequest* request = UnwrapRequest(info.Holder());
487 487
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 NewStringType::kNormal, 529 NewStringType::kNormal,
530 static_cast<int>(path.length())).ToLocalChecked()); 530 static_cast<int>(path.length())).ToLocalChecked());
531 } 531 }
532 532
533 533
534 Local<ObjectTemplate> JsHttpRequestProcessor::MakeRequestTemplate( 534 Local<ObjectTemplate> JsHttpRequestProcessor::MakeRequestTemplate(
535 Isolate* isolate) { 535 Isolate* isolate) {
536 EscapableHandleScope handle_scope(isolate); 536 EscapableHandleScope handle_scope(isolate);
537 537
538 Local<ObjectTemplate> result = ObjectTemplate::New(isolate); 538 Local<ObjectTemplate> result = ObjectTemplate::New(isolate);
539 result->SetInternalFieldCount(1); 539 result->SetEmbedderFieldCount(1);
540 540
541 // Add accessors for each of the fields of the request. 541 // Add accessors for each of the fields of the request.
542 result->SetAccessor( 542 result->SetAccessor(
543 String::NewFromUtf8(isolate, "path", NewStringType::kInternalized) 543 String::NewFromUtf8(isolate, "path", NewStringType::kInternalized)
544 .ToLocalChecked(), 544 .ToLocalChecked(),
545 GetPath); 545 GetPath);
546 result->SetAccessor( 546 result->SetAccessor(
547 String::NewFromUtf8(isolate, "referrer", NewStringType::kInternalized) 547 String::NewFromUtf8(isolate, "referrer", NewStringType::kInternalized)
548 .ToLocalChecked(), 548 .ToLocalChecked(),
549 GetReferrer); 549 GetReferrer);
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 JsHttpRequestProcessor processor(isolate, source); 702 JsHttpRequestProcessor processor(isolate, source);
703 map<string, string> output; 703 map<string, string> output;
704 if (!processor.Initialize(&options, &output)) { 704 if (!processor.Initialize(&options, &output)) {
705 fprintf(stderr, "Error initializing processor.\n"); 705 fprintf(stderr, "Error initializing processor.\n");
706 return 1; 706 return 1;
707 } 707 }
708 if (!ProcessEntries(platform, &processor, kSampleSize, kSampleRequests)) 708 if (!ProcessEntries(platform, &processor, kSampleSize, kSampleRequests))
709 return 1; 709 return 1;
710 PrintMap(&output); 710 PrintMap(&output);
711 } 711 }
OLDNEW
« include/v8-experimental.h ('K') | « include/v8-util.h ('k') | src/api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698