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 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 CHECK_EQ(0, eternal_handles->NumberOfHandles()); | 331 CHECK_EQ(0, eternal_handles->NumberOfHandles()); |
332 for (int i = 0; i < kArrayLength; i++) { | 332 for (int i = 0; i < kArrayLength; i++) { |
333 indices[i] = -1; | 333 indices[i] = -1; |
334 HandleScope scope(isolate); | 334 HandleScope scope(isolate); |
335 v8::Local<v8::Object> object = v8::Object::New(); | 335 v8::Local<v8::Object> object = v8::Object::New(); |
336 object->Set(i, v8::Integer::New(i, v8_isolate)); | 336 object->Set(i, v8::Integer::New(i, v8_isolate)); |
337 // Create with internal api | 337 // Create with internal api |
338 eternal_handles->Create( | 338 eternal_handles->Create( |
339 isolate, *v8::Utils::OpenHandle(*object), &indices[i]); | 339 isolate, *v8::Utils::OpenHandle(*object), &indices[i]); |
340 // Create with external api | 340 // Create with external api |
| 341 CHECK(eternals[i].IsEmpty()); |
| 342 eternals[i].Set(v8_isolate, object); |
341 CHECK(!eternals[i].IsEmpty()); | 343 CHECK(!eternals[i].IsEmpty()); |
342 eternals[i].Set(v8_isolate, object); | |
343 CHECK(eternals[i].IsEmpty()); | |
344 } | 344 } |
345 | 345 |
346 isolate->heap()->CollectAllAvailableGarbage(); | 346 isolate->heap()->CollectAllAvailableGarbage(); |
347 | 347 |
348 for (int i = 0; i < kArrayLength; i++) { | 348 for (int i = 0; i < kArrayLength; i++) { |
349 for (int j = 0; j < 2; j++) { | 349 for (int j = 0; j < 2; j++) { |
350 HandleScope scope(isolate); | 350 HandleScope scope(isolate); |
351 v8::Local<v8::Value> local; | 351 v8::Local<v8::Value> local; |
352 if (j == 0) { | 352 if (j == 0) { |
353 // Test internal api | 353 // Test internal api |
354 local = v8::Utils::ToLocal(eternal_handles->Get(indices[i])); | 354 local = v8::Utils::ToLocal(eternal_handles->Get(indices[i])); |
355 } else { | 355 } else { |
356 // Test external api | 356 // Test external api |
357 local = eternals[i].Get(v8_isolate); | 357 local = eternals[i].Get(v8_isolate); |
358 } | 358 } |
359 v8::Local<v8::Object> object = v8::Handle<v8::Object>::Cast(local); | 359 v8::Local<v8::Object> object = v8::Handle<v8::Object>::Cast(local); |
360 v8::Local<v8::Value> value = object->Get(i); | 360 v8::Local<v8::Value> value = object->Get(i); |
361 CHECK(value->IsInt32()); | 361 CHECK(value->IsInt32()); |
362 CHECK_EQ(i, value->Int32Value()); | 362 CHECK_EQ(i, value->Int32Value()); |
363 } | 363 } |
364 } | 364 } |
365 | 365 |
366 CHECK_EQ(2*kArrayLength, eternal_handles->NumberOfHandles()); | 366 CHECK_EQ(2*kArrayLength, eternal_handles->NumberOfHandles()); |
367 | 367 |
368 // Create an eternal via the constructor | 368 // Create an eternal via the constructor |
369 { | 369 { |
370 HandleScope scope(isolate); | 370 HandleScope scope(isolate); |
371 v8::Local<v8::Object> object = v8::Object::New(); | 371 v8::Local<v8::Object> object = v8::Object::New(); |
372 v8::Eternal<v8::Object> eternal(v8_isolate, object); | 372 v8::Eternal<v8::Object> eternal(v8_isolate, object); |
373 CHECK(eternal.IsEmpty()); | 373 CHECK(!eternal.IsEmpty()); |
374 CHECK(object == eternal.Get(v8_isolate)); | 374 CHECK(object == eternal.Get(v8_isolate)); |
375 } | 375 } |
376 | 376 |
377 CHECK_EQ(2*kArrayLength + 1, eternal_handles->NumberOfHandles()); | 377 CHECK_EQ(2*kArrayLength + 1, eternal_handles->NumberOfHandles()); |
378 } | 378 } |
OLD | NEW |