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

Method JSObjectProxy_setdefault_method

src/JSObjectProxy.cc:648–678  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

646}
647
648PyObject *JSObjectProxyMethodDefinitions::JSObjectProxy_setdefault_method(JSObjectProxy *self, PyObject *const *args, Py_ssize_t nargs) {
649 PyObject *key;
650 PyObject *default_value = Py_None;
651
652 if (!_PyArg_CheckPositional("setdefault", nargs, 1, 2)) {
653 return NULL;
654 }
655 key = args[0];
656 if (nargs < 2) {
657 goto skip_optional;
658 }
659
660 default_value = args[1];
661
662skip_optional:
663
664 JS::RootedId id(GLOBAL_CX);
665 if (!keyToId(key, &id)) { // invalid key
666 // TODO (Caleb Aikens): raise exception here
667 return NULL;
668 }
669
670 PyObject *value = getKey(self, key, id, true);
671 if (value == Py_None) {
672 assignKeyValue(self, key, id, default_value);
673 Py_XINCREF(default_value);
674 return default_value;
675 }
676
677 return value;
678}
679
680PyObject *JSObjectProxyMethodDefinitions::JSObjectProxy_pop_method(JSObjectProxy *self, PyObject *const *args, Py_ssize_t nargs) {
681 PyObject *key;

Callers

nothing calls this directly

Calls 4

_PyArg_CheckPositionalFunction · 0.85
keyToIdFunction · 0.85
getKeyFunction · 0.85
assignKeyValueFunction · 0.85

Tested by

no test coverage detected