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

Side by Side Diff: Source/bindings/core/v8/ScriptPromisePropertyTest.cpp

Issue 1306083008: Fix ScriptState leak in ScriptPromiseProperty unittests. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 #include "bindings/core/v8/ScriptPromiseProperty.h" 6 #include "bindings/core/v8/ScriptPromiseProperty.h"
7 7
8 #include "bindings/core/v8/DOMWrapperWorld.h" 8 #include "bindings/core/v8/DOMWrapperWorld.h"
9 #include "bindings/core/v8/ScriptFunction.h" 9 #include "bindings/core/v8/ScriptFunction.h"
10 #include "bindings/core/v8/ScriptPromise.h" 10 #include "bindings/core/v8/ScriptPromise.h"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 119
120 Persistent<Property> m_property; 120 Persistent<Property> m_property;
121 }; 121 };
122 122
123 class ScriptPromisePropertyTestBase { 123 class ScriptPromisePropertyTestBase {
124 public: 124 public:
125 ScriptPromisePropertyTestBase() 125 ScriptPromisePropertyTestBase()
126 : m_page(DummyPageHolder::create(IntSize(1, 1))) 126 : m_page(DummyPageHolder::create(IntSize(1, 1)))
127 { 127 {
128 v8::HandleScope handleScope(isolate()); 128 v8::HandleScope handleScope(isolate());
129 m_otherScriptState = ScriptStateForTesting::create(v8::Context::New(isol ate()), DOMWrapperWorld::create(isolate(), 1)); 129 m_otherScriptState = ScriptStateForTesting::create(v8::Context::New(isol ate()), DOMWrapperWorld::ensureIsolatedWorld(isolate(), 1, -1));
130 } 130 }
131 131
132 virtual ~ScriptPromisePropertyTestBase() 132 virtual ~ScriptPromisePropertyTestBase()
133 { 133 {
134 m_page.clear(); 134 ScriptPromisePropertyTestBase::destroyContext();
135 gc();
136 Heap::collectAllGarbage();
137 } 135 }
138 136
139 Document& document() { return m_page->document(); } 137 Document& document() { return m_page->document(); }
140 v8::Isolate* isolate() { return toIsolate(&document()); } 138 v8::Isolate* isolate() { return toIsolate(&document()); }
141 ScriptState* mainScriptState() { return ScriptState::forMainWorld(document() .frame()); } 139 ScriptState* mainScriptState() { return ScriptState::forMainWorld(document() .frame()); }
142 DOMWrapperWorld& mainWorld() { return mainScriptState()->world(); } 140 DOMWrapperWorld& mainWorld() { return mainScriptState()->world(); }
143 ScriptState* otherScriptState() { return m_otherScriptState.get(); } 141 ScriptState* otherScriptState() { return m_otherScriptState.get(); }
144 DOMWrapperWorld& otherWorld() { return m_otherScriptState->world(); } 142 DOMWrapperWorld& otherWorld() { return m_otherScriptState->world(); }
145 ScriptState* currentScriptState() { return ScriptState::current(isolate()); } 143 ScriptState* currentScriptState() { return ScriptState::current(isolate()); }
146 144
147 virtual void destroyContext() 145 virtual void destroyContext()
148 { 146 {
149 m_page.clear(); 147 m_page.clear();
150 m_otherScriptState.clear(); 148 if (m_otherScriptState) {
149 m_otherScriptState->disposePerContextData();
150 m_otherScriptState = nullptr;
151 }
151 gc(); 152 gc();
152 Heap::collectGarbage(ThreadState::HeapPointersOnStack, ThreadState::GCWi thSweep, Heap::ForcedGC); 153 Heap::collectAllGarbage();
sof 2015/08/31 06:44:40 Incidental to this CL, but having the name of this
haraken 2015/08/31 06:46:42 Yeah, a better idea would be to call V8GCControlle
sof 2015/08/31 06:50:22 You have to supply the "force" flag in V8GCControl
haraken 2015/08/31 06:55:52 V8GCController::collectGarbage calls window.gc() a
sof 2015/08/31 06:58:34 This is a unit test -- isn't "gc()" mapping to wha
sof 2015/08/31 07:03:46 Which maps to v8/src/extensions/gc-extension.* i.
yhirano 2015/08/31 07:10:43 Once I was told that relying on the conservative G
153 } 154 }
154 155
155 void gc() { V8GCController::collectGarbage(v8::Isolate::GetCurrent()); } 156 void gc() { V8GCController::collectGarbage(v8::Isolate::GetCurrent()); }
156 157
157 v8::Local<v8::Function> notReached(ScriptState* scriptState) { return NotRea ched::createFunction(scriptState); } 158 v8::Local<v8::Function> notReached(ScriptState* scriptState) { return NotRea ched::createFunction(scriptState); }
158 v8::Local<v8::Function> stub(ScriptState* scriptState, ScriptValue& value, s ize_t& callCount) { return StubFunction::createFunction(scriptState, value, call Count); } 159 v8::Local<v8::Function> stub(ScriptState* scriptState, ScriptValue& value, s ize_t& callCount) { return StubFunction::createFunction(scriptState, value, call Count); }
159 160
160 template <typename T> 161 template <typename T>
161 ScriptValue wrap(DOMWrapperWorld& world, const T& value) 162 ScriptValue wrap(DOMWrapperWorld& world, const T& value)
162 { 163 {
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 isolate()->RunMicrotasks(); 355 isolate()->RunMicrotasks();
355 EXPECT_EQ(1u, nRejectCalls); 356 EXPECT_EQ(1u, nRejectCalls);
356 EXPECT_EQ(wrap(mainWorld(), reason), actual); 357 EXPECT_EQ(wrap(mainWorld(), reason), actual);
357 EXPECT_EQ(1u, nOtherRejectCalls); 358 EXPECT_EQ(1u, nOtherRejectCalls);
358 EXPECT_NE(actual, otherActual); 359 EXPECT_NE(actual, otherActual);
359 EXPECT_EQ(wrap(otherWorld(), reason), otherActual); 360 EXPECT_EQ(wrap(otherWorld(), reason), otherActual);
360 } 361 }
361 362
362 TEST_F(ScriptPromisePropertyGarbageCollectedTest, Promise_DeadContext) 363 TEST_F(ScriptPromisePropertyGarbageCollectedTest, Promise_DeadContext)
363 { 364 {
364 Property* property = this->property(); 365 Persistent<Property> property = this->property();
365 property->resolve(new GarbageCollectedScriptWrappable("value")); 366 property->resolve(new GarbageCollectedScriptWrappable("value"));
366 EXPECT_EQ(Property::Resolved, property->state()); 367 EXPECT_EQ(Property::Resolved, property->state());
367 368
368 destroyContext(); 369 destroyContext();
369 370
370 EXPECT_TRUE(property->promise(DOMWrapperWorld::mainWorld()).isEmpty()); 371 EXPECT_TRUE(property->promise(DOMWrapperWorld::mainWorld()).isEmpty());
371 } 372 }
372 373
373 TEST_F(ScriptPromisePropertyGarbageCollectedTest, Resolve_DeadContext) 374 TEST_F(ScriptPromisePropertyGarbageCollectedTest, Resolve_DeadContext)
374 { 375 {
375 Property* property = this->property(); 376 Persistent<Property> property = this->property();
376 377
377 { 378 {
378 ScriptState::Scope scope(mainScriptState()); 379 ScriptState::Scope scope(mainScriptState());
379 property->promise(DOMWrapperWorld::mainWorld()).then(notReached(currentS criptState()), notReached(currentScriptState())); 380 property->promise(DOMWrapperWorld::mainWorld()).then(notReached(currentS criptState()), notReached(currentScriptState()));
380 } 381 }
381 382
382 destroyContext(); 383 destroyContext();
383 EXPECT_TRUE(!property->executionContext() || property->executionContext()->a ctiveDOMObjectsAreStopped()); 384 EXPECT_TRUE(!property->executionContext() || property->executionContext()->a ctiveDOMObjectsAreStopped());
384 385
385 property->resolve(new GarbageCollectedScriptWrappable("value")); 386 property->resolve(new GarbageCollectedScriptWrappable("value"));
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 { 547 {
547 test(String("hello"), "hello", __FILE__, __LINE__); 548 test(String("hello"), "hello", __FILE__, __LINE__);
548 } 549 }
549 550
550 TEST_F(ScriptPromisePropertyNonScriptWrappableResolutionTargetTest, ResolveWithI nteger) 551 TEST_F(ScriptPromisePropertyNonScriptWrappableResolutionTargetTest, ResolveWithI nteger)
551 { 552 {
552 test(-1, "-1", __FILE__, __LINE__); 553 test(-1, "-1", __FILE__, __LINE__);
553 } 554 }
554 555
555 } // namespace 556 } // namespace
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698