diff options
Diffstat (limited to 'node_modules/scheduler/cjs/scheduler-unstable_mock.development.js')
-rw-r--r-- | node_modules/scheduler/cjs/scheduler-unstable_mock.development.js | 288 |
1 files changed, 48 insertions, 240 deletions
diff --git a/node_modules/scheduler/cjs/scheduler-unstable_mock.development.js b/node_modules/scheduler/cjs/scheduler-unstable_mock.development.js index a143004..9f0da52 100644 --- a/node_modules/scheduler/cjs/scheduler-unstable_mock.development.js +++ b/node_modules/scheduler/cjs/scheduler-unstable_mock.development.js @@ -1,4 +1,4 @@ -/** @license React v0.19.1 +/** @license React v0.20.2 * scheduler-unstable_mock.development.js * * Copyright (c) Facebook, Inc. and its affiliates. @@ -9,14 +9,12 @@ 'use strict'; - - if (process.env.NODE_ENV !== "production") { (function() { 'use strict'; var enableSchedulerDebugging = false; -var enableProfiling = true; +var enableProfiling = false; var currentTime = 0; var scheduledCallback = null; @@ -178,6 +176,13 @@ function unstable_flushAll() { } } function unstable_yieldValue(value) { + // eslint-disable-next-line react-internal/no-production-logging + if (console.log.name === 'disabledLog') { + // If console.log has been patched, we assume we're in render + // replaying and we ignore any values yielding in the second pass. + return; + } + if (yieldedValues === null) { yieldedValues = [value]; } else { @@ -185,6 +190,13 @@ function unstable_yieldValue(value) { } } function unstable_advanceTime(ms) { + // eslint-disable-next-line react-internal/no-production-logging + if (console.log.name === 'disabledLog') { + // If console.log has been patched, we assume we're in render + // replaying and we ignore any time advancing in the second pass. + return; + } + currentTime += ms; if (scheduledTimeout !== null && timeoutTime <= currentTime) { @@ -280,172 +292,13 @@ function compare(a, b) { } // TODO: Use symbols? -var NoPriority = 0; var ImmediatePriority = 1; var UserBlockingPriority = 2; var NormalPriority = 3; var LowPriority = 4; var IdlePriority = 5; -var runIdCounter = 0; -var mainThreadIdCounter = 0; -var profilingStateSize = 4; -var sharedProfilingBuffer = // $FlowFixMe Flow doesn't know about SharedArrayBuffer -typeof SharedArrayBuffer === 'function' ? new SharedArrayBuffer(profilingStateSize * Int32Array.BYTES_PER_ELEMENT) : // $FlowFixMe Flow doesn't know about ArrayBuffer -typeof ArrayBuffer === 'function' ? new ArrayBuffer(profilingStateSize * Int32Array.BYTES_PER_ELEMENT) : null // Don't crash the init path on IE9 -; -var profilingState = sharedProfilingBuffer !== null ? new Int32Array(sharedProfilingBuffer) : []; // We can't read this but it helps save bytes for null checks - -var PRIORITY = 0; -var CURRENT_TASK_ID = 1; -var CURRENT_RUN_ID = 2; -var QUEUE_SIZE = 3; - -{ - profilingState[PRIORITY] = NoPriority; // This is maintained with a counter, because the size of the priority queue - // array might include canceled tasks. - - profilingState[QUEUE_SIZE] = 0; - profilingState[CURRENT_TASK_ID] = 0; -} // Bytes per element is 4 - - -var INITIAL_EVENT_LOG_SIZE = 131072; -var MAX_EVENT_LOG_SIZE = 524288; // Equivalent to 2 megabytes - -var eventLogSize = 0; -var eventLogBuffer = null; -var eventLog = null; -var eventLogIndex = 0; -var TaskStartEvent = 1; -var TaskCompleteEvent = 2; -var TaskErrorEvent = 3; -var TaskCancelEvent = 4; -var TaskRunEvent = 5; -var TaskYieldEvent = 6; -var SchedulerSuspendEvent = 7; -var SchedulerResumeEvent = 8; - -function logEvent(entries) { - if (eventLog !== null) { - var offset = eventLogIndex; - eventLogIndex += entries.length; - - if (eventLogIndex + 1 > eventLogSize) { - eventLogSize *= 2; - - if (eventLogSize > MAX_EVENT_LOG_SIZE) { - // Using console['error'] to evade Babel and ESLint - console['error']("Scheduler Profiling: Event log exceeded maximum size. Don't " + 'forget to call `stopLoggingProfilingEvents()`.'); - stopLoggingProfilingEvents(); - return; - } - - var newEventLog = new Int32Array(eventLogSize * 4); - newEventLog.set(eventLog); - eventLogBuffer = newEventLog.buffer; - eventLog = newEventLog; - } - - eventLog.set(entries, offset); - } -} - -function startLoggingProfilingEvents() { - eventLogSize = INITIAL_EVENT_LOG_SIZE; - eventLogBuffer = new ArrayBuffer(eventLogSize * 4); - eventLog = new Int32Array(eventLogBuffer); - eventLogIndex = 0; -} -function stopLoggingProfilingEvents() { - var buffer = eventLogBuffer; - eventLogSize = 0; - eventLogBuffer = null; - eventLog = null; - eventLogIndex = 0; - return buffer; -} -function markTaskStart(task, ms) { - { - profilingState[QUEUE_SIZE]++; - - if (eventLog !== null) { - // performance.now returns a float, representing milliseconds. When the - // event is logged, it's coerced to an int. Convert to microseconds to - // maintain extra degrees of precision. - logEvent([TaskStartEvent, ms * 1000, task.id, task.priorityLevel]); - } - } -} -function markTaskCompleted(task, ms) { - { - profilingState[PRIORITY] = NoPriority; - profilingState[CURRENT_TASK_ID] = 0; - profilingState[QUEUE_SIZE]--; - - if (eventLog !== null) { - logEvent([TaskCompleteEvent, ms * 1000, task.id]); - } - } -} -function markTaskCanceled(task, ms) { - { - profilingState[QUEUE_SIZE]--; - - if (eventLog !== null) { - logEvent([TaskCancelEvent, ms * 1000, task.id]); - } - } -} function markTaskErrored(task, ms) { - { - profilingState[PRIORITY] = NoPriority; - profilingState[CURRENT_TASK_ID] = 0; - profilingState[QUEUE_SIZE]--; - - if (eventLog !== null) { - logEvent([TaskErrorEvent, ms * 1000, task.id]); - } - } -} -function markTaskRun(task, ms) { - { - runIdCounter++; - profilingState[PRIORITY] = task.priorityLevel; - profilingState[CURRENT_TASK_ID] = task.id; - profilingState[CURRENT_RUN_ID] = runIdCounter; - - if (eventLog !== null) { - logEvent([TaskRunEvent, ms * 1000, task.id, runIdCounter]); - } - } -} -function markTaskYield(task, ms) { - { - profilingState[PRIORITY] = NoPriority; - profilingState[CURRENT_TASK_ID] = 0; - profilingState[CURRENT_RUN_ID] = 0; - - if (eventLog !== null) { - logEvent([TaskYieldEvent, ms * 1000, task.id, runIdCounter]); - } - } -} -function markSchedulerSuspended(ms) { - { - mainThreadIdCounter++; - - if (eventLog !== null) { - logEvent([SchedulerSuspendEvent, ms * 1000, mainThreadIdCounter]); - } - } -} -function markSchedulerUnsuspended(ms) { - { - if (eventLog !== null) { - logEvent([SchedulerResumeEvent, ms * 1000, mainThreadIdCounter]); - } - } } /* eslint-disable no-var */ @@ -456,11 +309,11 @@ var maxSigned31BitInt = 1073741823; // Times out immediately var IMMEDIATE_PRIORITY_TIMEOUT = -1; // Eventually times out -var USER_BLOCKING_PRIORITY = 250; +var USER_BLOCKING_PRIORITY_TIMEOUT = 250; var NORMAL_PRIORITY_TIMEOUT = 5000; var LOW_PRIORITY_TIMEOUT = 10000; // Never times out -var IDLE_PRIORITY = maxSigned31BitInt; // Tasks are stored on a min heap +var IDLE_PRIORITY_TIMEOUT = maxSigned31BitInt; // Tasks are stored on a min heap var taskQueue = []; var timerQueue = []; // Incrementing id counter. Used to maintain insertion order. @@ -486,11 +339,6 @@ function advanceTimers(currentTime) { pop(timerQueue); timer.sortIndex = timer.expirationTime; push(taskQueue, timer); - - { - markTaskStart(timer, currentTime); - timer.isQueued = true; - } } else { // Remaining timers are pending. return; @@ -519,9 +367,6 @@ function handleTimeout(currentTime) { } function flushWork(hasTimeRemaining, initialTime) { - { - markSchedulerUnsuspended(initialTime); - } // We'll need a host callback the next time work is scheduled. isHostCallbackScheduled = false; @@ -549,19 +394,13 @@ function flushWork(hasTimeRemaining, initialTime) { throw error; } } else { - // No catch in prod codepath. + // No catch in prod code path. return workLoop(hasTimeRemaining, initialTime); } } finally { currentTask = null; currentPriorityLevel = previousPriorityLevel; isPerformingWork = false; - - { - var _currentTime = getCurrentTime(); - - markSchedulerSuspended(_currentTime); - } } } @@ -578,22 +417,17 @@ function workLoop(hasTimeRemaining, initialTime) { var callback = currentTask.callback; - if (callback !== null) { + if (typeof callback === 'function') { currentTask.callback = null; currentPriorityLevel = currentTask.priorityLevel; var didUserCallbackTimeout = currentTask.expirationTime <= currentTime; - markTaskRun(currentTask, currentTime); + var continuationCallback = callback(didUserCallbackTimeout); currentTime = getCurrentTime(); if (typeof continuationCallback === 'function') { currentTask.callback = continuationCallback; - markTaskYield(currentTask, currentTime); } else { - { - markTaskCompleted(currentTask, currentTime); - currentTask.isQueued = false; - } if (currentTask === peek(taskQueue)) { pop(taskQueue); @@ -687,30 +521,9 @@ function unstable_wrapCallback(callback) { }; } -function timeoutForPriorityLevel(priorityLevel) { - switch (priorityLevel) { - case ImmediatePriority: - return IMMEDIATE_PRIORITY_TIMEOUT; - - case UserBlockingPriority: - return USER_BLOCKING_PRIORITY; - - case IdlePriority: - return IDLE_PRIORITY; - - case LowPriority: - return LOW_PRIORITY_TIMEOUT; - - case NormalPriority: - default: - return NORMAL_PRIORITY_TIMEOUT; - } -} - function unstable_scheduleCallback(priorityLevel, callback, options) { var currentTime = getCurrentTime(); var startTime; - var timeout; if (typeof options === 'object' && options !== null) { var delay = options.delay; @@ -720,13 +533,35 @@ function unstable_scheduleCallback(priorityLevel, callback, options) { } else { startTime = currentTime; } - - timeout = typeof options.timeout === 'number' ? options.timeout : timeoutForPriorityLevel(priorityLevel); } else { - timeout = timeoutForPriorityLevel(priorityLevel); startTime = currentTime; } + var timeout; + + switch (priorityLevel) { + case ImmediatePriority: + timeout = IMMEDIATE_PRIORITY_TIMEOUT; + break; + + case UserBlockingPriority: + timeout = USER_BLOCKING_PRIORITY_TIMEOUT; + break; + + case IdlePriority: + timeout = IDLE_PRIORITY_TIMEOUT; + break; + + case LowPriority: + timeout = LOW_PRIORITY_TIMEOUT; + break; + + case NormalPriority: + default: + timeout = NORMAL_PRIORITY_TIMEOUT; + break; + } + var expirationTime = startTime + timeout; var newTask = { id: taskIdCounter++, @@ -737,10 +572,6 @@ function unstable_scheduleCallback(priorityLevel, callback, options) { sortIndex: -1 }; - { - newTask.isQueued = false; - } - if (startTime > currentTime) { // This is a delayed task. newTask.sortIndex = startTime; @@ -761,11 +592,6 @@ function unstable_scheduleCallback(priorityLevel, callback, options) { } else { newTask.sortIndex = expirationTime; push(taskQueue, newTask); - - { - markTaskStart(newTask, currentTime); - newTask.isQueued = true; - } // Schedule a host callback, if needed. If we're already performing work, // wait until the next time we yield. @@ -794,13 +620,6 @@ function unstable_getFirstCallbackNode() { } function unstable_cancelCallback(task) { - { - if (task.isQueued) { - var currentTime = getCurrentTime(); - markTaskCanceled(task, currentTime); - task.isQueued = false; - } - } // Null out the callback to indicate the task has been canceled. (Can't // remove from the queue because you can't remove arbitrary nodes from an // array based heap, only the first one.) @@ -812,19 +631,8 @@ function unstable_getCurrentPriorityLevel() { return currentPriorityLevel; } -function unstable_shouldYield() { - var currentTime = getCurrentTime(); - advanceTimers(currentTime); - var firstTask = peek(taskQueue); - return firstTask !== currentTask && currentTask !== null && firstTask !== null && firstTask.callback !== null && firstTask.startTime <= currentTime && firstTask.expirationTime < currentTask.expirationTime || shouldYieldToHost(); -} - var unstable_requestPaint = requestPaint; -var unstable_Profiling = { - startLoggingProfilingEvents: startLoggingProfilingEvents, - stopLoggingProfilingEvents: stopLoggingProfilingEvents, - sharedProfilingBuffer: sharedProfilingBuffer -} ; +var unstable_Profiling = null; exports.unstable_IdlePriority = IdlePriority; exports.unstable_ImmediatePriority = ImmediatePriority; @@ -850,7 +658,7 @@ exports.unstable_pauseExecution = unstable_pauseExecution; exports.unstable_requestPaint = unstable_requestPaint; exports.unstable_runWithPriority = unstable_runWithPriority; exports.unstable_scheduleCallback = unstable_scheduleCallback; -exports.unstable_shouldYield = unstable_shouldYield; +exports.unstable_shouldYield = shouldYieldToHost; exports.unstable_wrapCallback = unstable_wrapCallback; exports.unstable_yieldValue = unstable_yieldValue; })(); |