| 1492 | } |
| 1493 | |
| 1494 | bool ObjectPrototype::lazy_define_gobject_property( |
| 1495 | JSContext* cx, JS::HandleObject obj, JS::HandleId id, GParamSpec* pspec, |
| 1496 | bool* resolved, const char* name, |
| 1497 | const Maybe<const GI::AutoPropertyInfo>& property_info) { |
| 1498 | JS::RootedId canonical_id{cx}; |
| 1499 | JS::Rooted<JS::PropertyDescriptor> canonical_desc{cx}; |
| 1500 | |
| 1501 | // Make property configurable so that interface properties can be |
| 1502 | // overridden by GObject.ParamSpec.override in the class that |
| 1503 | // implements them |
| 1504 | unsigned flags = GJS_MODULE_PROP_FLAGS & ~JSPROP_PERMANENT; |
| 1505 | |
| 1506 | if (!g_str_equal(pspec->name, name)) { |
| 1507 | canonical_id = gjs_intern_string_to_id(cx, pspec->name); |
| 1508 | |
| 1509 | JS::Rooted<mozilla::Maybe<JS::PropertyDescriptor>> desc{cx}; |
| 1510 | if (!JS_GetOwnPropertyDescriptorById(cx, obj, canonical_id, &desc)) |
| 1511 | return false; |
| 1512 | |
| 1513 | if (desc.isSome()) { |
| 1514 | debug_jsprop("Defining alias GObject property", id, obj); |
| 1515 | canonical_desc = *desc; |
| 1516 | if (!JS_DefinePropertyById(cx, obj, id, canonical_desc)) |
| 1517 | return false; |
| 1518 | |
| 1519 | *resolved = true; |
| 1520 | return true; |
| 1521 | } |
| 1522 | } |
| 1523 | |
| 1524 | debug_jsprop("Defining lazy GObject property", id, obj); |
| 1525 | |
| 1526 | if (!(pspec->flags & (G_PARAM_WRITABLE | G_PARAM_READABLE))) { |
| 1527 | if (!JS_DefinePropertyById(cx, obj, id, JS::UndefinedHandleValue, |
| 1528 | flags)) |
| 1529 | return false; |
| 1530 | |
| 1531 | if (!canonical_id.isVoid() && |
| 1532 | !JS_DefinePropertyById(cx, obj, canonical_id, |
| 1533 | JS::UndefinedHandleValue, flags)) |
| 1534 | return false; |
| 1535 | |
| 1536 | *resolved = true; |
| 1537 | return true; |
| 1538 | } |
| 1539 | |
| 1540 | // Do not fetch JS overridden properties from GObject, to avoid |
| 1541 | // infinite recursion. |
| 1542 | if (g_param_spec_get_qdata(pspec, ObjectBase::custom_property_quark())) { |
| 1543 | *resolved = false; |
| 1544 | return true; |
| 1545 | } |
| 1546 | |
| 1547 | JS::RootedValue getter_priv{cx}; |
| 1548 | JSNative js_getter = |
| 1549 | get_getter_for_property(cx, pspec, property_info, &getter_priv); |
| 1550 | if (!js_getter) |
| 1551 | return false; |
nothing calls this directly
no test coverage detected