LCOV - code coverage report
Current view: top level - src - contexts-inl.h (source / functions) Hit Total Coverage
Test: app.info Lines: 35 35 100.0 %
Date: 2017-04-26 Functions: 24 24 100.0 %

          Line data    Source code
       1             : // Copyright 2015 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_CONTEXTS_INL_H_
       6             : #define V8_CONTEXTS_INL_H_
       7             : 
       8             : #include "src/contexts.h"
       9             : #include "src/heap/heap.h"
      10             : #include "src/objects-inl.h"
      11             : #include "src/objects/dictionary.h"
      12             : #include "src/objects/regexp-match-info.h"
      13             : 
      14             : namespace v8 {
      15             : namespace internal {
      16             : 
      17             : 
      18             : // static
      19             : ScriptContextTable* ScriptContextTable::cast(Object* context) {
      20             :   DCHECK(context->IsScriptContextTable());
      21             :   return reinterpret_cast<ScriptContextTable*>(context);
      22             : }
      23             : 
      24             : 
      25             : int ScriptContextTable::used() const {
      26             :   return Smi::cast(get(kUsedSlot))->value();
      27             : }
      28             : 
      29             : 
      30             : void ScriptContextTable::set_used(int used) {
      31             :   set(kUsedSlot, Smi::FromInt(used));
      32             : }
      33             : 
      34             : 
      35             : // static
      36    10796198 : Handle<Context> ScriptContextTable::GetContext(Handle<ScriptContextTable> table,
      37             :                                                int i) {
      38             :   DCHECK(i < table->used());
      39             :   return Handle<Context>::cast(
      40    10796198 :       FixedArray::get(*table, i + kFirstContextSlot, table->GetIsolate()));
      41             : }
      42             : 
      43             : 
      44             : // static
      45      143498 : Context* Context::cast(Object* context) {
      46             :   DCHECK(context->IsContext());
      47      143498 :   return reinterpret_cast<Context*>(context);
      48             : }
      49             : 
      50             : 
      51       23072 : JSFunction* Context::closure() { return JSFunction::cast(get(CLOSURE_INDEX)); }
      52     1315558 : void Context::set_closure(JSFunction* closure) { set(CLOSURE_INDEX, closure); }
      53             : 
      54             : 
      55             : Context* Context::previous() {
      56             :   Object* result = get(PREVIOUS_INDEX);
      57             :   DCHECK(IsBootstrappingOrValidParentContext(result, this));
      58             :   return reinterpret_cast<Context*>(result);
      59             : }
      60     1315558 : void Context::set_previous(Context* context) { set(PREVIOUS_INDEX, context); }
      61             : 
      62             : Object* Context::next_context_link() { return get(Context::NEXT_CONTEXT_LINK); }
      63             : 
      64      604988 : bool Context::has_extension() { return !extension()->IsTheHole(GetIsolate()); }
      65             : HeapObject* Context::extension() {
      66             :   return HeapObject::cast(get(EXTENSION_INDEX));
      67             : }
      68             : void Context::set_extension(HeapObject* object) {
      69     1456526 :   set(EXTENSION_INDEX, object);
      70             : }
      71             : 
      72             : 
      73       25296 : Context* Context::native_context() {
      74             :   Object* result = get(NATIVE_CONTEXT_INDEX);
      75             :   DCHECK(IsBootstrappingOrNativeContext(this->GetIsolate(), result));
      76       25296 :   return reinterpret_cast<Context*>(result);
      77             : }
      78             : 
      79             : 
      80             : void Context::set_native_context(Context* context) {
      81     1315656 :   set(NATIVE_CONTEXT_INDEX, context);
      82             : }
      83             : 
      84             : 
      85    37325754 : bool Context::IsNativeContext() {
      86             :   Map* map = this->map();
      87    37325754 :   return map == map->GetHeap()->native_context_map();
      88             : }
      89             : 
      90             : 
      91    35872632 : bool Context::IsFunctionContext() {
      92             :   Map* map = this->map();
      93    35872632 :   return map == map->GetHeap()->function_context_map();
      94             : }
      95             : 
      96             : 
      97     3561411 : bool Context::IsCatchContext() {
      98             :   Map* map = this->map();
      99     3561411 :   return map == map->GetHeap()->catch_context_map();
     100             : }
     101             : 
     102             : 
     103    33695730 : bool Context::IsWithContext() {
     104             :   Map* map = this->map();
     105    33695730 :   return map == map->GetHeap()->with_context_map();
     106             : }
     107             : 
     108     3597352 : bool Context::IsDebugEvaluateContext() {
     109             :   Map* map = this->map();
     110     3597352 :   return map == map->GetHeap()->debug_evaluate_context_map();
     111             : }
     112             : 
     113    10780740 : bool Context::IsBlockContext() {
     114             :   Map* map = this->map();
     115    10780740 :   return map == map->GetHeap()->block_context_map();
     116             : }
     117             : 
     118             : 
     119    11105197 : bool Context::IsModuleContext() {
     120             :   Map* map = this->map();
     121    11105197 :   return map == map->GetHeap()->module_context_map();
     122             : }
     123             : 
     124    14547556 : bool Context::IsEvalContext() {
     125             :   Map* map = this->map();
     126    14547556 :   return map == map->GetHeap()->eval_context_map();
     127             : }
     128             : 
     129     4246035 : bool Context::IsScriptContext() {
     130             :   Map* map = this->map();
     131     4246035 :   return map == map->GetHeap()->script_context_map();
     132             : }
     133             : 
     134     1097051 : bool Context::OptimizedCodeMapIsCleared() {
     135     1097051 :   return osr_code_table() == GetHeap()->empty_fixed_array();
     136             : }
     137             : 
     138     5123614 : bool Context::HasSameSecurityTokenAs(Context* that) {
     139             :   return this->native_context()->security_token() ==
     140     5123614 :          that->native_context()->security_token();
     141             : }
     142             : 
     143             : 
     144             : #define NATIVE_CONTEXT_FIELD_ACCESSORS(index, type, name) \
     145             :   void Context::set_##name(type* value) {                 \
     146             :     DCHECK(IsNativeContext());                            \
     147             :     set(index, value);                                    \
     148             :   }                                                       \
     149             :   bool Context::is_##name(type* value) {                  \
     150             :     DCHECK(IsNativeContext());                            \
     151             :     return type::cast(get(index)) == value;               \
     152             :   }                                                       \
     153             :   type* Context::name() {                                 \
     154             :     DCHECK(IsNativeContext());                            \
     155             :     return type::cast(get(index));                        \
     156             :   }
     157    12474244 : NATIVE_CONTEXT_FIELDS(NATIVE_CONTEXT_FIELD_ACCESSORS)
     158             : #undef NATIVE_CONTEXT_FIELD_ACCESSORS
     159             : 
     160             : 
     161             : }  // namespace internal
     162             : }  // namespace v8
     163             : 
     164             : #endif  // V8_CONTEXTS_INL_H_

Generated by: LCOV version 1.10