LCOV - code coverage report
Current view: top level - src - utils-inl.h (source / functions) Hit Total Coverage
Test: app.info Lines: 18 18 100.0 %
Date: 2017-10-20 Functions: 3 3 100.0 %

          Line data    Source code
       1             : // Copyright 2016 the V8 project authors. All rights reserved.
       2             : // Use of this source code is governed by a BSD-style license that can be
       3             : // found in the LICENSE file.
       4             : 
       5             : #ifndef V8_UTILS_INL_H_
       6             : #define V8_UTILS_INL_H_
       7             : 
       8             : #include "src/utils.h"
       9             : 
      10             : #include "include/v8-platform.h"
      11             : #include "src/base/platform/time.h"
      12             : #include "src/char-predicates-inl.h"
      13             : #include "src/v8.h"
      14             : 
      15             : namespace v8 {
      16             : namespace internal {
      17             : 
      18             : class TimedScope {
      19             :  public:
      20             :   explicit TimedScope(double* result)
      21      333309 :       : start_(TimestampMs()), result_(result) {}
      22             : 
      23      333465 :   ~TimedScope() { *result_ = TimestampMs() - start_; }
      24             : 
      25             :  private:
      26      666495 :   static inline double TimestampMs() {
      27      666495 :     return V8::GetCurrentPlatform()->MonotonicallyIncreasingTime() *
      28      666692 :            static_cast<double>(base::Time::kMillisecondsPerSecond);
      29             :   }
      30             : 
      31             :   double start_;
      32             :   double* result_;
      33             : };
      34             : 
      35             : template <typename Stream>
      36     1760846 : bool StringToArrayIndex(Stream* stream, uint32_t* index) {
      37     1760817 :   uint16_t ch = stream->GetNext();
      38             : 
      39             :   // If the string begins with a '0' character, it must only consist
      40             :   // of it to be a legal array index.
      41     1760846 :   if (ch == '0') {
      42      108059 :     *index = 0;
      43      108059 :     return !stream->HasMore();
      44             :   }
      45             : 
      46             :   // Convert string to uint32 array index; character by character.
      47     3305574 :   if (!IsDecimalDigit(ch)) return false;
      48             :   int d = ch - '0';
      49             :   uint32_t result = d;
      50       22863 :   while (stream->HasMore()) {
      51       20750 :     ch = stream->GetNext();
      52       41974 :     if (!IsDecimalDigit(ch)) return false;
      53             :     d = ch - '0';
      54             :     // Check that the new result is below the 32 bit limit.
      55       18941 :     if (result > 429496729U - ((d + 3) >> 3)) return false;
      56       18662 :     result = (result * 10) + d;
      57             :   }
      58             : 
      59        1876 :   *index = result;
      60        1876 :   return true;
      61             : }
      62             : 
      63             : }  // namespace internal
      64             : }  // namespace v8
      65             : 
      66             : #endif  // V8_UTILS_INL_H_

Generated by: LCOV version 1.10