mirror of
https://github.com/status-im/react-native.git
synced 2025-02-11 00:46:32 +00:00
expose systemclock time to JS
Reviewed By: tadeuzagallo Differential Revision: D2748749 fb-gh-sync-id: 4d1dbae61f69a07b7106cb57caff03cadfb85776
This commit is contained in:
parent
a86171a482
commit
1a94698658
@ -9,6 +9,7 @@
|
|||||||
#include <folly/json.h>
|
#include <folly/json.h>
|
||||||
#include <folly/String.h>
|
#include <folly/String.h>
|
||||||
#include <jni/fbjni/Exceptions.h>
|
#include <jni/fbjni/Exceptions.h>
|
||||||
|
#include <sys/time.h>
|
||||||
#include "Value.h"
|
#include "Value.h"
|
||||||
#include "jni/OnLoad.h"
|
#include "jni/OnLoad.h"
|
||||||
|
|
||||||
@ -34,6 +35,9 @@ using fbsystrace::FbSystraceSection;
|
|||||||
#include <jsc_config_android.h>
|
#include <jsc_config_android.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static const int64_t NANOSECONDS_IN_SECOND = 1000000000LL;
|
||||||
|
static const int64_t NANOSECONDS_IN_MILLISECOND = 1000000LL;
|
||||||
|
|
||||||
using namespace facebook::jni;
|
using namespace facebook::jni;
|
||||||
|
|
||||||
namespace facebook {
|
namespace facebook {
|
||||||
@ -54,6 +58,13 @@ static JSValueRef nativeLoggingHook(
|
|||||||
size_t argumentCount,
|
size_t argumentCount,
|
||||||
const JSValueRef arguments[],
|
const JSValueRef arguments[],
|
||||||
JSValueRef *exception);
|
JSValueRef *exception);
|
||||||
|
static JSValueRef nativePerformanceNow(
|
||||||
|
JSContextRef ctx,
|
||||||
|
JSObjectRef function,
|
||||||
|
JSObjectRef thisObject,
|
||||||
|
size_t argumentCount,
|
||||||
|
const JSValueRef arguments[],
|
||||||
|
JSValueRef *exception);
|
||||||
|
|
||||||
static JSValueRef evaluateScriptWithJSC(
|
static JSValueRef evaluateScriptWithJSC(
|
||||||
JSGlobalContextRef ctx,
|
JSGlobalContextRef ctx,
|
||||||
@ -110,6 +121,7 @@ JSCExecutor::JSCExecutor(FlushImmediateCallback cb) :
|
|||||||
s_globalContextRefToJSCExecutor[m_context] = this;
|
s_globalContextRefToJSCExecutor[m_context] = this;
|
||||||
installGlobalFunction(m_context, "nativeFlushQueueImmediate", nativeFlushQueueImmediate);
|
installGlobalFunction(m_context, "nativeFlushQueueImmediate", nativeFlushQueueImmediate);
|
||||||
installGlobalFunction(m_context, "nativeLoggingHook", nativeLoggingHook);
|
installGlobalFunction(m_context, "nativeLoggingHook", nativeLoggingHook);
|
||||||
|
installGlobalFunction(m_context, "nativePerformanceNow", nativePerformanceNow);
|
||||||
|
|
||||||
#ifdef WITH_FB_JSC_TUNING
|
#ifdef WITH_FB_JSC_TUNING
|
||||||
configureJSCForAndroid();
|
configureJSCForAndroid();
|
||||||
@ -283,4 +295,17 @@ static JSValueRef nativeLoggingHook(
|
|||||||
return JSValueMakeUndefined(ctx);
|
return JSValueMakeUndefined(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static JSValueRef nativePerformanceNow(
|
||||||
|
JSContextRef ctx,
|
||||||
|
JSObjectRef function,
|
||||||
|
JSObjectRef thisObject,
|
||||||
|
size_t argumentCount,
|
||||||
|
const JSValueRef arguments[], JSValueRef *exception) {
|
||||||
|
// This is equivalent to android.os.SystemClock.elapsedRealtime() in native
|
||||||
|
struct timespec now;
|
||||||
|
clock_gettime(CLOCK_MONOTONIC_RAW, &now);
|
||||||
|
int64_t nano = now.tv_sec * NANOSECONDS_IN_SECOND + now.tv_nsec;
|
||||||
|
return JSValueMakeNumber(ctx, (nano / (double)NANOSECONDS_IN_MILLISECOND));
|
||||||
|
}
|
||||||
|
|
||||||
} }
|
} }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user