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

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

Issue 14788013: Add Persistent<T>::Reset which disposes the handle and redirects it to point to another object. (Closed) Base URL: git://github.com/v8/v8.git@master
Patch Set: code review (svenpanne) + fixes (val_ -> this->val_) Created 7 years, 7 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
« no previous file with comments | « 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 2468 matching lines...) Expand 10 before | Expand all | Expand 10 after
2479 { 2479 {
2480 v8::HandleScope scope(isolate); 2480 v8::HandleScope scope(isolate);
2481 Local<String> str = v8_str("str"); 2481 Local<String> str = v8_str("str");
2482 global = v8::Persistent<String>::New(isolate, str); 2482 global = v8::Persistent<String>::New(isolate, str);
2483 } 2483 }
2484 CHECK_EQ(global->Length(), 3); 2484 CHECK_EQ(global->Length(), 3);
2485 global.Dispose(isolate); 2485 global.Dispose(isolate);
2486 } 2486 }
2487 2487
2488 2488
2489 THREADED_TEST(ResettingGlobalHandle) {
2490 v8::Isolate* isolate = v8::Isolate::GetCurrent();
2491 v8::internal::GlobalHandles* global_handles = NULL;
2492 int initial_handle_count = 0;
2493 v8::Persistent<String> global;
2494 {
2495 v8::HandleScope scope(isolate);
2496 Local<String> str = v8_str("str");
2497 global_handles =
2498 reinterpret_cast<v8::internal::Isolate*>(isolate)->global_handles();
2499 initial_handle_count = global_handles->NumberOfGlobalHandles();
2500 global = v8::Persistent<String>::New(isolate, str);
2501 }
2502 CHECK_EQ(global->Length(), 3);
2503 CHECK_EQ(global_handles->NumberOfGlobalHandles(), initial_handle_count + 1);
2504 {
2505 v8::HandleScope scope(isolate);
2506 Local<String> str = v8_str("longer");
2507 global.Reset(isolate, str);
2508 }
2509 CHECK_EQ(global->Length(), 6);
2510 CHECK_EQ(global_handles->NumberOfGlobalHandles(), initial_handle_count + 1);
2511 global.Dispose(isolate);
2512 CHECK_EQ(global_handles->NumberOfGlobalHandles(), initial_handle_count);
2513 }
2514
2515
2516 THREADED_TEST(ResettingGlobalHandleToEmpty) {
2517 v8::Isolate* isolate = v8::Isolate::GetCurrent();
2518 v8::internal::GlobalHandles* global_handles = NULL;
2519 int initial_handle_count = 0;
2520 v8::Persistent<String> global;
2521 {
2522 v8::HandleScope scope(isolate);
2523 Local<String> str = v8_str("str");
2524 global_handles =
2525 reinterpret_cast<v8::internal::Isolate*>(isolate)->global_handles();
2526 initial_handle_count = global_handles->NumberOfGlobalHandles();
2527 global = v8::Persistent<String>::New(isolate, str);
2528 }
2529 CHECK_EQ(global->Length(), 3);
2530 CHECK_EQ(global_handles->NumberOfGlobalHandles(), initial_handle_count + 1);
2531 {
2532 v8::HandleScope scope(isolate);
2533 Local<String> empty;
2534 global.Reset(isolate, empty);
2535 }
2536 CHECK(global.IsEmpty());
2537 CHECK_EQ(global_handles->NumberOfGlobalHandles(), initial_handle_count);
2538 }
2539
2540
2489 THREADED_TEST(LocalHandle) { 2541 THREADED_TEST(LocalHandle) {
2490 v8::HandleScope scope(v8::Isolate::GetCurrent()); 2542 v8::HandleScope scope(v8::Isolate::GetCurrent());
2491 v8::Local<String> local = v8::Local<String>::New(v8_str("str")); 2543 v8::Local<String> local = v8::Local<String>::New(v8_str("str"));
2492 CHECK_EQ(local->Length(), 3); 2544 CHECK_EQ(local->Length(), 3);
2493 2545
2494 local = v8::Local<String>::New(v8::Isolate::GetCurrent(), v8_str("str")); 2546 local = v8::Local<String>::New(v8::Isolate::GetCurrent(), v8_str("str"));
2495 CHECK_EQ(local->Length(), 3); 2547 CHECK_EQ(local->Length(), 3);
2496 } 2548 }
2497 2549
2498 2550
(...skipping 16394 matching lines...) Expand 10 before | Expand all | Expand 10 after
18893 i::Semaphore* sem_; 18945 i::Semaphore* sem_;
18894 volatile int sem_value_; 18946 volatile int sem_value_;
18895 }; 18947 };
18896 18948
18897 18949
18898 THREADED_TEST(SemaphoreInterruption) { 18950 THREADED_TEST(SemaphoreInterruption) {
18899 ThreadInterruptTest().RunTest(); 18951 ThreadInterruptTest().RunTest();
18900 } 18952 }
18901 18953
18902 #endif // WIN32 18954 #endif // WIN32
OLDNEW
« no previous file with comments | « include/v8.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698