LCOV - code coverage report
Current view: top level - src/ast - compile-time-value.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 16 16 100.0 %
Date: 2017-04-26 Functions: 4 4 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             : #include "src/ast/compile-time-value.h"
       6             : 
       7             : #include "src/ast/ast.h"
       8             : #include "src/factory.h"
       9             : #include "src/handles-inl.h"
      10             : #include "src/isolate.h"
      11             : #include "src/objects-inl.h"
      12             : 
      13             : namespace v8 {
      14             : namespace internal {
      15             : 
      16    39123387 : bool CompileTimeValue::IsCompileTimeValue(Expression* expression) {
      17    39123389 :   if (expression->IsLiteral()) return true;
      18     4686754 :   MaterializedLiteral* lit = expression->AsMaterializedLiteral();
      19     4686754 :   return lit != NULL && lit->is_simple();
      20             : }
      21             : 
      22      294850 : Handle<FixedArray> CompileTimeValue::GetValue(Isolate* isolate,
      23             :                                               Expression* expression) {
      24             :   Factory* factory = isolate->factory();
      25             :   DCHECK(IsCompileTimeValue(expression));
      26      294850 :   Handle<FixedArray> result = factory->NewFixedArray(2, TENURED);
      27      523090 :   ObjectLiteral* object_literal = expression->AsObjectLiteral();
      28      294850 :   if (object_literal != NULL) {
      29             :     DCHECK(object_literal->is_simple());
      30      228240 :     if (object_literal->fast_elements()) {
      31             :       result->set(kLiteralTypeSlot, Smi::FromInt(OBJECT_LITERAL_FAST_ELEMENTS));
      32             :     } else {
      33             :       result->set(kLiteralTypeSlot, Smi::FromInt(OBJECT_LITERAL_SLOW_ELEMENTS));
      34             :     }
      35      228240 :     result->set(kElementsSlot, *object_literal->constant_properties());
      36             :   } else {
      37             :     ArrayLiteral* array_literal = expression->AsArrayLiteral();
      38             :     DCHECK(array_literal != NULL && array_literal->is_simple());
      39             :     result->set(kLiteralTypeSlot, Smi::FromInt(ARRAY_LITERAL));
      40       66610 :     result->set(kElementsSlot, *array_literal->constant_elements());
      41             :   }
      42      294850 :   return result;
      43             : }
      44             : 
      45      305069 : CompileTimeValue::LiteralType CompileTimeValue::GetLiteralType(
      46             :     Handle<FixedArray> value) {
      47             :   Smi* literal_type = Smi::cast(value->get(kLiteralTypeSlot));
      48      305069 :   return static_cast<LiteralType>(literal_type->value());
      49             : }
      50             : 
      51      305069 : Handle<HeapObject> CompileTimeValue::GetElements(Handle<FixedArray> value) {
      52      305069 :   return Handle<HeapObject>(HeapObject::cast(value->get(kElementsSlot)));
      53             : }
      54             : 
      55             : }  // namespace internal
      56             : }  // namespace v8

Generated by: LCOV version 1.10