LCOV - code coverage report
Current view: top level - gjs - atoms.cpp (source / functions) Coverage Total Hit
Test: gjs- Code Coverage Lines: 87.5 % 24 21
Test Date: 2024-04-16 04:37:39 Functions: 100.0 % 4 4
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 50.0 % 132 66

             Branch data     Line data    Source code
       1                 :             : /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
       2                 :             : // SPDX-License-Identifier: MIT OR LGPL-2.0-or-later
       3                 :             : // SPDX-FileCopyrightText: 2018 Philip Chimento <philip.chimento@gmail.com>
       4                 :             : // SPDX-FileCopyrightText: 2018 Marco Trevisan <marco.trevisan@canonical.com>
       5                 :             : 
       6                 :             : #define GJS_USE_ATOM_FOREACH
       7                 :             : 
       8                 :             : #include <config.h>
       9                 :             : 
      10                 :             : #include <js/Id.h>
      11                 :             : #include <js/RootingAPI.h>
      12                 :             : #include <js/String.h>
      13                 :             : #include <js/Symbol.h>
      14                 :             : #include <js/TracingAPI.h>
      15                 :             : #include <js/TypeDecls.h>
      16                 :             : 
      17                 :             : #include "gjs/atoms.h"
      18                 :             : 
      19                 :       13552 : bool GjsAtom::init(JSContext* cx, const char* str) {
      20                 :       13552 :     JSString* s = JS_AtomizeAndPinString(cx, str);
      21         [ -  + ]:       13552 :     if (!s)
      22                 :           0 :         return false;
      23                 :       13552 :     m_jsid = JS::Heap<jsid>{JS::PropertyKey::fromPinnedString(s)};
      24                 :       13552 :     return true;
      25                 :             : }
      26                 :             : 
      27                 :        1694 : bool GjsSymbolAtom::init(JSContext* cx, const char* str) {
      28                 :        1694 :     JS::RootedString descr(cx, JS_AtomizeAndPinString(cx, str));
      29         [ -  + ]:        1694 :     if (!descr)
      30                 :           0 :         return false;
      31                 :        1694 :     JS::Symbol* symbol = JS::NewSymbol(cx, descr);
      32         [ -  + ]:        1694 :     if (!symbol)
      33                 :           0 :         return false;
      34                 :        1694 :     m_jsid = JS::Heap<jsid>{JS::PropertyKey::Symbol(symbol)};
      35                 :        1694 :     return true;
      36                 :        1694 : }
      37                 :             : 
      38                 :             : /* Requires a current realm. This can GC, so it needs to be done after the
      39                 :             :  * tracing has been set up. */
      40                 :         242 : bool GjsAtoms::init_atoms(JSContext* cx) {
      41                 :             : #define INITIALIZE_ATOM(identifier, str) \
      42                 :             :     if (!identifier.init(cx, str))       \
      43                 :             :         return false;
      44   [ -  +  -  +  :         242 :     FOR_EACH_ATOM(INITIALIZE_ATOM)
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
                +  -  + ]
      45   [ -  +  -  +  :         242 :     FOR_EACH_SYMBOL_ATOM(INITIALIZE_ATOM)
          -  +  -  +  -  
             +  -  +  -  
                      + ]
      46                 :         242 :     return true;
      47                 :             : }
      48                 :             : 
      49                 :         323 : void GjsAtoms::trace(JSTracer* trc) {
      50                 :             : #define TRACE_ATOM(identifier, str) \
      51                 :             :     JS::TraceEdge<jsid>(trc, identifier.id(), "Atom " str);
      52                 :         323 :     FOR_EACH_ATOM(TRACE_ATOM)
      53                 :         323 :     FOR_EACH_SYMBOL_ATOM(TRACE_ATOM)
      54                 :             : #undef TRACE_ATOM
      55                 :         323 : }
        

Generated by: LCOV version 2.0-1