| 264 | } |
| 265 | |
| 266 | int JSArrayProxyMethodDefinitions::JSArrayProxy_assign_key(JSArrayProxy *self, PyObject *key, PyObject *value) |
| 267 | { |
| 268 | if (PyIndex_Check(key)) { |
| 269 | Py_ssize_t index = PyNumber_AsSsize_t(key, PyExc_IndexError); |
| 270 | if (index == -1 && PyErr_Occurred()) { |
| 271 | return -1; |
| 272 | } |
| 273 | |
| 274 | Py_ssize_t selfLength = JSArrayProxy_length(self); |
| 275 | |
| 276 | if (index < 0) { |
| 277 | index += selfLength; |
| 278 | } |
| 279 | |
| 280 | if ((size_t)index >= (size_t)selfLength) { |
| 281 | PyErr_SetObject(PyExc_IndexError, PyUnicode_FromString("list assignment index out of range")); |
| 282 | return -1; |
| 283 | } |
| 284 | |
| 285 | JS::RootedId id(GLOBAL_CX); |
| 286 | JS_IndexToId(GLOBAL_CX, index, &id); |
| 287 | |
| 288 | if (value) { // we are setting a value |
| 289 | JS::RootedValue jValue(GLOBAL_CX, jsTypeFactory(GLOBAL_CX, value)); |
| 290 | JS_SetPropertyById(GLOBAL_CX, *(self->jsArray), id, jValue); |
| 291 | } else { // we are deleting a value |
| 292 | JS::ObjectOpResult ignoredResult; |
| 293 | JS_DeletePropertyById(GLOBAL_CX, *(self->jsArray), id, ignoredResult); |
| 294 | } |
| 295 | |
| 296 | return 0; |
| 297 | } |
| 298 | else if (PySlice_Check(key)) { |
| 299 | Py_ssize_t start, stop, step, slicelength; |
| 300 | |
| 301 | if (PySlice_Unpack(key, &start, &stop, &step) < 0) { |
| 302 | return -1; |
| 303 | } |
| 304 | |
| 305 | Py_ssize_t selfSize = JSArrayProxy_length(self); |
| 306 | |
| 307 | slicelength = PySlice_AdjustIndices(selfSize, &start, &stop, step); |
| 308 | |
| 309 | if (step == 1) { |
| 310 | return list_ass_slice(self, start, stop, value); |
| 311 | } |
| 312 | |
| 313 | /* Make sure s[5:2] = [..] inserts at the right place: |
| 314 | before 5, not before 2. */ |
| 315 | if ((step < 0 && start < stop) || (step > 0 && start > stop)) { |
| 316 | stop = start; |
| 317 | } |
| 318 | |
| 319 | if (value == NULL) { |
| 320 | /* delete slice */ |
| 321 | size_t cur; |
| 322 | Py_ssize_t i; |
| 323 |
nothing calls this directly
no test coverage detected