summaryrefslogtreecommitdiff
path: root/gjs/objectbox.h
blob: b2d3f349155b92d8f326fbeda7165af7d31d7ceb (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
/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
// SPDX-License-Identifier: MIT OR LGPL-2.0-or-later
// SPDX-FileCopyrightText: 2019 Marco Trevisan <marco.trevisan@canonical.com>

#pragma once

#include <config.h>

#include <memory>

#include <glib-object.h>

#include <js/TypeDecls.h>

#include "gjs/macros.h"

class JSTracer;

struct ObjectBox {
    using Ptr = std::unique_ptr<ObjectBox, void (*)(ObjectBox*)>;

    [[nodiscard]] static GType gtype();

    GJS_JSAPI_RETURN_CONVENTION
    static ObjectBox::Ptr boxed(JSContext*, JSObject*);

    GJS_JSAPI_RETURN_CONVENTION
    static JSObject* object_for_c_ptr(JSContext*, ObjectBox*);

    void trace(JSTracer* trc);

 private:
    explicit ObjectBox(JSObject*);

    static void* boxed_copy(void*);
    static void boxed_free(void*);

    struct impl;
    std::unique_ptr<impl> m_impl;
};