MCPcopy Create free account
hub / github.com/Distributive-Network/PythonMonkey / JSObjectProxy_pop_method

Method JSObjectProxy_pop_method

src/JSObjectProxy.cc:680–716  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

678}
679
680PyObject *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
693skip_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
718PyObject *JSObjectProxyMethodDefinitions::JSObjectProxy_clear_method(JSObjectProxy *self) {
719 JS::RootedIdVector props(GLOBAL_CX);

Callers

nothing calls this directly

Calls 4

_PyArg_CheckPositionalFunction · 0.85
keyToIdFunction · 0.85
PyErr_SetKeyErrorFunction · 0.85
pyTypeFactoryFunction · 0.85

Tested by

no test coverage detected