Skip to content

Commit

Permalink
Manually inline parseErrorStack
Browse files Browse the repository at this point in the history
Reviewed By: davidaurelio

Differential Revision: D4779541

fbshipit-source-id: bb395a0abd3cf1f9c940429f375cd57ecb992789
  • Loading branch information
javache authored and thotegowda committed May 7, 2017
1 parent 2513817 commit ddc81e0
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions Libraries/Core/Timers/JSTimers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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);
Expand All @@ -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. ' +
Expand All @@ -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;
},

Expand All @@ -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;
},

Expand All @@ -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;
},

Expand All @@ -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');
Expand All @@ -150,7 +150,7 @@ const JSTimers = {
}

if (JSTimersExecution.requestIdleCallbacks.length === 0) {
RCTTiming.setSendIdleEvents(false);
Timing.setSendIdleEvents(false);
}
},

Expand Down

0 comments on commit ddc81e0

Please sign in to comment.