diff --git a/Libraries/Core/Timers/JSTimers.js b/Libraries/Core/Timers/JSTimers.js index 0d73d59e89..8682a1dcda 100644 --- a/Libraries/Core/Timers/JSTimers.js +++ b/Libraries/Core/Timers/JSTimers.js @@ -42,7 +42,7 @@ let requestIdleCallbacks: Array = []; const requestIdleCallbackTimeouts: {[number]: number, ...} = {}; let GUID = 1; -let errors: ?Array = null; +const errors: Array = []; 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); + 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); + 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); + errors.length = 0; while (_callReactNativeMicrotasksPass()) {} - if (errors) { - errors.forEach(error => - JSTimers.setTimeout(() => { - throw error; - }, 0), - ); - } + errors.forEach(error => + JSTimers.setTimeout(() => { + throw error; + }, 0), + ); }, /**