OLD | NEW |
---|---|
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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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::ensureIsolatedWorld(isolate(), 1, -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 ScriptPromisePropertyTestBase::destroyContext(); | 134 destroyContext(); |
135 } | 135 } |
136 | 136 |
137 Document& document() { return m_page->document(); } | 137 Document& document() { return m_page->document(); } |
138 v8::Isolate* isolate() { return toIsolate(&document()); } | 138 v8::Isolate* isolate() { return toIsolate(&document()); } |
139 ScriptState* mainScriptState() { return ScriptState::forMainWorld(document() .frame()); } | 139 ScriptState* mainScriptState() { return ScriptState::forMainWorld(document() .frame()); } |
140 DOMWrapperWorld& mainWorld() { return mainScriptState()->world(); } | 140 DOMWrapperWorld& mainWorld() { return mainScriptState()->world(); } |
141 ScriptState* otherScriptState() { return m_otherScriptState.get(); } | 141 ScriptState* otherScriptState() { return m_otherScriptState.get(); } |
142 DOMWrapperWorld& otherWorld() { return m_otherScriptState->world(); } | 142 DOMWrapperWorld& otherWorld() { return m_otherScriptState->world(); } |
143 ScriptState* currentScriptState() { return ScriptState::current(isolate()); } | 143 ScriptState* currentScriptState() { return ScriptState::current(isolate()); } |
144 | 144 |
145 virtual void destroyContext() | 145 void destroyContext() |
146 { | 146 { |
147 m_page.clear(); | 147 m_page.clear(); |
148 if (m_otherScriptState) { | 148 if (m_otherScriptState) { |
149 m_otherScriptState->disposePerContextData(); | 149 m_otherScriptState->disposePerContextData(); |
150 m_otherScriptState = nullptr; | 150 m_otherScriptState = nullptr; |
151 } | 151 } |
152 gc(); | |
153 Heap::collectAllGarbage(); | |
154 } | 152 } |
155 | 153 |
156 void gc() { V8GCController::collectGarbage(v8::Isolate::GetCurrent()); } | 154 void gc() { V8GCController::collectGarbage(v8::Isolate::GetCurrent()); } |
157 | 155 |
158 v8::Local<v8::Function> notReached(ScriptState* scriptState) { return NotRea ched::createFunction(scriptState); } | 156 v8::Local<v8::Function> notReached(ScriptState* scriptState) { return NotRea ched::createFunction(scriptState); } |
159 v8::Local<v8::Function> stub(ScriptState* scriptState, ScriptValue& value, s ize_t& callCount) { return StubFunction::createFunction(scriptState, value, call Count); } | 157 v8::Local<v8::Function> stub(ScriptState* scriptState, ScriptValue& value, s ize_t& callCount) { return StubFunction::createFunction(scriptState, value, call Count); } |
160 | 158 |
161 template <typename T> | 159 template <typename T> |
162 ScriptValue wrap(DOMWrapperWorld& world, const T& value) | 160 ScriptValue wrap(DOMWrapperWorld& world, const T& value) |
163 { | 161 { |
(...skipping 17 matching lines...) Expand all Loading... | |
181 | 179 |
182 ScriptPromisePropertyGarbageCollectedTest() | 180 ScriptPromisePropertyGarbageCollectedTest() |
183 : m_holder(new GarbageCollectedHolder(&document())) | 181 : m_holder(new GarbageCollectedHolder(&document())) |
184 { | 182 { |
185 } | 183 } |
186 | 184 |
187 GarbageCollectedHolder* holder() { return m_holder; } | 185 GarbageCollectedHolder* holder() { return m_holder; } |
188 Property* property() { return m_holder->property(); } | 186 Property* property() { return m_holder->property(); } |
189 ScriptPromise promise(DOMWrapperWorld& world) { return property()->promise(w orld); } | 187 ScriptPromise promise(DOMWrapperWorld& world) { return property()->promise(w orld); } |
190 | 188 |
191 void destroyContext() override | |
192 { | |
193 m_holder = nullptr; | |
194 ScriptPromisePropertyTestBase::destroyContext(); | |
195 } | |
196 | |
197 private: | 189 private: |
198 Persistent<GarbageCollectedHolder> m_holder; | 190 Persistent<GarbageCollectedHolder> m_holder; |
199 }; | 191 }; |
200 | 192 |
201 TEST_F(ScriptPromisePropertyGarbageCollectedTest, Promise_IsStableObjectInMainWo rld) | 193 TEST_F(ScriptPromisePropertyGarbageCollectedTest, Promise_IsStableObjectInMainWo rld) |
202 { | 194 { |
203 ScriptPromise v = property()->promise(DOMWrapperWorld::mainWorld()); | 195 ScriptPromise v = property()->promise(DOMWrapperWorld::mainWorld()); |
204 ScriptPromise w = property()->promise(DOMWrapperWorld::mainWorld()); | 196 ScriptPromise w = property()->promise(DOMWrapperWorld::mainWorld()); |
205 EXPECT_EQ(v, w); | 197 EXPECT_EQ(v, w); |
206 ASSERT_FALSE(v.isEmpty()); | 198 ASSERT_FALSE(v.isEmpty()); |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
355 isolate()->RunMicrotasks(); | 347 isolate()->RunMicrotasks(); |
356 EXPECT_EQ(1u, nRejectCalls); | 348 EXPECT_EQ(1u, nRejectCalls); |
357 EXPECT_EQ(wrap(mainWorld(), reason), actual); | 349 EXPECT_EQ(wrap(mainWorld(), reason), actual); |
358 EXPECT_EQ(1u, nOtherRejectCalls); | 350 EXPECT_EQ(1u, nOtherRejectCalls); |
359 EXPECT_NE(actual, otherActual); | 351 EXPECT_NE(actual, otherActual); |
360 EXPECT_EQ(wrap(otherWorld(), reason), otherActual); | 352 EXPECT_EQ(wrap(otherWorld(), reason), otherActual); |
361 } | 353 } |
362 | 354 |
363 TEST_F(ScriptPromisePropertyGarbageCollectedTest, Promise_DeadContext) | 355 TEST_F(ScriptPromisePropertyGarbageCollectedTest, Promise_DeadContext) |
364 { | 356 { |
365 Persistent<Property> property = this->property(); | 357 Property* property = this->property(); |
sof
2015/08/31 08:44:03
not needed now, but a nicety to bind it to a local
yhirano
2015/09/01 07:01:55
Ah, I didn't notice that. Removed.
| |
366 property->resolve(new GarbageCollectedScriptWrappable("value")); | 358 property->resolve(new GarbageCollectedScriptWrappable("value")); |
367 EXPECT_EQ(Property::Resolved, property->state()); | 359 EXPECT_EQ(Property::Resolved, property->state()); |
368 | 360 |
369 destroyContext(); | 361 destroyContext(); |
370 | 362 |
371 EXPECT_TRUE(property->promise(DOMWrapperWorld::mainWorld()).isEmpty()); | 363 EXPECT_TRUE(property->promise(DOMWrapperWorld::mainWorld()).isEmpty()); |
372 } | 364 } |
373 | 365 |
374 TEST_F(ScriptPromisePropertyGarbageCollectedTest, Resolve_DeadContext) | 366 TEST_F(ScriptPromisePropertyGarbageCollectedTest, Resolve_DeadContext) |
375 { | 367 { |
376 Persistent<Property> property = this->property(); | 368 Property* property = this->property(); |
377 | 369 |
378 { | 370 { |
379 ScriptState::Scope scope(mainScriptState()); | 371 ScriptState::Scope scope(mainScriptState()); |
380 property->promise(DOMWrapperWorld::mainWorld()).then(notReached(currentS criptState()), notReached(currentScriptState())); | 372 property->promise(DOMWrapperWorld::mainWorld()).then(notReached(currentS criptState()), notReached(currentScriptState())); |
381 } | 373 } |
382 | 374 |
383 destroyContext(); | 375 destroyContext(); |
384 EXPECT_TRUE(!property->executionContext() || property->executionContext()->a ctiveDOMObjectsAreStopped()); | 376 EXPECT_TRUE(!property->executionContext() || property->executionContext()->a ctiveDOMObjectsAreStopped()); |
385 | 377 |
386 property->resolve(new GarbageCollectedScriptWrappable("value")); | 378 property->resolve(new GarbageCollectedScriptWrappable("value")); |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
547 { | 539 { |
548 test(String("hello"), "hello", __FILE__, __LINE__); | 540 test(String("hello"), "hello", __FILE__, __LINE__); |
549 } | 541 } |
550 | 542 |
551 TEST_F(ScriptPromisePropertyNonScriptWrappableResolutionTargetTest, ResolveWithI nteger) | 543 TEST_F(ScriptPromisePropertyNonScriptWrappableResolutionTargetTest, ResolveWithI nteger) |
552 { | 544 { |
553 test(-1, "-1", __FILE__, __LINE__); | 545 test(-1, "-1", __FILE__, __LINE__); |
554 } | 546 } |
555 | 547 |
556 } // namespace | 548 } // namespace |
OLD | NEW |