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

Method init_custom_class_from_gobject

gi/object.cpp:3533–3562  ·  view source on GitHub ↗

* ObjectInstance::init_custom_class_from_gobject: * * Does all the necessary initialization for an ObjectInstance and JSObject * wrapper, given a newly-created GObject pointer, of a GObject class that was * created in JS with GObject.registerClass(). This is called from the GObject's * instance init function in gobject.cpp, and that's the only reason it's a * public method. */

Source from the content-addressed store, hash-verified

3531 * public method.
3532 */
3533bool ObjectInstance::init_custom_class_from_gobject(JSContext* cx,
3534 JS::HandleObject wrapper,
3535 GObject* gobj) {
3536 associate_js_gobject(cx, wrapper, gobj);
3537
3538 // Custom JS objects will most likely have visible state, so just do this
3539 // from the start.
3540 ensure_uses_toggle_ref(cx);
3541 if (!m_uses_toggle_ref) {
3542 gjs_throw(cx, "Impossible to set toggle references on %sobject %p",
3543 m_gobj_disposed ? "disposed " : "", gobj);
3544 return false;
3545 }
3546
3547 const GjsAtoms& atoms = GjsContextPrivate::atoms(cx);
3548 JS::RootedValue v(cx);
3549 if (!JS_GetPropertyById(cx, wrapper, atoms.instance_init(), &v))
3550 return false;
3551
3552 if (v.isUndefined())
3553 return true;
3554 if (!v.isObject() || !JS::IsCallable(&v.toObject())) {
3555 gjs_throw(cx, "_instance_init property was not a function");
3556 return false;
3557 }
3558
3559 JS::RootedValue ignored_rval(cx);
3560 return JS_CallFunctionValue(cx, wrapper, v, JS::HandleValueArray::empty(),
3561 &ignored_rval);
3562}
3563
3564/**
3565 * ObjectInstance::new_for_gobject:

Callers 1

gjs_object_custom_initFunction · 0.80

Calls 1

gjs_throwFunction · 0.85

Tested by

no test coverage detected