| 478 | } |
| 479 | |
| 480 | void Console::timeEndCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 481 | try { |
| 482 | auto isolate = info.GetIsolate(); |
| 483 | |
| 484 | auto argLen = info.Length(); |
| 485 | std::string label = "default"; |
| 486 | |
| 487 | v8::Local<v8::String> argString; |
| 488 | if (argLen && info[0]->ToString(isolate->GetCurrentContext()).ToLocal(&argString)) { |
| 489 | label = ArgConverter::ConvertToString(argString); |
| 490 | } |
| 491 | |
| 492 | auto it = Console::s_isolateToConsoleTimersMap.find(isolate); |
| 493 | if (it == Console::s_isolateToConsoleTimersMap.end()) { |
| 494 | // throw? |
| 495 | } |
| 496 | |
| 497 | std::map<std::string, double> timersMap = it->second; |
| 498 | |
| 499 | auto itTimersMap = timersMap.find(label); |
| 500 | if (itTimersMap == timersMap.end()) { |
| 501 | std::string warning = std::string("No such label '" + label + "' for console.timeEnd()"); |
| 502 | |
| 503 | __android_log_write(ANDROID_LOG_WARN, LOG_TAG, warning.c_str()); |
| 504 | sendToDevToolsFrontEnd(isolate, ConsoleAPIType::kWarning, warning); |
| 505 | |
| 506 | return; |
| 507 | } |
| 508 | |
| 509 | auto nano = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()); |
| 510 | double endTimeStamp = nano.time_since_epoch().count(); |
| 511 | double startTimeStamp = itTimersMap->second; |
| 512 | |
| 513 | it->second.erase(label); |
| 514 | |
| 515 | double diffMicroseconds = endTimeStamp - startTimeStamp; |
| 516 | double diffMilliseconds = diffMicroseconds / 1000.0; |
| 517 | |
| 518 | std::stringstream ss; |
| 519 | ss << "CONSOLE TIME: " << label << ": " << std::fixed << std::setprecision(3) << diffMilliseconds << "ms" ; |
| 520 | std::string log = ss.str(); |
| 521 | |
| 522 | __android_log_write(ANDROID_LOG_INFO, LOG_TAG, log.c_str()); |
| 523 | sendToDevToolsFrontEnd(isolate, ConsoleAPIType::kTimeEnd, log); |
| 524 | } catch (NativeScriptException& e) { |
| 525 | e.ReThrowToV8(); |
| 526 | } catch (std::exception e) { |
| 527 | std::stringstream ss; |
| 528 | ss << "Error: c++ exception: " << e.what() << std::endl; |
| 529 | NativeScriptException nsEx(ss.str()); |
| 530 | nsEx.ReThrowToV8(); |
| 531 | } catch (...) { |
| 532 | NativeScriptException nsEx(std::string("Error: c++ exception!")); |
| 533 | nsEx.ReThrowToV8(); |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | void Console::onDisposeIsolate(v8::Isolate* isolate) { |
nothing calls this directly
no test coverage detected