Manually inline parseErrorStack
Reviewed By: davidaurelio Differential Revision: D4779541 fbshipit-source-id: bb395a0abd3cf1f9c940429f375cd57ecb992789
This commit is contained in:
parent
7de59b102d
commit
bb48c0c608
|
@ -13,11 +13,10 @@
|
|||
|
||||
// Note that the module JSTimers is split into two in order to solve a cycle
|
||||
// in dependencies. NativeModules > BatchedBridge > MessageQueue > JSTimersExecution
|
||||
const RCTTiming = require('NativeModules').Timing;
|
||||
const JSTimersExecution = require('JSTimersExecution');
|
||||
const Platform = require('Platform');
|
||||
|
||||
const parseErrorStack = require('parseErrorStack');
|
||||
const {Timing} = require('NativeModules');
|
||||
|
||||
import type {JSTimerType} from 'JSTimersExecution';
|
||||
|
||||
|
@ -37,6 +36,7 @@ function _allocateCallback(func: Function, type: JSTimerType): number {
|
|||
JSTimersExecution.callbacks[freeIndex] = func;
|
||||
JSTimersExecution.types[freeIndex] = type;
|
||||
if (__DEV__) {
|
||||
const parseErrorStack = require('parseErrorStack');
|
||||
const e = (new Error() : any);
|
||||
e.framesToPop = 1;
|
||||
const stack = parseErrorStack(e);
|
||||
|
@ -60,14 +60,14 @@ function _freeCallback(timerID: number) {
|
|||
JSTimersExecution._clearIndex(index);
|
||||
const type = JSTimersExecution.types[index];
|
||||
if (type !== 'setImmediate' && type !== 'requestIdleCallback') {
|
||||
RCTTiming.deleteTimer(timerID);
|
||||
Timing.deleteTimer(timerID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const MAX_TIMER_DURATION_MS = 60 * 1000;
|
||||
const IS_ANDROID = Platform.OS === 'android';
|
||||
const ANDROID_LONG_TIMER_MESSAGE =
|
||||
const ANDROID_LONG_TIMER_MESSAGE =
|
||||
'Setting a timer for a long period of time, i.e. multiple minutes, is a ' +
|
||||
'performance and correctness issue on Android as it keeps the timer ' +
|
||||
'module awake, and timers can only be called when the app is in the foreground. ' +
|
||||
|
@ -84,13 +84,13 @@ const JSTimers = {
|
|||
* @param {number} duration Number of milliseconds.
|
||||
*/
|
||||
setTimeout: function(func: Function, duration: number, ...args?: any): number {
|
||||
if (IS_ANDROID && duration > MAX_TIMER_DURATION_MS) {
|
||||
if (__DEV__ && IS_ANDROID && duration > MAX_TIMER_DURATION_MS) {
|
||||
console.warn(
|
||||
ANDROID_LONG_TIMER_MESSAGE + '\n' + '(Saw setTimeout with duration ' +
|
||||
duration + 'ms)');
|
||||
}
|
||||
const id = _allocateCallback(() => func.apply(undefined, args), 'setTimeout');
|
||||
RCTTiming.createTimer(id, duration || 0, Date.now(), /* recurring */ false);
|
||||
Timing.createTimer(id, duration || 0, Date.now(), /* recurring */ false);
|
||||
return id;
|
||||
},
|
||||
|
||||
|
@ -99,13 +99,13 @@ const JSTimers = {
|
|||
* @param {number} duration Number of milliseconds.
|
||||
*/
|
||||
setInterval: function(func: Function, duration: number, ...args?: any): number {
|
||||
if (IS_ANDROID && duration > MAX_TIMER_DURATION_MS) {
|
||||
if (__DEV__ && IS_ANDROID && duration > MAX_TIMER_DURATION_MS) {
|
||||
console.warn(
|
||||
ANDROID_LONG_TIMER_MESSAGE + '\n' + '(Saw setInterval with duration ' +
|
||||
duration + 'ms)');
|
||||
}
|
||||
const id = _allocateCallback(() => func.apply(undefined, args), 'setInterval');
|
||||
RCTTiming.createTimer(id, duration || 0, Date.now(), /* recurring */ true);
|
||||
Timing.createTimer(id, duration || 0, Date.now(), /* recurring */ true);
|
||||
return id;
|
||||
},
|
||||
|
||||
|
@ -124,7 +124,7 @@ const JSTimers = {
|
|||
*/
|
||||
requestAnimationFrame: function(func : Function) {
|
||||
const id = _allocateCallback(func, 'requestAnimationFrame');
|
||||
RCTTiming.createTimer(id, 1, Date.now(), /* recurring */ false);
|
||||
Timing.createTimer(id, 1, Date.now(), /* recurring */ false);
|
||||
return id;
|
||||
},
|
||||
|
||||
|
@ -134,7 +134,7 @@ const JSTimers = {
|
|||
*/
|
||||
requestIdleCallback: function(func : Function) {
|
||||
if (JSTimersExecution.requestIdleCallbacks.length === 0) {
|
||||
RCTTiming.setSendIdleEvents(true);
|
||||
Timing.setSendIdleEvents(true);
|
||||
}
|
||||
|
||||
const id = _allocateCallback(func, 'requestIdleCallback');
|
||||
|
@ -150,7 +150,7 @@ const JSTimers = {
|
|||
}
|
||||
|
||||
if (JSTimersExecution.requestIdleCallbacks.length === 0) {
|
||||
RCTTiming.setSendIdleEvents(false);
|
||||
Timing.setSendIdleEvents(false);
|
||||
}
|
||||
},
|
||||
|
||||
|
|
Loading…
Reference in New Issue