From 955093584a21b0782057fceb0262a217590579ef Mon Sep 17 00:00:00 2001 From: Tim Yung Date: Mon, 11 Jul 2016 10:28:03 -0700 Subject: [PATCH] RN: Change Time Drift Error into Warning Summary: Changes the time drift error into a warning that will only get logged once per debugging session. Reviewed By: jingc Differential Revision: D3539067 fbshipit-source-id: 357db15750d867a91c39b5fc5fd6ed4ae2852bc7 --- .../System/JSTimers/JSTimersExecution.js | 13 +++++++++++++ .../react/modules/core/JSTimersExecution.java | 2 ++ .../com/facebook/react/modules/core/Timing.java | 9 ++++----- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/Libraries/JavaScriptAppEngine/System/JSTimers/JSTimersExecution.js b/Libraries/JavaScriptAppEngine/System/JSTimers/JSTimersExecution.js index df1b609723e6dd..b118a28a6c48b3 100644 --- a/Libraries/JavaScriptAppEngine/System/JSTimers/JSTimersExecution.js +++ b/Libraries/JavaScriptAppEngine/System/JSTimers/JSTimersExecution.js @@ -16,6 +16,8 @@ var performanceNow = require('fbjs/lib/performanceNow'); var warning = require('fbjs/lib/warning'); var Systrace = require('Systrace'); +let hasEmittedTimeDriftWarning = false; + /** * JS implementation of timer functions. Must be completely driven by an * external clock signal, all that's stored here is timerID, timer type, and @@ -147,6 +149,17 @@ var JSTimersExecution = { } }, + /** + * Called from native (in development) when environment times are out-of-sync. + */ + emitTimeDriftWarning: function(warningMessage) { + if (hasEmittedTimeDriftWarning) { + return; + } + hasEmittedTimeDriftWarning = true; + console.warn(warningMessage); + }, + _clearIndex: function(i) { JSTimersExecution.timerIDs[i] = null; JSTimersExecution.callbacks[i] = null; diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/core/JSTimersExecution.java b/ReactAndroid/src/main/java/com/facebook/react/modules/core/JSTimersExecution.java index 9e0ba2a3d72893..41b241fad07622 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/core/JSTimersExecution.java +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/core/JSTimersExecution.java @@ -17,4 +17,6 @@ public interface JSTimersExecution extends JavaScriptModule { public void callTimers(WritableArray timerIDs); + + public void emitTimeDriftWarning(String warningMessage); } diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/core/Timing.java b/ReactAndroid/src/main/java/com/facebook/react/modules/core/Timing.java index d0ee51cfcd191f..8b88c05b464199 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/core/Timing.java +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/core/Timing.java @@ -226,11 +226,10 @@ public void createTimer( if (mDevSupportManager.getDevSupportEnabled()) { long driftTime = Math.abs(remoteTime - deviceTime); if (driftTime > 60000) { - throw new RuntimeException( - "Debugger and device times have drifted by more than 60s." + - "Please correct this by running adb shell " + - "\"date `date +%m%d%H%M%Y.%S`\" on your debugger machine." - ); + getReactApplicationContext().getJSModule(executorToken, JSTimersExecution.class) + .emitTimeDriftWarning( + "Debugger and device times have drifted by more than 60s. Please correct this by " + + "running adb shell \"date `date +%m%d%H%M%Y.%S`\" on your debugger machine."); } }