LCOV - code coverage report
Current view: top level - modules - cairo.cpp (source / functions) Coverage Total Hit
Test: gjs-1.87.1 Code Coverage Lines: 85.3 % 34 29
Test Date: 2026-01-05 03:41:30 Functions: 100.0 % 3 3
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 53.3 % 30 16

             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: 2010 litl, LLC.
       4                 :             : 
       5                 :             : #include <config.h>
       6                 :             : 
       7                 :             : #include <cairo-features.h>  // for CAIRO_HAS_PDF_SURFACE, CAIRO_HAS_PS_SURFA...
       8                 :             : #include <cairo.h>
       9                 :             : 
      10                 :             : #ifdef CAIRO_HAS_XLIB_SURFACE
      11                 :             : #    include <cairo-xlib.h>
      12                 :             : #    undef None
      13                 :             : // X11 defines a global None macro. Rude! This conflicts with None used as an
      14                 :             : // enum member in SpiderMonkey headers, e.g. JS::ExceptionStatus::None.
      15                 :             : #endif
      16                 :             : 
      17                 :             : #include <js/RootingAPI.h>
      18                 :             : #include <js/TypeDecls.h>
      19                 :             : #include <jsapi.h>  // for JS_NewPlainObject
      20                 :             : 
      21                 :             : #include "gjs/jsapi-util.h"
      22                 :             : #include "modules/cairo-private.h"  // IWYU pragma: associated
      23                 :             : 
      24                 :             : #ifdef CAIRO_HAS_XLIB_SURFACE
      25                 :             : class XLibConstructor {
      26                 :             :  public:
      27                 :         129 :     XLibConstructor() {
      28                 :         129 :         XInitThreads();
      29                 :         129 :     }
      30                 :             : };
      31                 :             : 
      32                 :             : static XLibConstructor constructor;
      33                 :             : #endif
      34                 :             : 
      35                 :         219 : bool gjs_cairo_check_status(JSContext* cx, cairo_status_t status,
      36                 :             :                             const char* name) {
      37         [ +  + ]:         219 :     if (status != CAIRO_STATUS_SUCCESS) {
      38                 :           1 :         gjs_throw(cx, "cairo error on %s: \"%s\" (%d)", name,
      39                 :             :                   cairo_status_to_string(status), status);
      40                 :           1 :         return false;
      41                 :             :     }
      42                 :             : 
      43                 :         218 :     return true;
      44                 :             : }
      45                 :             : 
      46                 :           2 : bool gjs_js_define_cairo_stuff(JSContext* cx, JS::MutableHandleObject module) {
      47                 :           2 :     module.set(JS_NewPlainObject(cx));
      48                 :             : 
      49         [ -  + ]:           2 :     if (!CairoRegion::create_prototype(cx, module))
      50                 :           0 :         return false;
      51                 :           2 :     gjs_cairo_region_init();
      52                 :             : 
      53         [ -  + ]:           2 :     if (!CairoContext::create_prototype(cx, module))
      54                 :           0 :         return false;
      55                 :           2 :     gjs_cairo_context_init();
      56                 :             : 
      57         [ -  + ]:           2 :     if (!CairoSurface::create_prototype(cx, module))
      58                 :           0 :         return false;
      59                 :           2 :     gjs_cairo_surface_init();
      60                 :             : 
      61         [ -  + ]:           2 :     if (!CairoPattern::create_prototype(cx, module))
      62                 :           0 :         return false;
      63                 :           2 :     gjs_cairo_pattern_init();
      64                 :             : 
      65         [ -  + ]:           2 :     if (!CairoPath::create_prototype(cx, module))
      66                 :           0 :         return false;
      67                 :           2 :     gjs_cairo_path_init();
      68                 :             : 
      69         [ +  - ]:           4 :     return CairoImageSurface::create_prototype(cx, module) &&
      70                 :             : #if CAIRO_HAS_PS_SURFACE
      71         [ +  - ]:           4 :            CairoPSSurface::create_prototype(cx, module) &&
      72                 :             : #endif
      73                 :             : #if CAIRO_HAS_PDF_SURFACE
      74         [ +  - ]:           4 :            CairoPDFSurface::create_prototype(cx, module) &&
      75                 :             : #endif
      76                 :             : #if CAIRO_HAS_SVG_SURFACE
      77         [ +  - ]:           4 :            CairoSVGSurface::create_prototype(cx, module) &&
      78                 :             : #endif
      79         [ +  - ]:           4 :            CairoGradient::create_prototype(cx, module) &&
      80         [ +  - ]:           4 :            CairoLinearGradient::create_prototype(cx, module) &&
      81         [ +  - ]:           4 :            CairoRadialGradient::create_prototype(cx, module) &&
      82   [ +  -  +  - ]:           6 :            CairoSurfacePattern::create_prototype(cx, module) &&
      83                 :           4 :            CairoSolidPattern::create_prototype(cx, module);
      84                 :             : }
        

Generated by: LCOV version 2.0-1