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

Function gjs_define_property_dynamic

gjs/jsapi-dynamic-class.cpp:186–214  ·  view source on GitHub ↗

* gjs_define_property_dynamic: * @cx: the #JSContext * @proto: the prototype of the object, on which to define the property * @prop_name: name of the property or field in GObject, visible to JS code * @func_namespace: string from which the internal names for the getter and * setter functions are built, not visible to JS code * @getter: getter function * @setter: setter function * @privat

Source from the content-addressed store, hash-verified

184 * Returns: %true on success, %false if an exception is pending on @cx.
185 */
186bool gjs_define_property_dynamic(JSContext* cx, JS::HandleObject proto,
187 const char* prop_name, JS::HandleId id,
188 const char* func_namespace, JSNative getter,
189 JS::HandleValue getter_slot, JSNative setter,
190 JS::HandleValue setter_slot, unsigned flags) {
191 Gjs::AutoChar getter_name{
192 g_strconcat(func_namespace, "_get::", prop_name, nullptr)};
193 Gjs::AutoChar setter_name{
194 g_strconcat(func_namespace, "_set::", prop_name, nullptr)};
195
196 JS::RootedObject getter_obj(
197 cx, define_native_accessor_wrapper(cx, getter, 0, getter_name,
198 getter_slot));
199 if (!getter_obj)
200 return false;
201
202 JS::RootedObject setter_obj(
203 cx, define_native_accessor_wrapper(cx, setter, 1, setter_name,
204 setter_slot));
205 if (!setter_obj)
206 return false;
207
208 if (id.isVoid()) {
209 return JS_DefineProperty(cx, proto, prop_name, getter_obj, setter_obj,
210 flags);
211 }
212
213 return JS_DefinePropertyById(cx, proto, id, getter_obj, setter_obj, flags);
214}
215
216/**
217 * gjs_dynamic_property_private_slot:

Callers 3

uncached_resolveMethod · 0.85

Calls 1

Tested by

no test coverage detected