@@ -60,71 +60,13 @@ var isPerformingWork = false; |
60 | 60 | var isHostCallbackScheduled = false; |
61 | 61 | var isHostTimeoutScheduled = false; |
62 | 62 |
|
63 | | -function scheduler_flushTaskAtPriority_Immediate(callback, didTimeout) { |
64 | | - return callback(didTimeout); |
65 | | -} |
66 | | -function scheduler_flushTaskAtPriority_UserBlocking(callback, didTimeout) { |
67 | | - return callback(didTimeout); |
68 | | -} |
69 | | -function scheduler_flushTaskAtPriority_Normal(callback, didTimeout) { |
70 | | - return callback(didTimeout); |
71 | | -} |
72 | | -function scheduler_flushTaskAtPriority_Low(callback, didTimeout) { |
73 | | - return callback(didTimeout); |
74 | | -} |
75 | | -function scheduler_flushTaskAtPriority_Idle(callback, didTimeout) { |
76 | | - return callback(didTimeout); |
77 | | -} |
78 | | - |
79 | 63 | function flushTask(task, callback, currentTime) { |
80 | | - var previousPriorityLevel = currentPriorityLevel; |
81 | | - var previousTask = currentTask; |
82 | 64 | currentPriorityLevel = task.priorityLevel; |
83 | | - currentTask = task; |
84 | | - try { |
85 | | - var didUserCallbackTimeout = task.expirationTime <= currentTime; |
86 | | - // Add an extra function to the callstack. Profiling tools can use this |
87 | | - // to infer the priority of work that appears higher in the stack. |
88 | | - var continuationCallback; |
89 | | - switch (currentPriorityLevel) { |
90 | | - case ImmediatePriority: |
91 | | - continuationCallback = scheduler_flushTaskAtPriority_Immediate( |
92 | | - callback, |
93 | | - didUserCallbackTimeout, |
94 | | - ); |
95 | | - break; |
96 | | - case UserBlockingPriority: |
97 | | - continuationCallback = scheduler_flushTaskAtPriority_UserBlocking( |
98 | | - callback, |
99 | | - didUserCallbackTimeout, |
100 | | - ); |
101 | | - break; |
102 | | - case NormalPriority: |
103 | | - continuationCallback = scheduler_flushTaskAtPriority_Normal( |
104 | | - callback, |
105 | | - didUserCallbackTimeout, |
106 | | - ); |
107 | | - break; |
108 | | - case LowPriority: |
109 | | - continuationCallback = scheduler_flushTaskAtPriority_Low( |
110 | | - callback, |
111 | | - didUserCallbackTimeout, |
112 | | - ); |
113 | | - break; |
114 | | - case IdlePriority: |
115 | | - continuationCallback = scheduler_flushTaskAtPriority_Idle( |
116 | | - callback, |
117 | | - didUserCallbackTimeout, |
118 | | - ); |
119 | | - break; |
120 | | - } |
121 | | - return typeof continuationCallback === 'function' |
122 | | - ? continuationCallback |
123 | | - : null; |
124 | | - } finally { |
125 | | - currentPriorityLevel = previousPriorityLevel; |
126 | | - currentTask = previousTask; |
127 | | - } |
| 65 | + var didUserCallbackTimeout = task.expirationTime <= currentTime; |
| 66 | + var continuationCallback = callback(didUserCallbackTimeout); |
| 67 | + return typeof continuationCallback === 'function' |
| 68 | + ? continuationCallback |
| 69 | + : null; |
128 | 70 | } |
129 | 71 |
|
130 | 72 | function advanceTimers(currentTime) { |
@@ -174,26 +116,30 @@ function flushWork(hasTimeRemaining, initialTime) { |
174 | 116 | } |
175 | 117 |
|
176 | 118 | isPerformingWork = true; |
| 119 | + const previousPriorityLevel = currentPriorityLevel; |
177 | 120 | try { |
178 | 121 | let currentTime = initialTime; |
179 | 122 | advanceTimers(currentTime); |
180 | | - let task = peek(taskQueue); |
181 | | - while (task !== null && !(enableSchedulerDebugging && isSchedulerPaused)) { |
| 123 | + currentTask = peek(taskQueue); |
| 124 | + while ( |
| 125 | + currentTask !== null && |
| 126 | + !(enableSchedulerDebugging && isSchedulerPaused) |
| 127 | + ) { |
182 | 128 | if ( |
183 | | - task.expirationTime > currentTime && |
| 129 | + currentTask.expirationTime > currentTime && |
184 | 130 | (!hasTimeRemaining || shouldYieldToHost()) |
185 | 131 | ) { |
186 | | - // This task hasn't expired, and we've reached the deadline. |
| 132 | + // This currentTask hasn't expired, and we've reached the deadline. |
187 | 133 | break; |
188 | 134 | } |
189 | | - const callback = task.callback; |
| 135 | + const callback = currentTask.callback; |
190 | 136 | if (callback !== null) { |
191 | | - task.callback = null; |
192 | | - const continuation = flushTask(task, callback, currentTime); |
| 137 | + currentTask.callback = null; |
| 138 | + const continuation = flushTask(currentTask, callback, currentTime); |
193 | 139 | if (continuation !== null) { |
194 | | - task.callback = continuation; |
| 140 | + currentTask.callback = continuation; |
195 | 141 | } else { |
196 | | - if (task === peek(taskQueue)) { |
| 142 | + if (currentTask === peek(taskQueue)) { |
197 | 143 | pop(taskQueue); |
198 | 144 | } |
199 | 145 | } |
@@ -202,10 +148,10 @@ function flushWork(hasTimeRemaining, initialTime) { |
202 | 148 | } else { |
203 | 149 | pop(taskQueue); |
204 | 150 | } |
205 | | - task = peek(taskQueue); |
| 151 | + currentTask = peek(taskQueue); |
206 | 152 | } |
207 | 153 | // Return whether there's additional work |
208 | | - if (task !== null) { |
| 154 | + if (currentTask !== null) { |
209 | 155 | return true; |
210 | 156 | } else { |
211 | 157 | let firstTimer = peek(timerQueue); |
@@ -215,6 +161,8 @@ function flushWork(hasTimeRemaining, initialTime) { |
215 | 161 | return false; |
216 | 162 | } |
217 | 163 | } finally { |
| 164 | + currentTask = null; |
| 165 | + currentPriorityLevel = previousPriorityLevel; |
218 | 166 | isPerformingWork = false; |
219 | 167 | } |
220 | 168 | } |
|