Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Scheduler] Temporarily remove wrapper function #16345

Merged
merged 1 commit into from
Aug 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 22 additions & 74 deletions packages/scheduler/src/Scheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,71 +60,13 @@ var isPerformingWork = false;
var isHostCallbackScheduled = false;
var isHostTimeoutScheduled = false;

function scheduler_flushTaskAtPriority_Immediate(callback, didTimeout) {
return callback(didTimeout);
}
function scheduler_flushTaskAtPriority_UserBlocking(callback, didTimeout) {
return callback(didTimeout);
}
function scheduler_flushTaskAtPriority_Normal(callback, didTimeout) {
return callback(didTimeout);
}
function scheduler_flushTaskAtPriority_Low(callback, didTimeout) {
return callback(didTimeout);
}
function scheduler_flushTaskAtPriority_Idle(callback, didTimeout) {
return callback(didTimeout);
}

function flushTask(task, callback, currentTime) {
var previousPriorityLevel = currentPriorityLevel;
var previousTask = currentTask;
currentPriorityLevel = task.priorityLevel;
currentTask = task;
try {
var didUserCallbackTimeout = task.expirationTime <= currentTime;
// Add an extra function to the callstack. Profiling tools can use this
// to infer the priority of work that appears higher in the stack.
var continuationCallback;
switch (currentPriorityLevel) {
case ImmediatePriority:
continuationCallback = scheduler_flushTaskAtPriority_Immediate(
callback,
didUserCallbackTimeout,
);
break;
case UserBlockingPriority:
continuationCallback = scheduler_flushTaskAtPriority_UserBlocking(
callback,
didUserCallbackTimeout,
);
break;
case NormalPriority:
continuationCallback = scheduler_flushTaskAtPriority_Normal(
callback,
didUserCallbackTimeout,
);
break;
case LowPriority:
continuationCallback = scheduler_flushTaskAtPriority_Low(
callback,
didUserCallbackTimeout,
);
break;
case IdlePriority:
continuationCallback = scheduler_flushTaskAtPriority_Idle(
callback,
didUserCallbackTimeout,
);
break;
}
return typeof continuationCallback === 'function'
? continuationCallback
: null;
} finally {
currentPriorityLevel = previousPriorityLevel;
currentTask = previousTask;
}
var didUserCallbackTimeout = task.expirationTime <= currentTime;
var continuationCallback = callback(didUserCallbackTimeout);
return typeof continuationCallback === 'function'
? continuationCallback
: null;
}

function advanceTimers(currentTime) {
Expand Down Expand Up @@ -174,26 +116,30 @@ function flushWork(hasTimeRemaining, initialTime) {
}

isPerformingWork = true;
const previousPriorityLevel = currentPriorityLevel;
try {
let currentTime = initialTime;
advanceTimers(currentTime);
let task = peek(taskQueue);
while (task !== null && !(enableSchedulerDebugging && isSchedulerPaused)) {
currentTask = peek(taskQueue);
while (
currentTask !== null &&
!(enableSchedulerDebugging && isSchedulerPaused)
) {
if (
task.expirationTime > currentTime &&
currentTask.expirationTime > currentTime &&
(!hasTimeRemaining || shouldYieldToHost())
) {
// This task hasn't expired, and we've reached the deadline.
// This currentTask hasn't expired, and we've reached the deadline.
break;
}
const callback = task.callback;
const callback = currentTask.callback;
if (callback !== null) {
task.callback = null;
const continuation = flushTask(task, callback, currentTime);
currentTask.callback = null;
const continuation = flushTask(currentTask, callback, currentTime);
if (continuation !== null) {
task.callback = continuation;
currentTask.callback = continuation;
} else {
if (task === peek(taskQueue)) {
if (currentTask === peek(taskQueue)) {
pop(taskQueue);
}
}
Expand All @@ -202,10 +148,10 @@ function flushWork(hasTimeRemaining, initialTime) {
} else {
pop(taskQueue);
}
task = peek(taskQueue);
currentTask = peek(taskQueue);
}
// Return whether there's additional work
if (task !== null) {
if (currentTask !== null) {
return true;
} else {
let firstTimer = peek(timerQueue);
Expand All @@ -215,6 +161,8 @@ function flushWork(hasTimeRemaining, initialTime) {
return false;
}
} finally {
currentTask = null;
currentPriorityLevel = previousPriorityLevel;
isPerformingWork = false;
}
}
Expand Down
4 changes: 3 additions & 1 deletion packages/scheduler/src/__tests__/Scheduler-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,9 @@ describe('Scheduler', () => {
if (__DEV__) {
// Function names are minified in prod, though you could still infer the
// priority if you have sourcemaps.
it('adds extra function to the JS stack whose name includes the priority level', () => {
// TODO: Feature temporarily disabled while we investigate a bug in one of
// our minifiers.
it.skip('adds extra function to the JS stack whose name includes the priority level', () => {
function inferPriorityFromCallstack() {
try {
throw Error();
Expand Down