OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/RejectedPromises.h" | 5 #include "bindings/core/v8/RejectedPromises.h" |
6 | 6 |
7 #include "bindings/core/v8/ScopedPersistent.h" | 7 #include "bindings/core/v8/ScopedPersistent.h" |
8 #include "bindings/core/v8/ScriptCallStack.h" | 8 #include "bindings/core/v8/ScriptCallStack.h" |
9 #include "bindings/core/v8/ScriptState.h" | 9 #include "bindings/core/v8/ScriptState.h" |
10 #include "bindings/core/v8/ScriptValue.h" | 10 #include "bindings/core/v8/ScriptValue.h" |
11 #include "bindings/core/v8/V8Binding.h" | 11 #include "bindings/core/v8/V8Binding.h" |
12 #include "core/dom/ExecutionContext.h" | 12 #include "core/dom/ExecutionContext.h" |
13 #include "core/events/EventTarget.h" | 13 #include "core/events/EventTarget.h" |
14 #include "core/events/PromiseRejectionEvent.h" | 14 #include "core/events/PromiseRejectionEvent.h" |
15 #include "core/inspector/ConsoleMessage.h" | 15 #include "core/inspector/ConsoleMessage.h" |
16 #include "core/inspector/ScriptArguments.h" | 16 #include "core/inspector/ScriptArguments.h" |
17 #include "platform/RuntimeEnabledFeatures.h" | 17 #include "platform/RuntimeEnabledFeatures.h" |
18 #include "platform/Task.h" | |
19 #include "public/platform/Platform.h" | 18 #include "public/platform/Platform.h" |
20 #include "public/platform/WebScheduler.h" | 19 #include "public/platform/WebScheduler.h" |
21 #include "public/platform/WebTaskRunner.h" | 20 #include "public/platform/WebTaskRunner.h" |
22 #include "public/platform/WebThread.h" | 21 #include "public/platform/WebThread.h" |
23 #include "wtf/Functional.h" | 22 #include "wtf/Functional.h" |
24 | 23 |
25 namespace blink { | 24 namespace blink { |
26 | 25 |
27 static const unsigned maxReportedHandlersPendingResolution = 1000; | 26 static const unsigned maxReportedHandlersPendingResolution = 1000; |
28 | 27 |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 m_queue.remove(it); | 213 m_queue.remove(it); |
215 return; | 214 return; |
216 } | 215 } |
217 } | 216 } |
218 | 217 |
219 // Then look it up in the reported errors. | 218 // Then look it up in the reported errors. |
220 for (size_t i = 0; i < m_reportedAsErrors.size(); ++i) { | 219 for (size_t i = 0; i < m_reportedAsErrors.size(); ++i) { |
221 auto& message = m_reportedAsErrors.at(i); | 220 auto& message = m_reportedAsErrors.at(i); |
222 if (!message->isCollected() && message->hasPromise(data.GetPromise())) { | 221 if (!message->isCollected() && message->hasPromise(data.GetPromise())) { |
223 message->makePromiseStrong(); | 222 message->makePromiseStrong(); |
224 Platform::current()->currentThread()->scheduler()->timerTaskRunner()
->postTask(BLINK_FROM_HERE, new Task(bind(&RejectedPromises::revokeNow, PassRefP
trWillBeRawPtr<RejectedPromises>(this), message.release()))); | 223 Platform::current()->currentThread()->scheduler()->timerTaskRunner()
->postTask(BLINK_FROM_HERE, bind(&RejectedPromises::revokeNow, PassRefPtrWillBeR
awPtr<RejectedPromises>(this), message.release())); |
225 m_reportedAsErrors.remove(i); | 224 m_reportedAsErrors.remove(i); |
226 return; | 225 return; |
227 } | 226 } |
228 } | 227 } |
229 } | 228 } |
230 | 229 |
231 PassOwnPtr<RejectedPromises::MessageQueue> RejectedPromises::createMessageQueue(
) | 230 PassOwnPtr<RejectedPromises::MessageQueue> RejectedPromises::createMessageQueue(
) |
232 { | 231 { |
233 return adoptPtr(new MessageQueue()); | 232 return adoptPtr(new MessageQueue()); |
234 } | 233 } |
235 | 234 |
236 void RejectedPromises::dispose() | 235 void RejectedPromises::dispose() |
237 { | 236 { |
238 if (m_queue.isEmpty()) | 237 if (m_queue.isEmpty()) |
239 return; | 238 return; |
240 | 239 |
241 OwnPtr<MessageQueue> queue = createMessageQueue(); | 240 OwnPtr<MessageQueue> queue = createMessageQueue(); |
242 queue->swap(m_queue); | 241 queue->swap(m_queue); |
243 processQueueNow(queue.release()); | 242 processQueueNow(queue.release()); |
244 } | 243 } |
245 | 244 |
246 void RejectedPromises::processQueue() | 245 void RejectedPromises::processQueue() |
247 { | 246 { |
248 if (m_queue.isEmpty()) | 247 if (m_queue.isEmpty()) |
249 return; | 248 return; |
250 | 249 |
251 OwnPtr<MessageQueue> queue = createMessageQueue(); | 250 OwnPtr<MessageQueue> queue = createMessageQueue(); |
252 queue->swap(m_queue); | 251 queue->swap(m_queue); |
253 Platform::current()->currentThread()->scheduler()->timerTaskRunner()->postTa
sk(BLINK_FROM_HERE, new Task(bind(&RejectedPromises::processQueueNow, PassRefPtr
<RejectedPromises>(this), queue.release()))); | 252 Platform::current()->currentThread()->scheduler()->timerTaskRunner()->postTa
sk(BLINK_FROM_HERE, bind(&RejectedPromises::processQueueNow, PassRefPtr<Rejected
Promises>(this), queue.release())); |
254 } | 253 } |
255 | 254 |
256 void RejectedPromises::processQueueNow(PassOwnPtr<MessageQueue> queue) | 255 void RejectedPromises::processQueueNow(PassOwnPtr<MessageQueue> queue) |
257 { | 256 { |
258 // Remove collected handlers. | 257 // Remove collected handlers. |
259 for (size_t i = 0; i < m_reportedAsErrors.size();) { | 258 for (size_t i = 0; i < m_reportedAsErrors.size();) { |
260 if (m_reportedAsErrors.at(i)->isCollected()) | 259 if (m_reportedAsErrors.at(i)->isCollected()) |
261 m_reportedAsErrors.remove(i); | 260 m_reportedAsErrors.remove(i); |
262 else | 261 else |
263 ++i; | 262 ++i; |
(...skipping 12 matching lines...) Expand all Loading... |
276 } | 275 } |
277 } | 276 } |
278 } | 277 } |
279 | 278 |
280 void RejectedPromises::revokeNow(PassOwnPtr<Message> message) | 279 void RejectedPromises::revokeNow(PassOwnPtr<Message> message) |
281 { | 280 { |
282 message->revoke(); | 281 message->revoke(); |
283 } | 282 } |
284 | 283 |
285 } // namespace blink | 284 } // namespace blink |
OLD | NEW |