| 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()->resolve(new GarbageCollectedScriptWrappable("value")); |
| 366 property->resolve(new GarbageCollectedScriptWrappable("value")); | 358 EXPECT_EQ(Property::Resolved, property()->state()); |
| 367 EXPECT_EQ(Property::Resolved, property->state()); | |
| 368 | 359 |
| 369 destroyContext(); | 360 destroyContext(); |
| 370 | 361 |
| 371 EXPECT_TRUE(property->promise(DOMWrapperWorld::mainWorld()).isEmpty()); | 362 EXPECT_TRUE(property()->promise(DOMWrapperWorld::mainWorld()).isEmpty()); |
| 372 } | 363 } |
| 373 | 364 |
| 374 TEST_F(ScriptPromisePropertyGarbageCollectedTest, Resolve_DeadContext) | 365 TEST_F(ScriptPromisePropertyGarbageCollectedTest, Resolve_DeadContext) |
| 375 { | 366 { |
| 376 Persistent<Property> property = this->property(); | |
| 377 | |
| 378 { | 367 { |
| 379 ScriptState::Scope scope(mainScriptState()); | 368 ScriptState::Scope scope(mainScriptState()); |
| 380 property->promise(DOMWrapperWorld::mainWorld()).then(notReached(currentS
criptState()), notReached(currentScriptState())); | 369 property()->promise(DOMWrapperWorld::mainWorld()).then(notReached(curren
tScriptState()), notReached(currentScriptState())); |
| 381 } | 370 } |
| 382 | 371 |
| 383 destroyContext(); | 372 destroyContext(); |
| 384 EXPECT_TRUE(!property->executionContext() || property->executionContext()->a
ctiveDOMObjectsAreStopped()); | 373 EXPECT_TRUE(!property()->executionContext() || property()->executionContext(
)->activeDOMObjectsAreStopped()); |
| 385 | 374 |
| 386 property->resolve(new GarbageCollectedScriptWrappable("value")); | 375 property()->resolve(new GarbageCollectedScriptWrappable("value")); |
| 387 EXPECT_EQ(Property::Pending, property->state()); | 376 EXPECT_EQ(Property::Pending, property()->state()); |
| 388 | 377 |
| 389 v8::Isolate::GetCurrent()->RunMicrotasks(); | 378 v8::Isolate::GetCurrent()->RunMicrotasks(); |
| 390 } | 379 } |
| 391 | 380 |
| 392 TEST_F(ScriptPromisePropertyGarbageCollectedTest, Reset) | 381 TEST_F(ScriptPromisePropertyGarbageCollectedTest, Reset) |
| 393 { | 382 { |
| 394 ScriptPromise oldPromise, newPromise; | 383 ScriptPromise oldPromise, newPromise; |
| 395 ScriptValue oldActual, newActual; | 384 ScriptValue oldActual, newActual; |
| 396 GarbageCollectedScriptWrappable* oldValue = new GarbageCollectedScriptWrappa
ble("old"); | 385 GarbageCollectedScriptWrappable* oldValue = new GarbageCollectedScriptWrappa
ble("old"); |
| 397 GarbageCollectedScriptWrappable* newValue = new GarbageCollectedScriptWrappa
ble("new"); | 386 GarbageCollectedScriptWrappable* newValue = new GarbageCollectedScriptWrappa
ble("new"); |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 { | 536 { |
| 548 test(String("hello"), "hello", __FILE__, __LINE__); | 537 test(String("hello"), "hello", __FILE__, __LINE__); |
| 549 } | 538 } |
| 550 | 539 |
| 551 TEST_F(ScriptPromisePropertyNonScriptWrappableResolutionTargetTest, ResolveWithI
nteger) | 540 TEST_F(ScriptPromisePropertyNonScriptWrappableResolutionTargetTest, ResolveWithI
nteger) |
| 552 { | 541 { |
| 553 test(-1, "-1", __FILE__, __LINE__); | 542 test(-1, "-1", __FILE__, __LINE__); |
| 554 } | 543 } |
| 555 | 544 |
| 556 } // namespace | 545 } // namespace |
| OLD | NEW |