2020-06-17 07:54:15 +00:00
|
|
|
// Copyright 2020 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 "include/cppgc/allocation.h"
|
|
|
|
#include "include/cppgc/garbage-collected.h"
|
|
|
|
#include "include/cppgc/platform.h"
|
|
|
|
#include "src/api/api-inl.h"
|
|
|
|
#include "src/heap/cppgc-js/cpp-heap.h"
|
|
|
|
#include "src/objects/objects-inl.h"
|
|
|
|
#include "test/unittests/heap/heap-utils.h"
|
2020-10-22 07:02:17 +00:00
|
|
|
#include "test/unittests/heap/unified-heap-utils.h"
|
2020-06-17 07:54:15 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class Wrappable final : public cppgc::GarbageCollected<Wrappable> {
|
|
|
|
public:
|
|
|
|
static size_t destructor_callcount;
|
|
|
|
|
|
|
|
~Wrappable() { destructor_callcount++; }
|
|
|
|
|
|
|
|
void Trace(cppgc::Visitor* visitor) const {}
|
|
|
|
};
|
|
|
|
|
|
|
|
size_t Wrappable::destructor_callcount = 0;
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2020-10-23 10:39:23 +00:00
|
|
|
TEST_F(UnifiedHeapTest, OnlyGC) { CollectGarbageWithEmbedderStack(); }
|
2020-06-17 07:54:15 +00:00
|
|
|
|
|
|
|
TEST_F(UnifiedHeapTest, FindingV8ToBlinkReference) {
|
|
|
|
v8::HandleScope scope(v8_isolate());
|
|
|
|
v8::Local<v8::Context> context = v8::Context::New(v8_isolate());
|
|
|
|
v8::Context::Scope context_scope(context);
|
2020-10-28 08:13:33 +00:00
|
|
|
v8::Local<v8::Object> api_object = WrapperHelper::CreateWrapper(
|
2020-06-17 07:54:15 +00:00
|
|
|
context, cppgc::MakeGarbageCollected<Wrappable>(allocation_handle()));
|
|
|
|
EXPECT_FALSE(api_object.IsEmpty());
|
|
|
|
EXPECT_EQ(0u, Wrappable::destructor_callcount);
|
2020-10-23 10:39:23 +00:00
|
|
|
CollectGarbageWithoutEmbedderStack();
|
2020-06-17 07:54:15 +00:00
|
|
|
EXPECT_EQ(0u, Wrappable::destructor_callcount);
|
2020-10-28 08:13:33 +00:00
|
|
|
WrapperHelper::ResetWrappableConnection(api_object);
|
2020-10-23 10:39:23 +00:00
|
|
|
CollectGarbageWithoutEmbedderStack();
|
2020-10-16 18:38:52 +00:00
|
|
|
// Calling CollectGarbage twice to force the first GC to finish sweeping.
|
2020-10-23 10:39:23 +00:00
|
|
|
CollectGarbageWithoutEmbedderStack();
|
2020-06-17 07:54:15 +00:00
|
|
|
EXPECT_EQ(1u, Wrappable::destructor_callcount);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|