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

Side by Side Diff: test/unittests/managed-unittests.cc

Issue 2676513008: [wasm] Managed<T> ensures T's lifetime does not leak past Isolate's (Closed)
Patch Set: link Created 3 years, 10 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
OLDNEW
(Empty)
1 // Copyright 2017 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "include/v8.h"
6 #include "src/flags.h"
7 #include "src/managed.h"
8 #include "src/objects-inl.h"
9
10 #include "test/unittests/test-utils.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 using namespace v8::base;
14 using namespace v8::internal;
15
16 using ManagedTest = TestWithIsolate;
17
18 class DeleteRecorder {
19 public:
20 explicit DeleteRecorder(bool* deleted) : deleted_(deleted) {
21 *deleted_ = false;
22 }
23 ~DeleteRecorder() { *deleted_ = true; }
24 static void Deleter(void* value) {
25 delete reinterpret_cast<DeleteRecorder*>(value);
26 }
27
28 private:
29 bool* deleted_;
30 };
31
32 class ScopedExposeGc {
33 public:
34 ScopedExposeGc() : was_exposed_(i::FLAG_expose_gc) {
35 i::FLAG_expose_gc = true;
36 }
37 ~ScopedExposeGc() { i::FLAG_expose_gc = was_exposed_; }
38
39 private:
40 const bool was_exposed_;
41 };
42
43 TEST_F(ManagedTest, ManagedCollect) {
44 bool deleted1 = false;
45 bool deleted2 = false;
46 DeleteRecorder* d1 = new DeleteRecorder(&deleted1);
47 DeleteRecorder* d2 = new DeleteRecorder(&deleted2);
48 Isolate::ManagedLifeline* list_node =
49 isolate()->RegisterForReleaseAtTeardown(d2, DeleteRecorder::Deleter);
50 {
51 HandleScope scope(isolate());
52 auto handle = Managed<DeleteRecorder>::New(isolate(), d1);
53 USE(handle);
54 }
55
56 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate());
57 {
58 ScopedExposeGc expose_gc;
59 v8_isolate->RequestGarbageCollectionForTesting(
60 v8::Isolate::kFullGarbageCollection);
61 }
62 CHECK(deleted1);
63 CHECK(!deleted2);
64 isolate()->UnregisterFromReleaseAtTeardown(list_node);
65 CHECK_NULL(list_node);
66 delete d2;
67 }
68
69 TEST_F(ManagedTest, DisposeCollect) {
70 v8::Isolate::CreateParams create_params;
71 create_params.array_buffer_allocator = isolate()->array_buffer_allocator();
72
73 v8::Isolate* new_isolate = v8::Isolate::New(create_params);
74 new_isolate->Enter();
75 Isolate* i_new_isolate = reinterpret_cast<i::Isolate*>(new_isolate);
76 bool deleted1 = false;
77 bool deleted2 = false;
78 DeleteRecorder* d1 = new DeleteRecorder(&deleted1);
79 DeleteRecorder* d2 = new DeleteRecorder(&deleted2);
80 {
81 HandleScope scope(i_new_isolate);
82 auto handle = Managed<DeleteRecorder>::New(i_new_isolate, d1);
83 USE(handle);
84 }
85 i_new_isolate->RegisterForReleaseAtTeardown(d2, DeleteRecorder::Deleter);
86
87 new_isolate->Exit();
88 new_isolate->Dispose();
89 CHECK(deleted1);
90 CHECK(deleted2);
91 }
OLDNEW
« src/isolate.h ('K') | « test/unittests/BUILD.gn ('k') | test/unittests/unittests.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698