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

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

Issue 2676513008: [wasm] Managed<T> ensures T's lifetime does not leak past Isolate's (Closed)
Patch Set: renamed to ManagedObjectFinalizer, and using "finalizer"` 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
« no previous file with comments | « test/cctest/cctest.gyp ('k') | test/cctest/wasm/test-managed.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 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 <stdint.h>
6 #include <stdlib.h>
7 #include <string.h>
8
9 #include "src/managed.h"
10
11 #include "src/objects-inl.h"
12 #include "test/cctest/cctest.h"
13
14 using namespace v8::base;
15 using namespace v8::internal;
16
17 class DeleteRecorder {
18 public:
19 explicit DeleteRecorder(bool* deleted) : deleted_(deleted) {
20 *deleted_ = false;
21 }
22 ~DeleteRecorder() { *deleted_ = true; }
23 static void Deleter(void* value) {
24 delete reinterpret_cast<DeleteRecorder*>(value);
25 }
26
27 private:
28 bool* deleted_;
29 };
30
31 TEST(ManagedCollect) {
32 Isolate* isolate = CcTest::InitIsolateOnce();
33 bool deleted1 = false;
34 bool deleted2 = false;
35 DeleteRecorder* d1 = new DeleteRecorder(&deleted1);
36 DeleteRecorder* d2 = new DeleteRecorder(&deleted2);
37 Isolate::ManagedObjectFinalizer* finalizer =
38 isolate->RegisterForReleaseAtTeardown(d2, DeleteRecorder::Deleter);
39 {
40 HandleScope scope(isolate);
41 auto handle = Managed<DeleteRecorder>::New(isolate, d1);
42 USE(handle);
43 }
44
45 CcTest::CollectAllAvailableGarbage();
46
47 CHECK(deleted1);
48 CHECK(!deleted2);
49 isolate->UnregisterFromReleaseAtTeardown(&finalizer);
50 CHECK_NULL(finalizer);
51 delete d2;
52 CHECK(deleted2);
53 }
54
55 TEST(DisposeCollect) {
56 v8::Isolate::CreateParams create_params;
57 create_params.array_buffer_allocator =
58 CcTest::InitIsolateOnce()->array_buffer_allocator();
59
60 v8::Isolate* isolate = v8::Isolate::New(create_params);
61 isolate->Enter();
62 Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
63 bool deleted1 = false;
64 bool deleted2 = false;
65 DeleteRecorder* d1 = new DeleteRecorder(&deleted1);
66 DeleteRecorder* d2 = new DeleteRecorder(&deleted2);
67 {
68 HandleScope scope(i_isolate);
69 auto handle = Managed<DeleteRecorder>::New(i_isolate, d1);
70 USE(handle);
71 }
72 i_isolate->RegisterForReleaseAtTeardown(d2, DeleteRecorder::Deleter);
73
74 isolate->Exit();
75 isolate->Dispose();
76 CHECK(deleted1);
77 CHECK(deleted2);
78 }
OLDNEW
« no previous file with comments | « test/cctest/cctest.gyp ('k') | test/cctest/wasm/test-managed.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698