| 1 | /**
|
|---|
| 2 | * @license React
|
|---|
| 3 | * scheduler-unstable_mock.development.js
|
|---|
| 4 | *
|
|---|
| 5 | * Copyright (c) Meta Platforms, Inc. and affiliates.
|
|---|
| 6 | *
|
|---|
| 7 | * This source code is licensed under the MIT license found in the
|
|---|
| 8 | * LICENSE file in the root directory of this source tree.
|
|---|
| 9 | */
|
|---|
| 10 |
|
|---|
| 11 | "use strict";
|
|---|
| 12 | "production" !== process.env.NODE_ENV &&
|
|---|
| 13 | (function () {
|
|---|
| 14 | function push(heap, node) {
|
|---|
| 15 | var index = heap.length;
|
|---|
| 16 | heap.push(node);
|
|---|
| 17 | a: for (; 0 < index; ) {
|
|---|
| 18 | var parentIndex = (index - 1) >>> 1,
|
|---|
| 19 | parent = heap[parentIndex];
|
|---|
| 20 | if (0 < compare(parent, node))
|
|---|
| 21 | (heap[parentIndex] = node),
|
|---|
| 22 | (heap[index] = parent),
|
|---|
| 23 | (index = parentIndex);
|
|---|
| 24 | else break a;
|
|---|
| 25 | }
|
|---|
| 26 | }
|
|---|
| 27 | function peek(heap) {
|
|---|
| 28 | return 0 === heap.length ? null : heap[0];
|
|---|
| 29 | }
|
|---|
| 30 | function pop(heap) {
|
|---|
| 31 | if (0 === heap.length) return null;
|
|---|
| 32 | var first = heap[0],
|
|---|
| 33 | last = heap.pop();
|
|---|
| 34 | if (last !== first) {
|
|---|
| 35 | heap[0] = last;
|
|---|
| 36 | a: for (
|
|---|
| 37 | var index = 0, length = heap.length, halfLength = length >>> 1;
|
|---|
| 38 | index < halfLength;
|
|---|
| 39 |
|
|---|
| 40 | ) {
|
|---|
| 41 | var leftIndex = 2 * (index + 1) - 1,
|
|---|
| 42 | left = heap[leftIndex],
|
|---|
| 43 | rightIndex = leftIndex + 1,
|
|---|
| 44 | right = heap[rightIndex];
|
|---|
| 45 | if (0 > compare(left, last))
|
|---|
| 46 | rightIndex < length && 0 > compare(right, left)
|
|---|
| 47 | ? ((heap[index] = right),
|
|---|
| 48 | (heap[rightIndex] = last),
|
|---|
| 49 | (index = rightIndex))
|
|---|
| 50 | : ((heap[index] = left),
|
|---|
| 51 | (heap[leftIndex] = last),
|
|---|
| 52 | (index = leftIndex));
|
|---|
| 53 | else if (rightIndex < length && 0 > compare(right, last))
|
|---|
| 54 | (heap[index] = right),
|
|---|
| 55 | (heap[rightIndex] = last),
|
|---|
| 56 | (index = rightIndex);
|
|---|
| 57 | else break a;
|
|---|
| 58 | }
|
|---|
| 59 | }
|
|---|
| 60 | return first;
|
|---|
| 61 | }
|
|---|
| 62 | function compare(a, b) {
|
|---|
| 63 | var diff = a.sortIndex - b.sortIndex;
|
|---|
| 64 | return 0 !== diff ? diff : a.id - b.id;
|
|---|
| 65 | }
|
|---|
| 66 | function advanceTimers(currentTime) {
|
|---|
| 67 | for (var timer = peek(timerQueue); null !== timer; ) {
|
|---|
| 68 | if (null === timer.callback) pop(timerQueue);
|
|---|
| 69 | else if (timer.startTime <= currentTime)
|
|---|
| 70 | pop(timerQueue),
|
|---|
| 71 | (timer.sortIndex = timer.expirationTime),
|
|---|
| 72 | push(taskQueue, timer);
|
|---|
| 73 | else break;
|
|---|
| 74 | timer = peek(timerQueue);
|
|---|
| 75 | }
|
|---|
| 76 | }
|
|---|
| 77 | function handleTimeout(currentTime) {
|
|---|
| 78 | isHostTimeoutScheduled = !1;
|
|---|
| 79 | advanceTimers(currentTime);
|
|---|
| 80 | if (!isHostCallbackScheduled)
|
|---|
| 81 | if (null !== peek(taskQueue))
|
|---|
| 82 | (isHostCallbackScheduled = !0), (scheduledCallback = flushWork);
|
|---|
| 83 | else {
|
|---|
| 84 | var firstTimer = peek(timerQueue);
|
|---|
| 85 | null !== firstTimer &&
|
|---|
| 86 | ((currentTime = firstTimer.startTime - currentTime),
|
|---|
| 87 | (scheduledTimeout = handleTimeout),
|
|---|
| 88 | (timeoutTime = currentMockTime + currentTime));
|
|---|
| 89 | }
|
|---|
| 90 | }
|
|---|
| 91 | function flushWork(hasTimeRemaining, initialTime) {
|
|---|
| 92 | isHostCallbackScheduled = !1;
|
|---|
| 93 | isHostTimeoutScheduled &&
|
|---|
| 94 | ((isHostTimeoutScheduled = !1),
|
|---|
| 95 | (scheduledTimeout = null),
|
|---|
| 96 | (timeoutTime = -1));
|
|---|
| 97 | isPerformingWork = !0;
|
|---|
| 98 | var previousPriorityLevel = currentPriorityLevel;
|
|---|
| 99 | try {
|
|---|
| 100 | a: {
|
|---|
| 101 | advanceTimers(initialTime);
|
|---|
| 102 | for (
|
|---|
| 103 | currentTask = peek(taskQueue);
|
|---|
| 104 | null !== currentTask &&
|
|---|
| 105 | (!(currentTask.expirationTime > initialTime) ||
|
|---|
| 106 | (hasTimeRemaining && !shouldYieldToHost()));
|
|---|
| 107 |
|
|---|
| 108 | ) {
|
|---|
| 109 | var callback = currentTask.callback;
|
|---|
| 110 | if ("function" === typeof callback) {
|
|---|
| 111 | currentTask.callback = null;
|
|---|
| 112 | currentPriorityLevel = currentTask.priorityLevel;
|
|---|
| 113 | var continuationCallback = callback(
|
|---|
| 114 | currentTask.expirationTime <= initialTime
|
|---|
| 115 | );
|
|---|
| 116 | initialTime = currentMockTime;
|
|---|
| 117 | if ("function" === typeof continuationCallback) {
|
|---|
| 118 | if (
|
|---|
| 119 | ((currentTask.callback = continuationCallback),
|
|---|
| 120 | advanceTimers(initialTime),
|
|---|
| 121 | shouldYieldForPaint)
|
|---|
| 122 | ) {
|
|---|
| 123 | var JSCompiler_inline_result = (needsPaint = !0);
|
|---|
| 124 | break a;
|
|---|
| 125 | }
|
|---|
| 126 | } else
|
|---|
| 127 | currentTask === peek(taskQueue) && pop(taskQueue),
|
|---|
| 128 | advanceTimers(initialTime);
|
|---|
| 129 | } else pop(taskQueue);
|
|---|
| 130 | currentTask = peek(taskQueue);
|
|---|
| 131 | }
|
|---|
| 132 | if (null !== currentTask) JSCompiler_inline_result = !0;
|
|---|
| 133 | else {
|
|---|
| 134 | var firstTimer = peek(timerQueue);
|
|---|
| 135 | if (null !== firstTimer) {
|
|---|
| 136 | var ms = firstTimer.startTime - initialTime;
|
|---|
| 137 | scheduledTimeout = handleTimeout;
|
|---|
| 138 | timeoutTime = currentMockTime + ms;
|
|---|
| 139 | }
|
|---|
| 140 | JSCompiler_inline_result = !1;
|
|---|
| 141 | }
|
|---|
| 142 | }
|
|---|
| 143 | return JSCompiler_inline_result;
|
|---|
| 144 | } finally {
|
|---|
| 145 | (currentTask = null),
|
|---|
| 146 | (currentPriorityLevel = previousPriorityLevel),
|
|---|
| 147 | (isPerformingWork = !1);
|
|---|
| 148 | }
|
|---|
| 149 | }
|
|---|
| 150 | function shouldYieldToHost() {
|
|---|
| 151 | return (0 === expectedNumberOfYields && null === yieldedValues) ||
|
|---|
| 152 | (-1 !== expectedNumberOfYields &&
|
|---|
| 153 | null !== yieldedValues &&
|
|---|
| 154 | yieldedValues.length >= expectedNumberOfYields) ||
|
|---|
| 155 | (shouldYieldForPaint && needsPaint)
|
|---|
| 156 | ? (didStop = !0)
|
|---|
| 157 | : !1;
|
|---|
| 158 | }
|
|---|
| 159 | function unstable_flushAllWithoutAsserting() {
|
|---|
| 160 | if (isFlushing) throw Error("Already flushing work.");
|
|---|
| 161 | if (null !== scheduledCallback) {
|
|---|
| 162 | var cb = scheduledCallback;
|
|---|
| 163 | isFlushing = !0;
|
|---|
| 164 | try {
|
|---|
| 165 | var hasMoreWork = !0;
|
|---|
| 166 | do hasMoreWork = cb(!0, currentMockTime);
|
|---|
| 167 | while (hasMoreWork);
|
|---|
| 168 | hasMoreWork || (scheduledCallback = null);
|
|---|
| 169 | return !0;
|
|---|
| 170 | } finally {
|
|---|
| 171 | isFlushing = !1;
|
|---|
| 172 | }
|
|---|
| 173 | } else return !1;
|
|---|
| 174 | }
|
|---|
| 175 | var taskQueue = [],
|
|---|
| 176 | timerQueue = [],
|
|---|
| 177 | taskIdCounter = 1,
|
|---|
| 178 | currentTask = null,
|
|---|
| 179 | currentPriorityLevel = 3,
|
|---|
| 180 | isPerformingWork = !1,
|
|---|
| 181 | isHostCallbackScheduled = !1,
|
|---|
| 182 | isHostTimeoutScheduled = !1,
|
|---|
| 183 | currentMockTime = 0,
|
|---|
| 184 | scheduledCallback = null,
|
|---|
| 185 | scheduledTimeout = null,
|
|---|
| 186 | timeoutTime = -1,
|
|---|
| 187 | yieldedValues = null,
|
|---|
| 188 | expectedNumberOfYields = -1,
|
|---|
| 189 | didStop = !1,
|
|---|
| 190 | isFlushing = !1,
|
|---|
| 191 | needsPaint = !1,
|
|---|
| 192 | shouldYieldForPaint = !1,
|
|---|
| 193 | disableYieldValue = !1;
|
|---|
| 194 | exports.log = function (value) {
|
|---|
| 195 | "disabledLog" === console.log.name ||
|
|---|
| 196 | disableYieldValue ||
|
|---|
| 197 | (null === yieldedValues
|
|---|
| 198 | ? (yieldedValues = [value])
|
|---|
| 199 | : yieldedValues.push(value));
|
|---|
| 200 | };
|
|---|
| 201 | exports.reset = function () {
|
|---|
| 202 | if (isFlushing) throw Error("Cannot reset while already flushing work.");
|
|---|
| 203 | currentMockTime = 0;
|
|---|
| 204 | scheduledTimeout = scheduledCallback = null;
|
|---|
| 205 | timeoutTime = -1;
|
|---|
| 206 | yieldedValues = null;
|
|---|
| 207 | expectedNumberOfYields = -1;
|
|---|
| 208 | needsPaint = isFlushing = didStop = !1;
|
|---|
| 209 | };
|
|---|
| 210 | exports.unstable_IdlePriority = 5;
|
|---|
| 211 | exports.unstable_ImmediatePriority = 1;
|
|---|
| 212 | exports.unstable_LowPriority = 4;
|
|---|
| 213 | exports.unstable_NormalPriority = 3;
|
|---|
| 214 | exports.unstable_Profiling = null;
|
|---|
| 215 | exports.unstable_UserBlockingPriority = 2;
|
|---|
| 216 | exports.unstable_advanceTime = function (ms) {
|
|---|
| 217 | "disabledLog" === console.log.name ||
|
|---|
| 218 | disableYieldValue ||
|
|---|
| 219 | ((currentMockTime += ms),
|
|---|
| 220 | null !== scheduledTimeout &&
|
|---|
| 221 | timeoutTime <= currentMockTime &&
|
|---|
| 222 | (scheduledTimeout(currentMockTime),
|
|---|
| 223 | (timeoutTime = -1),
|
|---|
| 224 | (scheduledTimeout = null)));
|
|---|
| 225 | };
|
|---|
| 226 | exports.unstable_cancelCallback = function (task) {
|
|---|
| 227 | task.callback = null;
|
|---|
| 228 | };
|
|---|
| 229 | exports.unstable_clearLog = function () {
|
|---|
| 230 | if (null === yieldedValues) return [];
|
|---|
| 231 | var values = yieldedValues;
|
|---|
| 232 | yieldedValues = null;
|
|---|
| 233 | return values;
|
|---|
| 234 | };
|
|---|
| 235 | exports.unstable_flushAll = function () {
|
|---|
| 236 | if (null !== yieldedValues)
|
|---|
| 237 | throw Error(
|
|---|
| 238 | "Log is not empty. Assert on the log of yielded values before flushing additional work."
|
|---|
| 239 | );
|
|---|
| 240 | unstable_flushAllWithoutAsserting();
|
|---|
| 241 | if (null !== yieldedValues)
|
|---|
| 242 | throw Error(
|
|---|
| 243 | "While flushing work, something yielded a value. Use an assertion helper to assert on the log of yielded values, e.g. expect(Scheduler).toFlushAndYield([...])"
|
|---|
| 244 | );
|
|---|
| 245 | };
|
|---|
| 246 | exports.unstable_flushAllWithoutAsserting =
|
|---|
| 247 | unstable_flushAllWithoutAsserting;
|
|---|
| 248 | exports.unstable_flushExpired = function () {
|
|---|
| 249 | if (isFlushing) throw Error("Already flushing work.");
|
|---|
| 250 | if (null !== scheduledCallback) {
|
|---|
| 251 | isFlushing = !0;
|
|---|
| 252 | try {
|
|---|
| 253 | scheduledCallback(!1, currentMockTime) || (scheduledCallback = null);
|
|---|
| 254 | } finally {
|
|---|
| 255 | isFlushing = !1;
|
|---|
| 256 | }
|
|---|
| 257 | }
|
|---|
| 258 | };
|
|---|
| 259 | exports.unstable_flushNumberOfYields = function (count) {
|
|---|
| 260 | if (isFlushing) throw Error("Already flushing work.");
|
|---|
| 261 | if (null !== scheduledCallback) {
|
|---|
| 262 | var cb = scheduledCallback;
|
|---|
| 263 | expectedNumberOfYields = count;
|
|---|
| 264 | isFlushing = !0;
|
|---|
| 265 | try {
|
|---|
| 266 | count = !0;
|
|---|
| 267 | do count = cb(!0, currentMockTime);
|
|---|
| 268 | while (count && !didStop);
|
|---|
| 269 | count || (scheduledCallback = null);
|
|---|
| 270 | } finally {
|
|---|
| 271 | (expectedNumberOfYields = -1), (isFlushing = didStop = !1);
|
|---|
| 272 | }
|
|---|
| 273 | }
|
|---|
| 274 | };
|
|---|
| 275 | exports.unstable_flushUntilNextPaint = function () {
|
|---|
| 276 | if (isFlushing) throw Error("Already flushing work.");
|
|---|
| 277 | if (null !== scheduledCallback) {
|
|---|
| 278 | var cb = scheduledCallback;
|
|---|
| 279 | shouldYieldForPaint = !0;
|
|---|
| 280 | needsPaint = !1;
|
|---|
| 281 | isFlushing = !0;
|
|---|
| 282 | try {
|
|---|
| 283 | var hasMoreWork = !0;
|
|---|
| 284 | do hasMoreWork = cb(!0, currentMockTime);
|
|---|
| 285 | while (hasMoreWork && !didStop);
|
|---|
| 286 | hasMoreWork || (scheduledCallback = null);
|
|---|
| 287 | } finally {
|
|---|
| 288 | isFlushing = didStop = shouldYieldForPaint = !1;
|
|---|
| 289 | }
|
|---|
| 290 | }
|
|---|
| 291 | return !1;
|
|---|
| 292 | };
|
|---|
| 293 | exports.unstable_forceFrameRate = function () {};
|
|---|
| 294 | exports.unstable_getCurrentPriorityLevel = function () {
|
|---|
| 295 | return currentPriorityLevel;
|
|---|
| 296 | };
|
|---|
| 297 | exports.unstable_hasPendingWork = function () {
|
|---|
| 298 | return null !== scheduledCallback;
|
|---|
| 299 | };
|
|---|
| 300 | exports.unstable_next = function (eventHandler) {
|
|---|
| 301 | switch (currentPriorityLevel) {
|
|---|
| 302 | case 1:
|
|---|
| 303 | case 2:
|
|---|
| 304 | case 3:
|
|---|
| 305 | var priorityLevel = 3;
|
|---|
| 306 | break;
|
|---|
| 307 | default:
|
|---|
| 308 | priorityLevel = currentPriorityLevel;
|
|---|
| 309 | }
|
|---|
| 310 | var previousPriorityLevel = currentPriorityLevel;
|
|---|
| 311 | currentPriorityLevel = priorityLevel;
|
|---|
| 312 | try {
|
|---|
| 313 | return eventHandler();
|
|---|
| 314 | } finally {
|
|---|
| 315 | currentPriorityLevel = previousPriorityLevel;
|
|---|
| 316 | }
|
|---|
| 317 | };
|
|---|
| 318 | exports.unstable_now = function () {
|
|---|
| 319 | return currentMockTime;
|
|---|
| 320 | };
|
|---|
| 321 | exports.unstable_requestPaint = function () {
|
|---|
| 322 | needsPaint = !0;
|
|---|
| 323 | };
|
|---|
| 324 | exports.unstable_runWithPriority = function (priorityLevel, eventHandler) {
|
|---|
| 325 | switch (priorityLevel) {
|
|---|
| 326 | case 1:
|
|---|
| 327 | case 2:
|
|---|
| 328 | case 3:
|
|---|
| 329 | case 4:
|
|---|
| 330 | case 5:
|
|---|
| 331 | break;
|
|---|
| 332 | default:
|
|---|
| 333 | priorityLevel = 3;
|
|---|
| 334 | }
|
|---|
| 335 | var previousPriorityLevel = currentPriorityLevel;
|
|---|
| 336 | currentPriorityLevel = priorityLevel;
|
|---|
| 337 | try {
|
|---|
| 338 | return eventHandler();
|
|---|
| 339 | } finally {
|
|---|
| 340 | currentPriorityLevel = previousPriorityLevel;
|
|---|
| 341 | }
|
|---|
| 342 | };
|
|---|
| 343 | exports.unstable_scheduleCallback = function (
|
|---|
| 344 | priorityLevel,
|
|---|
| 345 | callback,
|
|---|
| 346 | options
|
|---|
| 347 | ) {
|
|---|
| 348 | var currentTime = currentMockTime;
|
|---|
| 349 | "object" === typeof options && null !== options
|
|---|
| 350 | ? ((options = options.delay),
|
|---|
| 351 | (options =
|
|---|
| 352 | "number" === typeof options && 0 < options
|
|---|
| 353 | ? currentTime + options
|
|---|
| 354 | : currentTime))
|
|---|
| 355 | : (options = currentTime);
|
|---|
| 356 | switch (priorityLevel) {
|
|---|
| 357 | case 1:
|
|---|
| 358 | var timeout = -1;
|
|---|
| 359 | break;
|
|---|
| 360 | case 2:
|
|---|
| 361 | timeout = 250;
|
|---|
| 362 | break;
|
|---|
| 363 | case 5:
|
|---|
| 364 | timeout = 1073741823;
|
|---|
| 365 | break;
|
|---|
| 366 | case 4:
|
|---|
| 367 | timeout = 1e4;
|
|---|
| 368 | break;
|
|---|
| 369 | default:
|
|---|
| 370 | timeout = 5e3;
|
|---|
| 371 | }
|
|---|
| 372 | timeout = options + timeout;
|
|---|
| 373 | priorityLevel = {
|
|---|
| 374 | id: taskIdCounter++,
|
|---|
| 375 | callback: callback,
|
|---|
| 376 | priorityLevel: priorityLevel,
|
|---|
| 377 | startTime: options,
|
|---|
| 378 | expirationTime: timeout,
|
|---|
| 379 | sortIndex: -1
|
|---|
| 380 | };
|
|---|
| 381 | options > currentTime
|
|---|
| 382 | ? ((priorityLevel.sortIndex = options),
|
|---|
| 383 | push(timerQueue, priorityLevel),
|
|---|
| 384 | null === peek(taskQueue) &&
|
|---|
| 385 | priorityLevel === peek(timerQueue) &&
|
|---|
| 386 | (isHostTimeoutScheduled
|
|---|
| 387 | ? ((scheduledTimeout = null), (timeoutTime = -1))
|
|---|
| 388 | : (isHostTimeoutScheduled = !0),
|
|---|
| 389 | (scheduledTimeout = handleTimeout),
|
|---|
| 390 | (timeoutTime = currentMockTime + (options - currentTime))))
|
|---|
| 391 | : ((priorityLevel.sortIndex = timeout),
|
|---|
| 392 | push(taskQueue, priorityLevel),
|
|---|
| 393 | isHostCallbackScheduled ||
|
|---|
| 394 | isPerformingWork ||
|
|---|
| 395 | ((isHostCallbackScheduled = !0), (scheduledCallback = flushWork)));
|
|---|
| 396 | return priorityLevel;
|
|---|
| 397 | };
|
|---|
| 398 | exports.unstable_setDisableYieldValue = function (newValue) {
|
|---|
| 399 | disableYieldValue = newValue;
|
|---|
| 400 | };
|
|---|
| 401 | exports.unstable_shouldYield = shouldYieldToHost;
|
|---|
| 402 | exports.unstable_wrapCallback = function (callback) {
|
|---|
| 403 | var parentPriorityLevel = currentPriorityLevel;
|
|---|
| 404 | return function () {
|
|---|
| 405 | var previousPriorityLevel = currentPriorityLevel;
|
|---|
| 406 | currentPriorityLevel = parentPriorityLevel;
|
|---|
| 407 | try {
|
|---|
| 408 | return callback.apply(this, arguments);
|
|---|
| 409 | } finally {
|
|---|
| 410 | currentPriorityLevel = previousPriorityLevel;
|
|---|
| 411 | }
|
|---|
| 412 | };
|
|---|
| 413 | };
|
|---|
| 414 | })();
|
|---|