MCPcopy Create free account
hub / github.com/GNOME/gjs / gjs_define_enum_value

Function gjs_define_enum_value

gi/enumeration.cpp:30–62  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28#include "util/log.h"
29
30GJS_JSAPI_RETURN_CONVENTION
31static bool gjs_define_enum_value(JSContext* cx, JS::HandleObject in_object,
32 const GI::ValueInfo& info) {
33 const char* value_name = info.name();
34 int64_t value_val = info.value();
35
36 /* g-i converts enum members such as GDK_GRAVITY_SOUTH_WEST to
37 * Gdk.GravityType.south-west (where 'south-west' is value_name) Convert
38 * back to all SOUTH_WEST.
39 */
40 Gjs::AutoChar fixed_name{g_ascii_strup(value_name, -1)};
41 for (size_t i = 0; fixed_name[i]; ++i) {
42 char c = fixed_name[i];
43 if (!(g_ascii_isupper(c) || g_ascii_isdigit(c)))
44 fixed_name[i] = '_';
45 }
46
47 gjs_debug(GJS_DEBUG_GENUM,
48 "Defining enum value %s (fixed from %s) %" PRId64,
49 fixed_name.get(), value_name, value_val);
50
51 if (!JS_DefineProperty(cx, in_object, fixed_name,
52 static_cast<double>(value_val),
53 GJS_MODULE_PROP_FLAGS)) {
54 gjs_throw(cx,
55 "Unable to define enumeration value %s %" PRId64
56 " (no memory most likely)",
57 fixed_name.get(), value_val);
58 return false;
59 }
60
61 return true;
62}
63
64bool gjs_define_enum_values(JSContext* cx, JS::HandleObject in_object,
65 const GI::EnumInfo& info) {

Callers 1

gjs_define_enum_valuesFunction · 0.85

Calls 5

gjs_debugFunction · 0.85
gjs_throwFunction · 0.85
nameMethod · 0.45
valueMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected