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

Method JSObjectProxy_or

src/JSObjectProxy.cc:548–588  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

546}
547
548PyObject *JSObjectProxyMethodDefinitions::JSObjectProxy_or(JSObjectProxy *self, PyObject *other) {
549 #if PY_VERSION_HEX < 0x03090000
550 // | is not supported on dicts in python3.8 or less, so only allow if both
551 // operands are JSObjectProxy
552 if (!PyObject_TypeCheck(self, &JSObjectProxyType) || !PyObject_TypeCheck(other, &JSObjectProxyType)) {
553 Py_RETURN_NOTIMPLEMENTED;
554 }
555 #endif
556 if (!PyDict_Check(self) || !PyDict_Check(other)) {
557 Py_RETURN_NOTIMPLEMENTED;
558 }
559
560 if (!PyObject_TypeCheck(self, &JSObjectProxyType) && PyObject_TypeCheck(other, &JSObjectProxyType)) {
561 return PyDict_Type.tp_as_number->nb_or((PyObject *)&(self->dict), other);
562 }
563 else {
564 JS::Rooted<JS::ValueArray<3>> args(GLOBAL_CX);
565 args[0].setObjectOrNull(JS_NewPlainObject(GLOBAL_CX));
566 args[1].setObjectOrNull(*(self->jsObject)); // this is null is left operand is real dict
567 JS::RootedValue jValueOther(GLOBAL_CX, jsTypeFactory(GLOBAL_CX, other));
568 args[2].setObject(jValueOther.toObject());
569
570 JS::RootedObject global(GLOBAL_CX, JS::GetNonCCWObjectGlobal(*(self->jsObject)));
571
572 // call Object.assign
573 JS::RootedValue Object(GLOBAL_CX);
574 if (!JS_GetProperty(GLOBAL_CX, global, "Object", &Object)) {
575 PyErr_Format(PyExc_SystemError, "%s JSAPI call failed", JSObjectProxyType.tp_name);
576 return NULL;
577 }
578
579 JS::RootedObject rootedObject(GLOBAL_CX, Object.toObjectOrNull());
580 JS::RootedValue ret(GLOBAL_CX);
581
582 if (!JS_CallFunctionName(GLOBAL_CX, rootedObject, "assign", args, &ret)) {
583 PyErr_Format(PyExc_SystemError, "%s JSAPI call failed", JSObjectProxyType.tp_name);
584 return NULL;
585 }
586 return pyTypeFactory(GLOBAL_CX, ret);
587 }
588}
589
590PyObject *JSObjectProxyMethodDefinitions::JSObjectProxy_ior(JSObjectProxy *self, PyObject *other) {
591 if (PyDict_Check(other)) {

Callers

nothing calls this directly

Calls 2

jsTypeFactoryFunction · 0.85
pyTypeFactoryFunction · 0.85

Tested by

no test coverage detected