See GIWrapperBase::constructor().
| 72 | |
| 73 | // See GIWrapperBase::constructor(). |
| 74 | bool 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: |
nothing calls this directly
no test coverage detected