summaryrefslogtreecommitdiff
path: root/modules/cairo-path.cpp
blob: b6b0726c64dea9411b6a5059b294972e48a91e67 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
// SPDX-License-Identifier: MIT OR LGPL-2.0-or-later
// SPDX-FileCopyrightText: 2010 Red Hat, Inc.
// SPDX-FileCopyrightText: 2020 Philip Chimento <philip.chimento@gmail.com>

#include <config.h>

#include <cairo.h>

#include <js/PropertyDescriptor.h>  // for JSPROP_READONLY
#include <js/PropertySpec.h>
#include <js/RootingAPI.h>
#include <js/TypeDecls.h>
#include <jsapi.h>  // for JS_NewObjectWithGivenProto

#include "modules/cairo-private.h"

// clang-format off
const JSPropertySpec CairoPath::proto_props[] = {
    JS_STRING_SYM_PS(toStringTag, "Path", JSPROP_READONLY),
    JS_PS_END};
// clang-format on

/*
 * CairoPath::take_c_ptr():
 * Same as CWrapper::from_c_ptr(), but always takes ownership of the pointer
 * rather than copying it. It's not possible to copy a cairo_path_t*.
 */
JSObject* CairoPath::take_c_ptr(JSContext* cx, cairo_path_t* ptr) {
    JS::RootedObject proto(cx, CairoPath::prototype(cx));
    if (!proto)
        return nullptr;

    JS::RootedObject wrapper(
        cx, JS_NewObjectWithGivenProto(cx, &CairoPath::klass, proto));
    if (!wrapper)
        return nullptr;

    CairoPath::init_private(wrapper, ptr);

    debug_lifecycle(ptr, wrapper, "take_c_ptr");

    return wrapper;
}

void CairoPath::finalize_impl(JS::GCContext*, cairo_path_t* path) {
    if (!path)
        return;
    cairo_path_destroy(path);
}