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

Side by Side Diff: test/cctest/test-api.cc

Issue 88013002: Split Persistent into Persistent and UniquePersistent (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: comments Created 7 years 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
« include/v8.h ('K') | « include/v8.h ('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 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 3281 matching lines...) Expand 10 before | Expand all | Expand 10 after
3292 { 3292 {
3293 v8::HandleScope scope(isolate); 3293 v8::HandleScope scope(isolate);
3294 Local<String> empty; 3294 Local<String> empty;
3295 global.Reset(isolate, empty); 3295 global.Reset(isolate, empty);
3296 } 3296 }
3297 CHECK(global.IsEmpty()); 3297 CHECK(global.IsEmpty());
3298 CHECK_EQ(global_handles->global_handles_count(), initial_handle_count - 1); 3298 CHECK_EQ(global_handles->global_handles_count(), initial_handle_count - 1);
3299 } 3299 }
3300 3300
3301 3301
3302 template<class T>
3303 static v8::UniquePersistent<T> PassUnique(v8::UniquePersistent<T> unique) {
3304 return unique.Pass();
3305 }
3306
3307
3308 template<class T>
3309 static v8::UniquePersistent<T> ReturnUnique(v8::Isolate* isolate,
3310 const v8::Persistent<T> & global) {
3311 v8::UniquePersistent<String> unique(isolate, global);
3312 return unique.Pass();
3313 }
3314
3315
3316 THREADED_TEST(UniquePersistent) {
3317 v8::Isolate* isolate = CcTest::isolate();
3318 v8::Persistent<String> global;
3319 {
3320 v8::HandleScope scope(isolate);
3321 global.Reset(isolate, v8_str("str"));
3322 }
3323 v8::internal::GlobalHandles* global_handles =
3324 reinterpret_cast<v8::internal::Isolate*>(isolate)->global_handles();
3325 int initial_handle_count = global_handles->global_handles_count();
3326 {
3327 v8::UniquePersistent<String> unique(isolate, global);
3328 CHECK_EQ(initial_handle_count + 1, global_handles->global_handles_count());
3329 // Test assignment via Pass
3330 {
3331 v8::UniquePersistent<String> copy = unique.Pass();
3332 CHECK(unique.IsEmpty());
3333 CHECK(copy == global);
3334 CHECK_EQ(initial_handle_count + 1,
3335 global_handles->global_handles_count());
3336 unique = copy.Pass();
3337 }
3338 // Test ctor via Pass
3339 {
3340 v8::UniquePersistent<String> copy(unique.Pass());
3341 CHECK(unique.IsEmpty());
3342 CHECK(copy == global);
3343 CHECK_EQ(initial_handle_count + 1,
3344 global_handles->global_handles_count());
3345 unique = copy.Pass();
3346 }
3347 // Test pass through function call
3348 {
3349 v8::UniquePersistent<String> copy = PassUnique(unique.Pass());
3350 CHECK(unique.IsEmpty());
3351 CHECK(copy == global);
3352 CHECK_EQ(initial_handle_count + 1,
3353 global_handles->global_handles_count());
3354 unique = copy.Pass();
3355 }
3356 CHECK_EQ(initial_handle_count + 1, global_handles->global_handles_count());
3357 }
3358 // Test pass from function call
3359 {
3360 v8::UniquePersistent<String> unique = ReturnUnique(isolate, global);
3361 CHECK(unique == global);
3362 CHECK_EQ(initial_handle_count + 1, global_handles->global_handles_count());
3363 }
3364 CHECK_EQ(initial_handle_count, global_handles->global_handles_count());
3365 global.Reset();
3366 }
3367
3368
3302 THREADED_TEST(GlobalHandleUpcast) { 3369 THREADED_TEST(GlobalHandleUpcast) {
3303 v8::Isolate* isolate = CcTest::isolate(); 3370 v8::Isolate* isolate = CcTest::isolate();
3304 v8::HandleScope scope(isolate); 3371 v8::HandleScope scope(isolate);
3305 v8::Local<String> local = v8::Local<String>::New(isolate, v8_str("str")); 3372 v8::Local<String> local = v8::Local<String>::New(isolate, v8_str("str"));
3306 v8::Persistent<String> global_string(isolate, local); 3373 v8::Persistent<String> global_string(isolate, local);
3307 v8::Persistent<Value>& global_value = 3374 v8::Persistent<Value>& global_value =
3308 v8::Persistent<Value>::Cast(global_string); 3375 v8::Persistent<Value>::Cast(global_string);
3309 CHECK(v8::Local<v8::Value>::New(isolate, global_value)->IsString()); 3376 CHECK(v8::Local<v8::Value>::New(isolate, global_value)->IsString());
3310 CHECK(global_string == v8::Persistent<String>::Cast(global_value)); 3377 CHECK(global_string == v8::Persistent<String>::Cast(global_value));
3311 global_string.Reset(); 3378 global_string.Reset();
(...skipping 17468 matching lines...) Expand 10 before | Expand all | Expand 10 after
20780 } 20847 }
20781 for (int i = 0; i < runs; i++) { 20848 for (int i = 0; i < runs; i++) {
20782 Local<String> expected; 20849 Local<String> expected;
20783 if (i != 0) { 20850 if (i != 0) {
20784 CHECK_EQ(v8_str("escape value"), values[i]); 20851 CHECK_EQ(v8_str("escape value"), values[i]);
20785 } else { 20852 } else {
20786 CHECK(values[i].IsEmpty()); 20853 CHECK(values[i].IsEmpty());
20787 } 20854 }
20788 } 20855 }
20789 } 20856 }
OLDNEW
« include/v8.h ('K') | « include/v8.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698