LCOV - code coverage report
Current view: top level - src/objects - js-regexp-inl.h (source / functions) Hit Total Coverage
Test: app.info Lines: 34 35 97.1 %
Date: 2019-01-20 Functions: 18 18 100.0 %

          Line data    Source code
       1             : // Copyright 2017 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_OBJECTS_JS_REGEXP_INL_H_
       6             : #define V8_OBJECTS_JS_REGEXP_INL_H_
       7             : 
       8             : #include "src/objects/js-regexp.h"
       9             : 
      10             : #include "src/objects-inl.h"  // Needed for write barriers
      11             : #include "src/objects/smi.h"
      12             : #include "src/objects/string.h"
      13             : 
      14             : // Has to be the last include (doesn't have include guards):
      15             : #include "src/objects/object-macros.h"
      16             : 
      17             : namespace v8 {
      18             : namespace internal {
      19             : 
      20     1422410 : OBJECT_CONSTRUCTORS_IMPL(JSRegExp, JSObject)
      21             : 
      22      711205 : CAST_ACCESSOR(JSRegExp)
      23             : 
      24     8237527 : ACCESSORS(JSRegExp, data, Object, kDataOffset)
      25     2294839 : ACCESSORS(JSRegExp, flags, Object, kFlagsOffset)
      26     2294947 : ACCESSORS(JSRegExp, source, Object, kSourceOffset)
      27       29721 : ACCESSORS(JSRegExp, last_index, Object, kLastIndexOffset)
      28             : 
      29      500085 : JSRegExp::Type JSRegExp::TypeTag() const {
      30      500085 :   Object data = this->data();
      31      500085 :   if (data->IsUndefined()) return JSRegExp::NOT_COMPILED;
      32             :   Smi smi = Smi::cast(FixedArray::cast(data)->get(kTagIndex));
      33      500085 :   return static_cast<JSRegExp::Type>(smi->value());
      34             : }
      35             : 
      36      189382 : int JSRegExp::CaptureCount() {
      37      189382 :   switch (TypeTag()) {
      38             :     case ATOM:
      39             :       return 0;
      40             :     case IRREGEXP:
      41        8314 :       return Smi::ToInt(DataAt(kIrregexpCaptureCountIndex));
      42             :     default:
      43           0 :       UNREACHABLE();
      44             :   }
      45             : }
      46             : 
      47      194947 : JSRegExp::Flags JSRegExp::GetFlags() {
      48             :   DCHECK(this->data()->IsFixedArray());
      49      194947 :   Object data = this->data();
      50             :   Smi smi = Smi::cast(FixedArray::cast(data)->get(kFlagsIndex));
      51      194947 :   return Flags(smi->value());
      52             : }
      53             : 
      54       86314 : String JSRegExp::Pattern() {
      55             :   DCHECK(this->data()->IsFixedArray());
      56       86314 :   Object data = this->data();
      57             :   String pattern = String::cast(FixedArray::cast(data)->get(kSourceIndex));
      58       86314 :   return pattern;
      59             : }
      60             : 
      61         108 : Object JSRegExp::CaptureNameMap() {
      62             :   DCHECK(this->data()->IsFixedArray());
      63             :   DCHECK_EQ(TypeTag(), IRREGEXP);
      64      176958 :   Object value = DataAt(kIrregexpCaptureNameMapIndex);
      65             :   DCHECK_NE(value, Smi::FromInt(JSRegExp::kUninitializedValue));
      66      176958 :   return value;
      67             : }
      68             : 
      69      506619 : Object JSRegExp::DataAt(int index) const {
      70             :   DCHECK(TypeTag() != NOT_COMPILED);
      71     1013238 :   return FixedArray::cast(data())->get(index);
      72             : }
      73             : 
      74          10 : void JSRegExp::SetDataAt(int index, Object value) {
      75             :   DCHECK(TypeTag() != NOT_COMPILED);
      76             :   DCHECK_GE(index,
      77             :             kDataIndex);  // Only implementation data can be set this way.
      78          20 :   FixedArray::cast(data())->set(index, value);
      79          10 : }
      80             : 
      81          30 : bool JSRegExp::HasCompiledCode() const {
      82          95 :   return TypeTag() == IRREGEXP && (DataAt(kIrregexpLatin1CodeIndex)->IsCode() ||
      83          80 :                                    DataAt(kIrregexpUC16CodeIndex)->IsCode());
      84             : }
      85             : 
      86           5 : void JSRegExp::DiscardCompiledCodeForSerialization() {
      87             :   DCHECK(HasCompiledCode());
      88           5 :   SetDataAt(kIrregexpLatin1CodeIndex, Smi::FromInt(kUninitializedValue));
      89           5 :   SetDataAt(kIrregexpUC16CodeIndex, Smi::FromInt(kUninitializedValue));
      90           5 : }
      91             : 
      92             : }  // namespace internal
      93             : }  // namespace v8
      94             : 
      95             : #include "src/objects/object-macros-undef.h"
      96             : 
      97             : #endif  // V8_OBJECTS_JS_REGEXP_INL_H_

Generated by: LCOV version 1.10