OLD | NEW |
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 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 reinterpret_cast<HeapObject**>(g2s1.location())); | 314 reinterpret_cast<HeapObject**>(g2s1.location())); |
315 ASSERT(implicit_refs->at(1)->length == 1); | 315 ASSERT(implicit_refs->at(1)->length == 1); |
316 ASSERT(implicit_refs->at(1)->children[0] == g2c1.location()); | 316 ASSERT(implicit_refs->at(1)->children[0] == g2c1.location()); |
317 } | 317 } |
318 | 318 |
319 | 319 |
320 TEST(EternalHandles) { | 320 TEST(EternalHandles) { |
321 CcTest::InitializeVM(); | 321 CcTest::InitializeVM(); |
322 Isolate* isolate = Isolate::Current(); | 322 Isolate* isolate = Isolate::Current(); |
323 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); | 323 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); |
324 EternalHandles* eternals = isolate->eternal_handles(); | 324 EternalHandles* eternal_handles = isolate->eternal_handles(); |
325 | 325 |
326 // Create a number of handles that will not be on a block boundary | 326 // Create a number of handles that will not be on a block boundary |
327 const int kArrayLength = 2048-1; | 327 const int kArrayLength = 2048-1; |
328 int indices[kArrayLength]; | 328 int indices[kArrayLength]; |
| 329 v8::Eternal<v8::Value> eternals[kArrayLength]; |
329 | 330 |
330 CHECK_EQ(0, eternals->NumberOfHandles()); | 331 CHECK_EQ(0, eternal_handles->NumberOfHandles()); |
331 for (int i = 0; i < kArrayLength; i++) { | 332 for (int i = 0; i < kArrayLength; i++) { |
332 HandleScope scope(isolate); | 333 HandleScope scope(isolate); |
333 v8::Local<v8::Object> object = v8::Object::New(); | 334 v8::Local<v8::Object> object = v8::Object::New(); |
334 object->Set(i, v8::Integer::New(i, v8_isolate)); | 335 object->Set(i, v8::Integer::New(i, v8_isolate)); |
335 if (i % 2 == 0) { | 336 // Create with internal api |
336 // Create with internal api | 337 eternal_handles->Create( |
337 indices[i] = eternals->Create(isolate, *v8::Utils::OpenHandle(*object)); | 338 isolate, *v8::Utils::OpenHandle(*object), &indices[i]); |
338 } else { | 339 // Create with external api |
339 // Create with external api | 340 CHECK(!eternals[i].IsEmpty()); |
340 indices[i] = object.Eternalize(v8_isolate); | 341 eternals[i].Set(v8_isolate, object); |
341 } | 342 CHECK(eternals[i].IsEmpty()); |
342 } | 343 } |
343 | 344 |
344 isolate->heap()->CollectAllAvailableGarbage(); | 345 isolate->heap()->CollectAllAvailableGarbage(); |
345 | 346 |
346 for (int i = 0; i < kArrayLength; i++) { | 347 for (int i = 0; i < kArrayLength; i++) { |
347 for (int j = 0; j < 2; j++) { | 348 for (int j = 0; j < 2; j++) { |
348 HandleScope scope(isolate); | 349 HandleScope scope(isolate); |
349 v8::Local<v8::Object> object; | 350 v8::Local<v8::Value> local; |
350 if (j == 0) { | 351 if (j == 0) { |
351 // Test internal api | 352 // Test internal api |
352 v8::Local<v8::Value> local = | 353 local = v8::Utils::ToLocal(eternal_handles->Get(indices[i])); |
353 v8::Utils::ToLocal(eternals->Get(indices[i])); | |
354 object = v8::Handle<v8::Object>::Cast(local); | |
355 } else { | 354 } else { |
356 // Test external api | 355 // Test external api |
357 object = v8::Local<v8::Object>::GetEternal(v8_isolate, indices[i]); | 356 local = eternals[i].Get(v8_isolate); |
358 } | 357 } |
| 358 v8::Local<v8::Object> object = v8::Handle<v8::Object>::Cast(local); |
359 v8::Local<v8::Value> value = object->Get(i); | 359 v8::Local<v8::Value> value = object->Get(i); |
360 CHECK(value->IsInt32()); | 360 CHECK(value->IsInt32()); |
361 CHECK_EQ(i, value->Int32Value()); | 361 CHECK_EQ(i, value->Int32Value()); |
362 } | 362 } |
363 } | 363 } |
364 | 364 |
365 CHECK_EQ(kArrayLength, eternals->NumberOfHandles()); | 365 CHECK_EQ(2*kArrayLength, eternal_handles->NumberOfHandles()); |
| 366 |
| 367 // Create an eternal via the constructor |
| 368 { |
| 369 HandleScope scope(isolate); |
| 370 v8::Local<v8::Object> object = v8::Object::New(); |
| 371 v8::Eternal<v8::Object> eternal(v8_isolate, object); |
| 372 CHECK(eternal.IsEmpty()); |
| 373 CHECK(object == eternal.Get(v8_isolate)); |
| 374 } |
| 375 |
| 376 CHECK_EQ(2*kArrayLength + 1, eternal_handles->NumberOfHandles()); |
366 } | 377 } |
OLD | NEW |