| 678 | } |
| 679 | |
| 680 | PyObject *JSObjectProxyMethodDefinitions::JSObjectProxy_pop_method(JSObjectProxy *self, PyObject *const *args, Py_ssize_t nargs) { |
| 681 | PyObject *key; |
| 682 | PyObject *default_value = NULL; |
| 683 | |
| 684 | if (!_PyArg_CheckPositional("pop", nargs, 1, 2)) { |
| 685 | return NULL; |
| 686 | } |
| 687 | key = args[0]; |
| 688 | if (nargs < 2) { |
| 689 | goto skip_optional; |
| 690 | } |
| 691 | default_value = args[1]; |
| 692 | |
| 693 | skip_optional: |
| 694 | JS::RootedId id(GLOBAL_CX); |
| 695 | if (!keyToId(key, &id)) { |
| 696 | PyErr_SetString(PyExc_AttributeError, "JSObjectProxy property name must be of type str or int"); |
| 697 | return NULL; |
| 698 | } |
| 699 | |
| 700 | JS::RootedValue value(GLOBAL_CX); |
| 701 | JS_GetPropertyById(GLOBAL_CX, *(self->jsObject), id, &value); |
| 702 | if (value.isUndefined()) { |
| 703 | if (default_value != NULL) { |
| 704 | Py_INCREF(default_value); |
| 705 | return default_value; |
| 706 | } |
| 707 | PyErr_SetKeyError(key); |
| 708 | return NULL; |
| 709 | } |
| 710 | else { |
| 711 | JS::ObjectOpResult ignoredResult; |
| 712 | JS_DeletePropertyById(GLOBAL_CX, *(self->jsObject), id, ignoredResult); |
| 713 | |
| 714 | return pyTypeFactory(GLOBAL_CX, value); |
| 715 | } |
| 716 | } |
| 717 | |
| 718 | PyObject *JSObjectProxyMethodDefinitions::JSObjectProxy_clear_method(JSObjectProxy *self) { |
| 719 | JS::RootedIdVector props(GLOBAL_CX); |
nothing calls this directly
no test coverage detected