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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
// SPDX-License-Identifier: MIT OR LGPL-2.0-or-later
// SPDX-FileCopyrightText: 2025 Philip Chimento <philip.chimento@gmail.com>
#pragma once
#include <config.h>
#include <glib-object.h>
#include <glib.h>
#include <js/TypeDecls.h>
#include "gi/boxed.h"
#include "gi/cwrapper.h"
#include "gi/info.h"
#include "gi/wrapperutils.h"
#include "gjs/macros.h"
namespace JS {
class CallArgs;
}
struct JSClassOps;
class StructPrototype;
class StructInstance;
class StructBase
: public BoxedBase<StructBase, StructPrototype, StructInstance> {
friend class CWrapperPointerOps<StructBase>;
friend class GIWrapperBase<StructBase, StructPrototype, StructInstance>;
friend class BoxedBase<StructBase, StructPrototype, StructInstance>;
friend class BoxedPrototype<StructBase, StructPrototype, StructInstance>;
friend class BoxedInstance<StructBase, StructPrototype, StructInstance>;
protected:
using BoxedBase::BoxedBase;
static constexpr const char* DEBUG_TAG = "boxed"; // for historical reasons
static const JSClassOps class_ops;
static const JSClass klass;
public:
static constexpr const GI::InfoTag TAG = GI::InfoTag::STRUCT;
};
class StructPrototype
: public BoxedPrototype<StructBase, StructPrototype, StructInstance> {
friend class GIWrapperPrototype<StructBase, StructPrototype, StructInstance,
GI::AutoStructInfo, GI::StructInfo>;
StructPrototype(const GI::StructInfo, GType);
~StructPrototype();
public:
GJS_JSAPI_RETURN_CONVENTION
static bool define_class(JSContext* cx, JS::HandleObject in_object,
const GI::StructInfo);
};
class StructInstance
: public BoxedInstance<StructBase, StructPrototype, StructInstance> {
friend class GIWrapperBase<StructBase, StructPrototype, StructInstance>;
friend class GIWrapperInstance<StructBase, StructPrototype, StructInstance>;
StructInstance(StructPrototype*, JS::HandleObject);
~StructInstance();
GJS_JSAPI_RETURN_CONVENTION
bool constructor_impl(JSContext*, JS::HandleObject, const JS::CallArgs&);
GJS_JSAPI_RETURN_CONVENTION
static void* copy_ptr(JSContext* cx, GType gtype, void* ptr) {
if (g_type_is_a(gtype, G_TYPE_VARIANT))
return g_variant_ref(static_cast<GVariant*>(ptr));
return BoxedInstance::copy_ptr(cx, gtype, ptr);
}
public:
GJS_JSAPI_RETURN_CONVENTION
static JSObject* new_for_c_struct(JSContext*, const GI::StructInfo,
void* gboxed);
GJS_JSAPI_RETURN_CONVENTION
static JSObject* new_for_c_struct(JSContext*, const GI::StructInfo,
void* gboxed, Boxed::NoCopy);
};
|