| 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 "bindings/core/v8/ScriptPromiseResolver.h" | 5 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ScriptFunction.h" | 7 #include "bindings/core/v8/ScriptFunction.h" |
| 8 #include "bindings/core/v8/ScriptValue.h" | 8 #include "bindings/core/v8/ScriptValue.h" |
| 9 #include "bindings/core/v8/V8Binding.h" | 9 #include "bindings/core/v8/V8Binding.h" |
| 10 #include "core/dom/DOMException.h" | 10 #include "core/dom/DOMException.h" |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 } | 172 } |
| 173 | 173 |
| 174 String onFulfilled, onRejected; | 174 String onFulfilled, onRejected; |
| 175 ASSERT_FALSE(promise.isEmpty()); | 175 ASSERT_FALSE(promise.isEmpty()); |
| 176 { | 176 { |
| 177 ScriptState::Scope scope(getScriptState()); | 177 ScriptState::Scope scope(getScriptState()); |
| 178 promise.then(Function::createFunction(getScriptState(), &onFulfilled), | 178 promise.then(Function::createFunction(getScriptState(), &onFulfilled), |
| 179 Function::createFunction(getScriptState(), &onRejected)); | 179 Function::createFunction(getScriptState(), &onRejected)); |
| 180 } | 180 } |
| 181 | 181 |
| 182 getExecutionContext()->stopActiveDOMObjects(); | 182 getExecutionContext()->notifyContextDestroyed(); |
| 183 { | 183 { |
| 184 ScriptState::Scope scope(getScriptState()); | 184 ScriptState::Scope scope(getScriptState()); |
| 185 EXPECT_TRUE(resolver->promise().isEmpty()); | 185 EXPECT_TRUE(resolver->promise().isEmpty()); |
| 186 } | 186 } |
| 187 | 187 |
| 188 resolver->resolve("hello"); | 188 resolver->resolve("hello"); |
| 189 v8::MicrotasksScope::PerformCheckpoint(isolate()); | 189 v8::MicrotasksScope::PerformCheckpoint(isolate()); |
| 190 | 190 |
| 191 EXPECT_EQ(String(), onFulfilled); | 191 EXPECT_EQ(String(), onFulfilled); |
| 192 EXPECT_EQ(String(), onRejected); | 192 EXPECT_EQ(String(), onRejected); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 ScriptPromiseResolver* resolver = nullptr; | 256 ScriptPromiseResolver* resolver = nullptr; |
| 257 { | 257 { |
| 258 ScriptState::Scope scope(getScriptState()); | 258 ScriptState::Scope scope(getScriptState()); |
| 259 resolver = ScriptPromiseResolverKeepAlive::create(getScriptState()); | 259 resolver = ScriptPromiseResolverKeepAlive::create(getScriptState()); |
| 260 } | 260 } |
| 261 resolver->keepAliveWhilePending(); | 261 resolver->keepAliveWhilePending(); |
| 262 ThreadState::current()->collectGarbage( | 262 ThreadState::current()->collectGarbage( |
| 263 BlinkGC::NoHeapPointersOnStack, BlinkGC::GCWithSweep, BlinkGC::ForcedGC); | 263 BlinkGC::NoHeapPointersOnStack, BlinkGC::GCWithSweep, BlinkGC::ForcedGC); |
| 264 EXPECT_TRUE(ScriptPromiseResolverKeepAlive::isAlive()); | 264 EXPECT_TRUE(ScriptPromiseResolverKeepAlive::isAlive()); |
| 265 | 265 |
| 266 getExecutionContext()->stopActiveDOMObjects(); | 266 getExecutionContext()->notifyContextDestroyed(); |
| 267 ThreadState::current()->collectGarbage( | 267 ThreadState::current()->collectGarbage( |
| 268 BlinkGC::NoHeapPointersOnStack, BlinkGC::GCWithSweep, BlinkGC::ForcedGC); | 268 BlinkGC::NoHeapPointersOnStack, BlinkGC::GCWithSweep, BlinkGC::ForcedGC); |
| 269 EXPECT_FALSE(ScriptPromiseResolverKeepAlive::isAlive()); | 269 EXPECT_FALSE(ScriptPromiseResolverKeepAlive::isAlive()); |
| 270 } | 270 } |
| 271 | 271 |
| 272 TEST_F(ScriptPromiseResolverTest, suspend) { | 272 TEST_F(ScriptPromiseResolverTest, suspend) { |
| 273 ScriptPromiseResolverKeepAlive::reset(); | 273 ScriptPromiseResolverKeepAlive::reset(); |
| 274 ScriptPromiseResolver* resolver = nullptr; | 274 ScriptPromiseResolver* resolver = nullptr; |
| 275 { | 275 { |
| 276 ScriptState::Scope scope(getScriptState()); | 276 ScriptState::Scope scope(getScriptState()); |
| 277 resolver = ScriptPromiseResolverKeepAlive::create(getScriptState()); | 277 resolver = ScriptPromiseResolverKeepAlive::create(getScriptState()); |
| 278 } | 278 } |
| 279 resolver->keepAliveWhilePending(); | 279 resolver->keepAliveWhilePending(); |
| 280 ThreadState::current()->collectGarbage( | 280 ThreadState::current()->collectGarbage( |
| 281 BlinkGC::NoHeapPointersOnStack, BlinkGC::GCWithSweep, BlinkGC::ForcedGC); | 281 BlinkGC::NoHeapPointersOnStack, BlinkGC::GCWithSweep, BlinkGC::ForcedGC); |
| 282 ASSERT_TRUE(ScriptPromiseResolverKeepAlive::isAlive()); | 282 ASSERT_TRUE(ScriptPromiseResolverKeepAlive::isAlive()); |
| 283 | 283 |
| 284 getExecutionContext()->suspendActiveDOMObjects(); | 284 getExecutionContext()->suspendActiveDOMObjects(); |
| 285 resolver->resolve("hello"); | 285 resolver->resolve("hello"); |
| 286 ThreadState::current()->collectGarbage( | 286 ThreadState::current()->collectGarbage( |
| 287 BlinkGC::NoHeapPointersOnStack, BlinkGC::GCWithSweep, BlinkGC::ForcedGC); | 287 BlinkGC::NoHeapPointersOnStack, BlinkGC::GCWithSweep, BlinkGC::ForcedGC); |
| 288 EXPECT_TRUE(ScriptPromiseResolverKeepAlive::isAlive()); | 288 EXPECT_TRUE(ScriptPromiseResolverKeepAlive::isAlive()); |
| 289 | 289 |
| 290 getExecutionContext()->stopActiveDOMObjects(); | 290 getExecutionContext()->notifyContextDestroyed(); |
| 291 ThreadState::current()->collectGarbage( | 291 ThreadState::current()->collectGarbage( |
| 292 BlinkGC::NoHeapPointersOnStack, BlinkGC::GCWithSweep, BlinkGC::ForcedGC); | 292 BlinkGC::NoHeapPointersOnStack, BlinkGC::GCWithSweep, BlinkGC::ForcedGC); |
| 293 EXPECT_FALSE(ScriptPromiseResolverKeepAlive::isAlive()); | 293 EXPECT_FALSE(ScriptPromiseResolverKeepAlive::isAlive()); |
| 294 } | 294 } |
| 295 | 295 |
| 296 TEST_F(ScriptPromiseResolverTest, resolveVoid) { | 296 TEST_F(ScriptPromiseResolverTest, resolveVoid) { |
| 297 ScriptPromiseResolver* resolver = nullptr; | 297 ScriptPromiseResolver* resolver = nullptr; |
| 298 ScriptPromise promise; | 298 ScriptPromise promise; |
| 299 { | 299 { |
| 300 ScriptState::Scope scope(getScriptState()); | 300 ScriptState::Scope scope(getScriptState()); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 resolver->reject(); | 337 resolver->reject(); |
| 338 v8::MicrotasksScope::PerformCheckpoint(isolate()); | 338 v8::MicrotasksScope::PerformCheckpoint(isolate()); |
| 339 | 339 |
| 340 EXPECT_EQ(String(), onFulfilled); | 340 EXPECT_EQ(String(), onFulfilled); |
| 341 EXPECT_EQ("undefined", onRejected); | 341 EXPECT_EQ("undefined", onRejected); |
| 342 } | 342 } |
| 343 | 343 |
| 344 } // namespace | 344 } // namespace |
| 345 | 345 |
| 346 } // namespace blink | 346 } // namespace blink |
| OLD | NEW |