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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/cctest/cctest.gyp ('k') | test/cctest/wasm/test-managed.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-managed.cc
diff --git a/test/cctest/test-managed.cc b/test/cctest/test-managed.cc
new file mode 100644
index 0000000000000000000000000000000000000000..21452b32f85e73894da00cbdd604db9914fd1332
--- /dev/null
+++ b/test/cctest/test-managed.cc
@@ -0,0 +1,78 @@
+// Copyright 2016 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "src/managed.h"
+
+#include "src/objects-inl.h"
+#include "test/cctest/cctest.h"
+
+using namespace v8::base;
+using namespace v8::internal;
+
+class DeleteRecorder {
+ public:
+ explicit DeleteRecorder(bool* deleted) : deleted_(deleted) {
+ *deleted_ = false;
+ }
+ ~DeleteRecorder() { *deleted_ = true; }
+ static void Deleter(void* value) {
+ delete reinterpret_cast<DeleteRecorder*>(value);
+ }
+
+ private:
+ bool* deleted_;
+};
+
+TEST(ManagedCollect) {
+ Isolate* isolate = CcTest::InitIsolateOnce();
+ bool deleted1 = false;
+ bool deleted2 = false;
+ DeleteRecorder* d1 = new DeleteRecorder(&deleted1);
+ DeleteRecorder* d2 = new DeleteRecorder(&deleted2);
+ Isolate::ManagedObjectFinalizer* finalizer =
+ isolate->RegisterForReleaseAtTeardown(d2, DeleteRecorder::Deleter);
+ {
+ HandleScope scope(isolate);
+ auto handle = Managed<DeleteRecorder>::New(isolate, d1);
+ USE(handle);
+ }
+
+ CcTest::CollectAllAvailableGarbage();
+
+ CHECK(deleted1);
+ CHECK(!deleted2);
+ isolate->UnregisterFromReleaseAtTeardown(&finalizer);
+ CHECK_NULL(finalizer);
+ delete d2;
+ CHECK(deleted2);
+}
+
+TEST(DisposeCollect) {
+ v8::Isolate::CreateParams create_params;
+ create_params.array_buffer_allocator =
+ CcTest::InitIsolateOnce()->array_buffer_allocator();
+
+ v8::Isolate* isolate = v8::Isolate::New(create_params);
+ isolate->Enter();
+ Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
+ bool deleted1 = false;
+ bool deleted2 = false;
+ DeleteRecorder* d1 = new DeleteRecorder(&deleted1);
+ DeleteRecorder* d2 = new DeleteRecorder(&deleted2);
+ {
+ HandleScope scope(i_isolate);
+ auto handle = Managed<DeleteRecorder>::New(i_isolate, d1);
+ USE(handle);
+ }
+ i_isolate->RegisterForReleaseAtTeardown(d2, DeleteRecorder::Deleter);
+
+ isolate->Exit();
+ isolate->Dispose();
+ CHECK(deleted1);
+ CHECK(deleted2);
+}
« 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