|
34 | 34 | #include "URLImpl.h"
|
35 | 35 | #include "URLSearchParamsImpl.h"
|
36 | 36 | #include "URLPatternImpl.h"
|
| 37 | +#include <chrono> |
37 | 38 |
|
38 | 39 | #ifdef APPLICATION_IN_DEBUG
|
39 | 40 | // #include "NetworkDomainCallbackHandlers.h"
|
@@ -487,6 +488,10 @@ Isolate* Runtime::PrepareV8Runtime(const string& filesPath, const string& native
|
487 | 488 |
|
488 | 489 | tns::instrumentation::Frame isolateFrame;
|
489 | 490 | auto isolate = Isolate::New(create_params);
|
| 491 | + // Capture start and realtime origin |
| 492 | + // MonotonicallyIncreasingTime returns seconds as double; store for performance.now() |
| 493 | + m_startTime = platform->MonotonicallyIncreasingTime(); |
| 494 | + m_realtimeOrigin = platform->CurrentClockTimeMillis(); |
490 | 495 | isolateFrame.log("Isolate.New");
|
491 | 496 |
|
492 | 497 | s_isolate2RuntimesCache[isolate] = this;
|
@@ -523,6 +528,15 @@ Isolate* Runtime::PrepareV8Runtime(const string& filesPath, const string& native
|
523 | 528 | globalTemplate->Set(ArgConverter::ConvertToV8String(isolate, "__exit"), FunctionTemplate::New(isolate, CallbackHandlers::ExitMethodCallback));
|
524 | 529 | globalTemplate->Set(ArgConverter::ConvertToV8String(isolate, "__runtimeVersion"), ArgConverter::ConvertToV8String(isolate, NATIVE_SCRIPT_RUNTIME_VERSION), readOnlyFlags);
|
525 | 530 | globalTemplate->Set(ArgConverter::ConvertToV8String(isolate, "__time"), FunctionTemplate::New(isolate, CallbackHandlers::TimeCallback));
|
| 531 | + |
| 532 | + // performance object (performance.now() + timeOrigin) |
| 533 | + { |
| 534 | + auto performanceTemplate = ObjectTemplate::New(isolate); |
| 535 | + auto nowFunc = FunctionTemplate::New(isolate, Runtime::PerformanceNowCallback); |
| 536 | + performanceTemplate->Set(ArgConverter::ConvertToV8String(isolate, "now"), nowFunc); |
| 537 | + performanceTemplate->Set(ArgConverter::ConvertToV8String(isolate, "timeOrigin"), Number::New(isolate, m_realtimeOrigin)); |
| 538 | + globalTemplate->Set(ArgConverter::ConvertToV8String(isolate, "performance"), performanceTemplate); |
| 539 | + } |
526 | 540 | globalTemplate->Set(ArgConverter::ConvertToV8String(isolate, "__releaseNativeCounterpart"), FunctionTemplate::New(isolate, CallbackHandlers::ReleaseNativeCounterpartCallback));
|
527 | 541 | globalTemplate->Set(ArgConverter::ConvertToV8String(isolate, "__markingMode"), Number::New(isolate, m_objectManager->GetMarkingMode()), readOnlyFlags);
|
528 | 542 | globalTemplate->Set(ArgConverter::ConvertToV8String(isolate, "__runOnMainThread"), FunctionTemplate::New(isolate, CallbackHandlers::RunOnMainThreadCallback));
|
@@ -741,6 +755,14 @@ void Runtime::SetManualInstrumentationMode(jstring mode) {
|
741 | 755 | }
|
742 | 756 | }
|
743 | 757 |
|
| 758 | +void Runtime::PerformanceNowCallback(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 759 | + auto isolate = args.GetIsolate(); |
| 760 | + auto runtime = Runtime::GetRuntime(isolate); |
| 761 | + // Difference in seconds * 1000 for ms |
| 762 | + double ms = (platform->MonotonicallyIncreasingTime() - runtime->m_startTime) * 1000.0; |
| 763 | + args.GetReturnValue().Set(ms); |
| 764 | +} |
| 765 | + |
744 | 766 | void Runtime::DestroyRuntime() {
|
745 | 767 | s_id2RuntimeCache.erase(m_id);
|
746 | 768 | s_isolate2RuntimesCache.erase(m_isolate);
|
|
0 commit comments