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

Method constructor_impl

gi/object.cpp:2721–2745  ·  view source on GitHub ↗

See GIWrapperBase::constructor()

Source from the content-addressed store, hash-verified

2719
2720// See GIWrapperBase::constructor()
2721bool ObjectInstance::constructor_impl(JSContext* cx, JS::HandleObject object,
2722 const JS::CallArgs& args) {
2723 JS::RootedValue initer{cx};
2724 GjsContextPrivate* gjs = GjsContextPrivate::from_cx(cx);
2725 const JS::MutableHandleValue& new_target = args.newTarget();
2726 bool has_gtype;
2727
2728 g_assert(new_target.isObject() && "new.target needs to be an object");
2729 JS::RootedObject rooted_target{cx, &new_target.toObject()};
2730 if (!JS_HasOwnPropertyById(cx, rooted_target, gjs->atoms().gtype(),
2731 &has_gtype))
2732 return false;
2733
2734 if (!has_gtype) {
2735 gjs_throw(cx,
2736 "Tried to construct an object without a GType; are "
2737 "you using GObject.registerClass() when inheriting "
2738 "from a GObject type?");
2739 return false;
2740 }
2741
2742 return gjs_object_require_property(cx, object, "GObject instance",
2743 gjs->atoms().init(), &initer) &&
2744 gjs->call_function(object, initer, args, args.rval());
2745}
2746
2747void ObjectInstance::trace_impl(JSTracer* tracer) {
2748 for (GClosure* closure : m_closures)

Callers

nothing calls this directly

Calls 5

gjs_throwFunction · 0.85
call_functionMethod · 0.80
gtypeMethod · 0.45
initMethod · 0.45

Tested by

no test coverage detected