OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 #include <utility> | 53 #include <utility> |
54 | 54 |
55 namespace blink { | 55 namespace blink { |
56 | 56 |
57 namespace { | 57 namespace { |
58 const int64_t kShortIdleHandlerDelayMs = 1000; | 58 const int64_t kShortIdleHandlerDelayMs = 1000; |
59 const int64_t kLongIdleHandlerDelayMs = 10*1000; | 59 const int64_t kLongIdleHandlerDelayMs = 10*1000; |
60 | 60 |
61 class MicrotaskRunner : public WebThread::TaskObserver { | 61 class MicrotaskRunner : public WebThread::TaskObserver { |
62 public: | 62 public: |
| 63 explicit MicrotaskRunner(WorkerThread* workerThread) |
| 64 : m_workerThread(workerThread) |
| 65 { |
| 66 } |
| 67 |
63 virtual void willProcessTask() override { } | 68 virtual void willProcessTask() override { } |
64 virtual void didProcessTask() override | 69 virtual void didProcessTask() override |
65 { | 70 { |
66 Microtask::performCheckpoint(); | 71 Microtask::performCheckpoint(); |
67 V8Initializer::reportRejectedPromises(); | 72 if (WorkerGlobalScope* globalScope = m_workerThread->workerGlobalScope()
) { |
| 73 if (WorkerScriptController* scriptController = globalScope->script()
) |
| 74 scriptController->rejectedPromises()->processQueue(); |
| 75 } |
68 } | 76 } |
| 77 |
| 78 private: |
| 79 // Thread owns the microtask runner; reference remains |
| 80 // valid for the lifetime of this object. |
| 81 WorkerThread* m_workerThread; |
69 }; | 82 }; |
70 | 83 |
71 } // namespace | 84 } // namespace |
72 | 85 |
73 static Mutex& threadSetMutex() | 86 static Mutex& threadSetMutex() |
74 { | 87 { |
75 AtomicallyInitializedStaticReference(Mutex, mutex, new Mutex); | 88 AtomicallyInitializedStaticReference(Mutex, mutex, new Mutex); |
76 return mutex; | 89 return mutex; |
77 } | 90 } |
78 | 91 |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 MutexLocker lock(m_threadCreationMutex); | 316 MutexLocker lock(m_threadCreationMutex); |
304 | 317 |
305 // The worker was terminated before the thread had a chance to run. | 318 // The worker was terminated before the thread had a chance to run. |
306 if (m_terminated) { | 319 if (m_terminated) { |
307 // Notify the proxy that the WorkerGlobalScope has been disposed of. | 320 // Notify the proxy that the WorkerGlobalScope has been disposed of. |
308 // This can free this thread object, hence it must not be touched af
terwards. | 321 // This can free this thread object, hence it must not be touched af
terwards. |
309 m_workerReportingProxy.workerThreadTerminated(); | 322 m_workerReportingProxy.workerThreadTerminated(); |
310 return; | 323 return; |
311 } | 324 } |
312 | 325 |
313 m_microtaskRunner = adoptPtr(new MicrotaskRunner); | 326 m_microtaskRunner = adoptPtr(new MicrotaskRunner(this)); |
314 m_thread->addTaskObserver(m_microtaskRunner.get()); | 327 m_thread->addTaskObserver(m_microtaskRunner.get()); |
315 m_thread->attachGC(); | 328 m_thread->attachGC(); |
316 m_workerGlobalScope = createWorkerGlobalScope(m_startupData.release()); | 329 m_workerGlobalScope = createWorkerGlobalScope(m_startupData.release()); |
317 | 330 |
318 m_sharedTimer = adoptPtr(new WorkerSharedTimer(this)); | 331 m_sharedTimer = adoptPtr(new WorkerSharedTimer(this)); |
319 PlatformThreadData::current().threadTimers().setSharedTimer(m_sharedTime
r.get()); | 332 PlatformThreadData::current().threadTimers().setSharedTimer(m_sharedTime
r.get()); |
320 } | 333 } |
321 | 334 |
322 // The corresponding call to stopRunLoop() is in ~WorkerScriptController(). | 335 // The corresponding call to stopRunLoop() is in ~WorkerScriptController(). |
323 didStartRunLoop(); | 336 didStartRunLoop(); |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 InspectorInstrumentation::didLeaveNestedRunLoop(m_workerGlobalScope.get()); | 566 InspectorInstrumentation::didLeaveNestedRunLoop(m_workerGlobalScope.get()); |
554 } | 567 } |
555 | 568 |
556 void WorkerThread::setWorkerInspectorController(WorkerInspectorController* worke
rInspectorController) | 569 void WorkerThread::setWorkerInspectorController(WorkerInspectorController* worke
rInspectorController) |
557 { | 570 { |
558 MutexLocker locker(m_workerInspectorControllerMutex); | 571 MutexLocker locker(m_workerInspectorControllerMutex); |
559 m_workerInspectorController = workerInspectorController; | 572 m_workerInspectorController = workerInspectorController; |
560 } | 573 } |
561 | 574 |
562 } // namespace blink | 575 } // namespace blink |
OLD | NEW |