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

Side by Side Diff: test/cctest/test-global-handles.cc

Issue 22795004: abstract eternal into class (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 4 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
« src/global-handles.h ('K') | « src/global-handles.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 data.Mutate(0.35); 468 data.Mutate(0.35);
469 // clear everything 469 // clear everything
470 data.RemoveAll(); 470 data.RemoveAll();
471 } 471 }
472 472
473 473
474 TEST(EternalHandles) { 474 TEST(EternalHandles) {
475 CcTest::InitializeVM(); 475 CcTest::InitializeVM();
476 Isolate* isolate = Isolate::Current(); 476 Isolate* isolate = Isolate::Current();
477 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); 477 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate);
478 EternalHandles* eternals = isolate->eternal_handles(); 478 EternalHandles* eternal_handles = isolate->eternal_handles();
479 479
480 // Create a number of handles that will not be on a block boundary 480 // Create a number of handles that will not be on a block boundary
481 const int kArrayLength = 2048-1; 481 const int kArrayLength = 2048-1;
482 int indices[kArrayLength]; 482 int indices[kArrayLength];
483 v8::Eternal<v8::Value> eternals[kArrayLength];
483 484
484 CHECK_EQ(0, eternals->NumberOfHandles()); 485 CHECK_EQ(0, eternal_handles->NumberOfHandles());
485 for (int i = 0; i < kArrayLength; i++) { 486 for (int i = 0; i < kArrayLength; i++) {
486 HandleScope scope(isolate); 487 HandleScope scope(isolate);
487 v8::Local<v8::Object> object = v8::Object::New(); 488 v8::Local<v8::Object> object = v8::Object::New();
488 object->Set(i, v8::Integer::New(i, v8_isolate)); 489 object->Set(i, v8::Integer::New(i, v8_isolate));
489 if (i % 2 == 0) { 490 // Create with internal api
490 // Create with internal api 491 eternal_handles->Create(
491 indices[i] = eternals->Create(isolate, *v8::Utils::OpenHandle(*object)); 492 isolate, *v8::Utils::OpenHandle(*object), &indices[i]);
492 } else { 493 // Create with external api
493 // Create with external api 494 CHECK(!eternals[i].IsSet());
494 indices[i] = object.Eternalize(v8_isolate); 495 eternals[i].Set(v8_isolate, object);
495 } 496 CHECK(eternals[i].IsSet());
496 } 497 }
497 498
498 isolate->heap()->CollectAllAvailableGarbage(); 499 isolate->heap()->CollectAllAvailableGarbage();
499 500
500 for (int i = 0; i < kArrayLength; i++) { 501 for (int i = 0; i < kArrayLength; i++) {
501 for (int j = 0; j < 2; j++) { 502 for (int j = 0; j < 2; j++) {
502 HandleScope scope(isolate); 503 HandleScope scope(isolate);
503 v8::Local<v8::Object> object; 504 v8::Local<v8::Value> local;
504 if (j == 0) { 505 if (j == 0) {
505 // Test internal api 506 // Test internal api
506 v8::Local<v8::Value> local = 507 local = v8::Utils::ToLocal(eternal_handles->Get(indices[i]));
507 v8::Utils::ToLocal(eternals->Get(indices[i]));
508 object = v8::Handle<v8::Object>::Cast(local);
509 } else { 508 } else {
510 // Test external api 509 // Test external api
511 object = v8::Local<v8::Object>::GetEternal(v8_isolate, indices[i]); 510 local = eternals[i].Get(v8_isolate);
512 } 511 }
512 v8::Local<v8::Object> object = v8::Handle<v8::Object>::Cast(local);
513 v8::Local<v8::Value> value = object->Get(i); 513 v8::Local<v8::Value> value = object->Get(i);
514 CHECK(value->IsInt32()); 514 CHECK(value->IsInt32());
515 CHECK_EQ(i, value->Int32Value()); 515 CHECK_EQ(i, value->Int32Value());
516 } 516 }
517 } 517 }
518 518
519 CHECK_EQ(kArrayLength, eternals->NumberOfHandles()); 519 CHECK_EQ(2*kArrayLength, eternal_handles->NumberOfHandles());
520
521 // Create an eternal with via the constructor
rossberg 2013/08/12 15:13:13 Nit: typo?
dcarney 2013/08/13 06:46:24 fixed
522 {
523 HandleScope scope(isolate);
524 v8::Local<v8::Object> object = v8::Object::New();
525 v8::Eternal<v8::Object> eternal(v8_isolate, object);
526 CHECK(eternal.IsSet());
527 CHECK(object == eternal.Get(v8_isolate));
528 }
529
530 CHECK_EQ(2*kArrayLength + 1, eternal_handles->NumberOfHandles());
520 } 531 }
521 532
OLDNEW
« src/global-handles.h ('K') | « src/global-handles.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698