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

Method constructor_impl

gi/gerror.cpp:74–99  ·  view source on GitHub ↗

See GIWrapperBase::constructor().

Source from the content-addressed store, hash-verified

72
73// See GIWrapperBase::constructor().
74bool ErrorInstance::constructor_impl(JSContext* cx, JS::HandleObject object,
75 const JS::CallArgs& args) {
76 if (args.length() != 1 || !args[0].isObject()) {
77 gjs_throw(cx,
78 "Invalid parameters passed to GError constructor, expected "
79 "one object");
80 return false;
81 }
82
83 JS::RootedObject params_obj{cx, &args[0].toObject()};
84 JS::UniqueChars message;
85 const GjsAtoms& atoms = GjsContextPrivate::atoms(cx);
86 if (!gjs_object_require_property(cx, params_obj, "GError constructor",
87 atoms.message(), &message))
88 return false;
89
90 int32_t code;
91 if (!gjs_object_require_property(cx, params_obj, "GError constructor",
92 atoms.code(), &code))
93 return false;
94
95 m_ptr = g_error_new_literal(domain(), code, message.get());
96
97 // We assume this error will be thrown in the same line as the constructor
98 return gjs_define_error_properties(cx, object);
99}
100
101/**
102 * ErrorBase::get_domain:

Callers

nothing calls this directly

Calls 8

gjs_throwFunction · 0.85
domainFunction · 0.85
lengthMethod · 0.80
codeMethod · 0.80
messageMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected