| 2100 | } |
| 2101 | |
| 2102 | bool PyListProxyHandler::defineProperty( |
| 2103 | JSContext *cx, JS::HandleObject proxy, JS::HandleId id, |
| 2104 | JS::Handle<JS::PropertyDescriptor> desc, JS::ObjectOpResult &result |
| 2105 | ) const { |
| 2106 | Py_ssize_t index; |
| 2107 | if (!idToIndex(cx, id, &index)) { // not an int-like property key |
| 2108 | return result.failBadIndex(); |
| 2109 | } |
| 2110 | |
| 2111 | if (desc.isAccessorDescriptor()) { // containing getter/setter |
| 2112 | return result.failNotDataDescriptor(); |
| 2113 | } |
| 2114 | if (!desc.hasValue()) { |
| 2115 | return result.failInvalidDescriptor(); |
| 2116 | } |
| 2117 | |
| 2118 | JS::RootedValue itemV(cx, desc.value()); |
| 2119 | PyObject *item = pyTypeFactory(cx, itemV); |
| 2120 | PyObject *self = JS::GetMaybePtrFromReservedSlot<PyObject>(proxy, PyObjectSlot); |
| 2121 | if (PyList_SetItem(self, index, item) < 0) { |
| 2122 | // we are out-of-bounds and need to expand |
| 2123 | Py_ssize_t len = PyList_GET_SIZE(self); |
| 2124 | // fill the space until the inserted index |
| 2125 | for (Py_ssize_t i = len; i < index; i++) { |
| 2126 | PyList_Append(self, Py_None); |
| 2127 | } |
| 2128 | |
| 2129 | PyList_Append(self, item); |
| 2130 | |
| 2131 | // clear pending exception |
| 2132 | PyErr_Clear(); |
| 2133 | } |
| 2134 | |
| 2135 | return result.succeed(); |
| 2136 | } |
| 2137 | |
| 2138 | bool PyListProxyHandler::ownPropertyKeys(JSContext *cx, JS::HandleObject proxy, JS::MutableHandleIdVector props) const { |
| 2139 | // Modified from https://hg.mozilla.org/releases/mozilla-esr102/file/3b574e1/dom/base/RemoteOuterWindowProxy.cpp#l137 |
no test coverage detected