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

Unified Diff: Source/bindings/core/v8/ScriptPromiseResolverTest.cpp

Issue 1233173002: Have ScriptPromiseResolver on the Oilpan heap always. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: retain resolver when delay'edly resolving Created 5 years, 5 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
Index: Source/bindings/core/v8/ScriptPromiseResolverTest.cpp
diff --git a/Source/bindings/core/v8/ScriptPromiseResolverTest.cpp b/Source/bindings/core/v8/ScriptPromiseResolverTest.cpp
index fb698ea14882ae5e816f77ffbdd3d1bd5f55e621..88d091f983e3ac77d02bad7e7242b85ce73be6e4 100644
--- a/Source/bindings/core/v8/ScriptPromiseResolverTest.cpp
+++ b/Source/bindings/core/v8/ScriptPromiseResolverTest.cpp
@@ -80,7 +80,7 @@ TEST_F(ScriptPromiseResolverTest, construct)
TEST_F(ScriptPromiseResolverTest, resolve)
{
- RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = nullptr;
+ ScriptPromiseResolver* resolver = nullptr;
ScriptPromise promise;
{
ScriptState::Scope scope(scriptState());
@@ -128,7 +128,7 @@ TEST_F(ScriptPromiseResolverTest, resolve)
TEST_F(ScriptPromiseResolverTest, reject)
{
- RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = nullptr;
+ ScriptPromiseResolver* resolver = nullptr;
ScriptPromise promise;
{
ScriptState::Scope scope(scriptState());
@@ -176,7 +176,7 @@ TEST_F(ScriptPromiseResolverTest, reject)
TEST_F(ScriptPromiseResolverTest, stop)
{
- RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = nullptr;
+ ScriptPromiseResolver* resolver = nullptr;
ScriptPromise promise;
{
ScriptState::Scope scope(scriptState());
@@ -204,74 +204,114 @@ TEST_F(ScriptPromiseResolverTest, stop)
EXPECT_EQ(String(), onRejected);
}
-#if !ENABLE(OILPAN)
+namespace {
yhirano 2015/07/16 11:14:14 You're already in an unnamed namespace, so you don
sof 2015/07/16 11:57:43 Dropped.
+
+class ScriptPromiseResolverKeepAlive : public ScriptPromiseResolver {
+public:
+ static ScriptPromiseResolverKeepAlive* create(ScriptState* scriptState)
+ {
+ ScriptPromiseResolverKeepAlive* resolver = new ScriptPromiseResolverKeepAlive(scriptState);
+ resolver->suspendIfNeeded();
+ return resolver;
+ }
+
+ ~ScriptPromiseResolverKeepAlive() override
+ {
+ s_destructorCalls++;
+ }
+
+ static void reset() { s_destructorCalls = 0; }
+ static bool isAlive() { return !s_destructorCalls; }
+
+ static int s_destructorCalls;
+
+private:
+ ScriptPromiseResolverKeepAlive(ScriptState* scriptState)
+ : ScriptPromiseResolver(scriptState)
+ {
+ }
+};
+
+int ScriptPromiseResolverKeepAlive::s_destructorCalls = 0;
+
+} // namespace
+
TEST_F(ScriptPromiseResolverTest, keepAliveUntilResolved)
{
- RefPtr<ScriptPromiseResolver> resolver;
+ ScriptPromiseResolverKeepAlive::reset();
+ ScriptPromiseResolver* resolver = nullptr;
{
ScriptState::Scope scope(scriptState());
- resolver = ScriptPromiseResolver::create(scriptState());
+ resolver = ScriptPromiseResolverKeepAlive::create(scriptState());
}
- EXPECT_EQ(1, resolver->refCount());
resolver->keepAliveWhilePending();
- EXPECT_EQ(2, resolver->refCount());
+ Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWithSweep, Heap::ForcedGC);
+ EXPECT_TRUE(ScriptPromiseResolverKeepAlive::isAlive());
yhirano 2015/07/16 11:14:14 ASSERT_TRUE? |resolver| will be a dangling pointer
sof 2015/07/16 11:57:43 Good idea, done (here & elsewhere.)
resolver->resolve("hello");
- EXPECT_EQ(1, resolver->refCount());
+ Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWithSweep, Heap::ForcedGC);
+ EXPECT_FALSE(ScriptPromiseResolverKeepAlive::isAlive());
}
TEST_F(ScriptPromiseResolverTest, keepAliveUntilRejected)
{
- RefPtr<ScriptPromiseResolver> resolver;
+ ScriptPromiseResolverKeepAlive::reset();
+ ScriptPromiseResolver* resolver = nullptr;
{
ScriptState::Scope scope(scriptState());
- resolver = ScriptPromiseResolver::create(scriptState());
+ resolver = ScriptPromiseResolverKeepAlive::create(scriptState());
}
- EXPECT_EQ(1, resolver->refCount());
resolver->keepAliveWhilePending();
- EXPECT_EQ(2, resolver->refCount());
+ Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWithSweep, Heap::ForcedGC);
+ EXPECT_TRUE(ScriptPromiseResolverKeepAlive::isAlive());
resolver->reject("hello");
- EXPECT_EQ(1, resolver->refCount());
+ Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWithSweep, Heap::ForcedGC);
+ EXPECT_FALSE(ScriptPromiseResolverKeepAlive::isAlive());
}
TEST_F(ScriptPromiseResolverTest, keepAliveUntilStopped)
{
- RefPtr<ScriptPromiseResolver> resolver;
+ ScriptPromiseResolverKeepAlive::reset();
+ ScriptPromiseResolver* resolver = nullptr;
{
ScriptState::Scope scope(scriptState());
- resolver = ScriptPromiseResolver::create(scriptState());
+ resolver = ScriptPromiseResolverKeepAlive::create(scriptState());
}
- EXPECT_EQ(1, resolver->refCount());
resolver->keepAliveWhilePending();
- EXPECT_EQ(2, resolver->refCount());
+ Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWithSweep, Heap::ForcedGC);
+ EXPECT_TRUE(ScriptPromiseResolverKeepAlive::isAlive());
executionContext()->stopActiveDOMObjects();
- EXPECT_EQ(1, resolver->refCount());
+ Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWithSweep, Heap::ForcedGC);
+ EXPECT_FALSE(ScriptPromiseResolverKeepAlive::isAlive());
}
TEST_F(ScriptPromiseResolverTest, suspend)
{
- RefPtr<ScriptPromiseResolver> resolver;
+ ScriptPromiseResolverKeepAlive::reset();
+ ScriptPromiseResolver* resolver = nullptr;
{
ScriptState::Scope scope(scriptState());
- resolver = ScriptPromiseResolver::create(scriptState());
+ resolver = ScriptPromiseResolverKeepAlive::create(scriptState());
}
- EXPECT_EQ(1, resolver->refCount());
resolver->keepAliveWhilePending();
- EXPECT_EQ(2, resolver->refCount());
+ Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWithSweep, Heap::ForcedGC);
+ EXPECT_TRUE(ScriptPromiseResolverKeepAlive::isAlive());
+
executionContext()->suspendActiveDOMObjects();
resolver->resolve("hello");
- EXPECT_EQ(3, resolver->refCount());
+ Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWithSweep, Heap::ForcedGC);
+ EXPECT_TRUE(ScriptPromiseResolverKeepAlive::isAlive());
executionContext()->stopActiveDOMObjects();
- EXPECT_EQ(1, resolver->refCount());
+ Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWithSweep, Heap::ForcedGC);
+ EXPECT_FALSE(ScriptPromiseResolverKeepAlive::isAlive());
}
-#endif
TEST_F(ScriptPromiseResolverTest, resolveVoid)
{
- RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = nullptr;
+ ScriptPromiseResolver* resolver = nullptr;
ScriptPromise promise;
{
ScriptState::Scope scope(scriptState());
@@ -295,7 +335,7 @@ TEST_F(ScriptPromiseResolverTest, resolveVoid)
TEST_F(ScriptPromiseResolverTest, rejectVoid)
{
- RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = nullptr;
+ ScriptPromiseResolver* resolver = nullptr;
ScriptPromise promise;
{
ScriptState::Scope scope(scriptState());

Powered by Google App Engine
This is Rietveld 408576698