|
36 | 36 | #include "URLImpl.h" |
37 | 37 | #include "URLSearchParamsImpl.h" |
38 | 38 | #include "URLPatternImpl.h" |
| 39 | +#include <chrono> |
39 | 40 |
|
40 | 41 | #ifdef APPLICATION_IN_DEBUG |
41 | 42 | // #include "NetworkDomainCallbackHandlers.h" |
@@ -489,6 +490,10 @@ Isolate* Runtime::PrepareV8Runtime(const string& filesPath, const string& native |
489 | 490 |
|
490 | 491 | tns::instrumentation::Frame isolateFrame; |
491 | 492 | auto isolate = Isolate::New(create_params); |
| 493 | + // Capture start and realtime origin |
| 494 | + // MonotonicallyIncreasingTime returns seconds as double; store for performance.now() |
| 495 | + m_startTime = platform->MonotonicallyIncreasingTime(); |
| 496 | + m_realtimeOrigin = platform->CurrentClockTimeMillis(); |
492 | 497 | isolateFrame.log("Isolate.New"); |
493 | 498 |
|
494 | 499 | s_isolate2RuntimesCache[isolate] = this; |
@@ -531,6 +536,15 @@ Isolate* Runtime::PrepareV8Runtime(const string& filesPath, const string& native |
531 | 536 | globalTemplate->Set(ArgConverter::ConvertToV8String(isolate, "__exit"), FunctionTemplate::New(isolate, CallbackHandlers::ExitMethodCallback)); |
532 | 537 | globalTemplate->Set(ArgConverter::ConvertToV8String(isolate, "__runtimeVersion"), ArgConverter::ConvertToV8String(isolate, NATIVE_SCRIPT_RUNTIME_VERSION), readOnlyFlags); |
533 | 538 | globalTemplate->Set(ArgConverter::ConvertToV8String(isolate, "__time"), FunctionTemplate::New(isolate, CallbackHandlers::TimeCallback)); |
| 539 | + |
| 540 | + // performance object (performance.now() + timeOrigin) |
| 541 | + { |
| 542 | + auto performanceTemplate = ObjectTemplate::New(isolate); |
| 543 | + auto nowFunc = FunctionTemplate::New(isolate, Runtime::PerformanceNowCallback); |
| 544 | + performanceTemplate->Set(ArgConverter::ConvertToV8String(isolate, "now"), nowFunc); |
| 545 | + performanceTemplate->Set(ArgConverter::ConvertToV8String(isolate, "timeOrigin"), Number::New(isolate, m_realtimeOrigin)); |
| 546 | + globalTemplate->Set(ArgConverter::ConvertToV8String(isolate, "performance"), performanceTemplate); |
| 547 | + } |
534 | 548 | globalTemplate->Set(ArgConverter::ConvertToV8String(isolate, "__releaseNativeCounterpart"), FunctionTemplate::New(isolate, CallbackHandlers::ReleaseNativeCounterpartCallback)); |
535 | 549 | globalTemplate->Set(ArgConverter::ConvertToV8String(isolate, "__markingMode"), Number::New(isolate, m_objectManager->GetMarkingMode()), readOnlyFlags); |
536 | 550 | globalTemplate->Set(ArgConverter::ConvertToV8String(isolate, "__runOnMainThread"), FunctionTemplate::New(isolate, CallbackHandlers::RunOnMainThreadCallback)); |
@@ -749,6 +763,14 @@ void Runtime::SetManualInstrumentationMode(jstring mode) { |
749 | 763 | } |
750 | 764 | } |
751 | 765 |
|
| 766 | +void Runtime::PerformanceNowCallback(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 767 | + auto isolate = args.GetIsolate(); |
| 768 | + auto runtime = Runtime::GetRuntime(isolate); |
| 769 | + // Difference in seconds * 1000 for ms |
| 770 | + double ms = (platform->MonotonicallyIncreasingTime() - runtime->m_startTime) * 1000.0; |
| 771 | + args.GetReturnValue().Set(ms); |
| 772 | +} |
| 773 | + |
752 | 774 | void Runtime::DestroyRuntime() { |
753 | 775 | s_id2RuntimeCache.erase(m_id); |
754 | 776 | s_isolate2RuntimesCache.erase(m_isolate); |
|
0 commit comments