truncate JSTimers errors array instead of making it nullable

Summary:
instead of `errors: ?Array<Error>` and setting it back to `null` to clear errors, which Flow is not very happy with, we can make it always an array and truncate it with `errors.length = 0`.

Changelog: [Internal]

Reviewed By: motiz88

Differential Revision: D33584184

fbshipit-source-id: 81b424e69e60203c645bafbac12177ffcdc0c6ef
This commit is contained in:
Marshall Roch 2022-01-14 09:05:41 -08:00 коммит произвёл Facebook GitHub Bot
Родитель 3cf0291008
Коммит 66dc211436
1 изменённых файлов: 17 добавлений и 28 удалений

Просмотреть файл

@ -42,7 +42,7 @@ let requestIdleCallbacks: Array<number> = [];
const requestIdleCallbackTimeouts: {[number]: number, ...} = {};
let GUID = 1;
let errors: ?Array<Error> = null;
const errors: Array<Error> = [];
let hasEmittedTimeDriftWarning = false;
@ -130,11 +130,7 @@ function _callTimer(timerID: number, frameTime: number, didTimeout: ?boolean) {
}
} catch (e) {
// Don't rethrow so that we can run all timers.
if (!errors) {
errors = [e];
} else {
errors.push(e);
}
errors.push(e);
}
if (__DEV__) {
@ -356,14 +352,13 @@ const JSTimers = {
'Cannot call `callTimers` with an empty list of IDs.',
);
errors = (null: ?Array<Error>);
errors.length = 0;
for (let i = 0; i < timersToCall.length; i++) {
_callTimer(timersToCall[i], 0);
}
if (errors) {
// $FlowFixMe[incompatible-use]
const errorCount = errors.length;
const errorCount = errors.length;
if (errorCount > 0) {
if (errorCount > 1) {
// Throw all the other errors in a setTimeout, which will throw each
// error one at a time
@ -371,13 +366,11 @@ const JSTimers = {
JSTimers.setTimeout(
(error => {
throw error;
// $FlowFixMe[incompatible-use]
}).bind(null, errors[ii]),
0,
);
}
}
// $FlowFixMe[incompatible-use]
throw errors[0];
}
},
@ -390,7 +383,7 @@ const JSTimers = {
return;
}
errors = (null: ?Array<Error>);
errors.length = 0;
if (requestIdleCallbacks.length > 0) {
const passIdleCallbacks = requestIdleCallbacks;
requestIdleCallbacks = [];
@ -404,13 +397,11 @@ const JSTimers = {
setSendIdleEvents(false);
}
if (errors) {
errors.forEach(error =>
JSTimers.setTimeout(() => {
throw error;
}, 0),
);
}
errors.forEach(error =>
JSTimers.setTimeout(() => {
throw error;
}, 0),
);
},
/**
@ -418,15 +409,13 @@ const JSTimers = {
* before we hand control back to native.
*/
callReactNativeMicrotasks() {
errors = (null: ?Array<Error>);
errors.length = 0;
while (_callReactNativeMicrotasksPass()) {}
if (errors) {
errors.forEach(error =>
JSTimers.setTimeout(() => {
throw error;
}, 0),
);
}
errors.forEach(error =>
JSTimers.setTimeout(() => {
throw error;
}, 0),
);
},
/**