LCOV - code coverage report
Current view: top level - js/src/irregexp - RegExpStack.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 34 41 82.9 %
Date: 2017-07-14 16:53:18 Functions: 7 8 87.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
       2             :  * vim: set ts=8 sts=4 et sw=4 tw=99: */
       3             : 
       4             : // Copyright 2012 the V8 project authors. All rights reserved.
       5             : // Redistribution and use in source and binary forms, with or without
       6             : // modification, are permitted provided that the following conditions are
       7             : // met:
       8             : //
       9             : //     * Redistributions of source code must retain the above copyright
      10             : //       notice, this list of conditions and the following disclaimer.
      11             : //     * Redistributions in binary form must reproduce the above
      12             : //       copyright notice, this list of conditions and the following
      13             : //       disclaimer in the documentation and/or other materials provided
      14             : //       with the distribution.
      15             : //     * Neither the name of Google Inc. nor the names of its
      16             : //       contributors may be used to endorse or promote products derived
      17             : //       from this software without specific prior written permission.
      18             : //
      19             : // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
      20             : // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
      21             : // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
      22             : // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
      23             : // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
      24             : // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
      25             : // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
      26             : // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
      27             : // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
      28             : // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
      29             : // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
      30             : 
      31             : #include "irregexp/RegExpStack.h"
      32             : 
      33             : #include "jscntxt.h"
      34             : 
      35             : using namespace js;
      36             : using namespace js::irregexp;
      37             : 
      38         264 : RegExpStackScope::RegExpStackScope(JSContext* cx)
      39         264 :   : regexp_stack(&cx->regexpStack.ref())
      40         264 : {}
      41             : 
      42         528 : RegExpStackScope::~RegExpStackScope()
      43             : {
      44         264 :     regexp_stack->reset();
      45         264 : }
      46             : 
      47             : int
      48           2 : irregexp::GrowBacktrackStack(JSRuntime* rt)
      49             : {
      50           2 :     return TlsContext.get()->regexpStack.ref().grow();
      51             : }
      52             : 
      53          40 : RegExpStack::RegExpStack()
      54          40 :   : base_(nullptr), size(0), limit_(nullptr)
      55          40 : {}
      56             : 
      57           0 : RegExpStack::~RegExpStack()
      58             : {
      59           0 :     js_free(base_);
      60           0 : }
      61             : 
      62             : bool
      63           4 : RegExpStack::init()
      64             : {
      65           4 :     base_ = js_malloc(kMinimumStackSize);
      66           4 :     if (!base_)
      67           0 :         return false;
      68             : 
      69           4 :     size = kMinimumStackSize;
      70           4 :     updateLimit();
      71           4 :     return true;
      72             : }
      73             : 
      74             : void
      75         264 : RegExpStack::reset()
      76             : {
      77         264 :     MOZ_ASSERT(size >= kMinimumStackSize);
      78             : 
      79         264 :     if (size != kMinimumStackSize) {
      80           2 :         void* newBase = js_realloc(base_, kMinimumStackSize);
      81           2 :         if (!newBase)
      82           0 :             return;
      83             : 
      84           2 :         base_ = newBase;
      85           2 :         size = kMinimumStackSize;
      86           2 :         updateLimit();
      87             :     }
      88             : }
      89             : 
      90             : bool
      91           2 : RegExpStack::grow()
      92             : {
      93           2 :     size_t newSize = size * 2;
      94           2 :     if (newSize > kMaximumStackSize)
      95           0 :         return false;
      96             : 
      97           2 :     void* newBase = js_realloc(base_, newSize);
      98           2 :     if (!newBase)
      99           0 :         return false;
     100             : 
     101           2 :     base_ = newBase;
     102           2 :     size = newSize;
     103           2 :     updateLimit();
     104             : 
     105           2 :     return true;
     106             : }

Generated by: LCOV version 1.13