Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions include/JSObjectProxy.hh
Original file line number Diff line number Diff line change
Expand Up @@ -129,24 +129,6 @@ public:
* @return the string representation (a PyUnicodeObject) on success, NULL on failure
*/
static PyObject *JSObjectProxy_repr(JSObjectProxy *self);

/**
* @brief Set union method
*
* @param self - The JSObjectProxy
* @param other - The other PyObject to be or'd, expected to be dict or JSObjectProxy
* @return PyObject* The resulting new dict
*/
static PyObject *JSObjectProxy_or(JSObjectProxy *self, PyObject *other);

/**
* @brief Set union method, in place
*
* @param self - The JSObjectProxy
* @param other - The other PyObject to be or'd, expected to be dict or JSObjectProxy
* @return PyObject* The resulting new dict, must be same object as self
*/
static PyObject *JSObjectProxy_ior(JSObjectProxy *self, PyObject *other);
};


Expand All @@ -164,11 +146,6 @@ static PySequenceMethods JSObjectProxy_sequence_methods = {
.sq_contains = (objobjproc)JSObjectProxyMethodDefinitions::JSObjectProxy_contains
};

static PyNumberMethods JSObjectProxy_number_methods = {
.nb_or = (binaryfunc)JSObjectProxyMethodDefinitions::JSObjectProxy_or,
.nb_inplace_or = (binaryfunc)JSObjectProxyMethodDefinitions::JSObjectProxy_ior
};

/**
* @brief Struct for the JSObjectProxyType, used by all JSObjectProxy objects
*/
Expand Down
53 changes: 0 additions & 53 deletions src/JSObjectProxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

#include <Python.h>

#include <object.h>

JSContext *GLOBAL_CX; /**< pointer to PythonMonkey's JSContext */

bool keyToId(PyObject *key, JS::MutableHandleId idp) {
Expand Down Expand Up @@ -260,54 +258,3 @@ PyObject *JSObjectProxyMethodDefinitions::JSObjectProxy_repr(JSObjectProxy *self
PyDict_DelItem(tsDict, cyclicKey);
return str;
}

PyObject *JSObjectProxyMethodDefinitions::JSObjectProxy_or(JSObjectProxy *self, PyObject *other) {
if (!PyDict_Check(self) || !PyDict_Check(other)) {
Py_RETURN_NOTIMPLEMENTED;
}

if (!PyObject_TypeCheck(self, &JSObjectProxyType) && PyObject_TypeCheck(other, &JSObjectProxyType)) {
return PyDict_Type.tp_as_number->nb_or((PyObject *)&(self->dict), other);
} else {
JS::Rooted<JS::ValueArray<3>> args(GLOBAL_CX);
args[0].setObjectOrNull(JS_NewPlainObject(GLOBAL_CX));
args[1].setObjectOrNull(self->jsObject); // this is null is left operand is real dict
JS::RootedValue jValueOther(GLOBAL_CX, jsTypeFactory(GLOBAL_CX, other));
args[2].setObject(jValueOther.toObject());

JS::RootedObject *global = new JS::RootedObject(GLOBAL_CX, JS::GetNonCCWObjectGlobal(self->jsObject));

// call Object.assign
JS::RootedValue Object(GLOBAL_CX);
JS_GetProperty(GLOBAL_CX, *global, "Object", &Object);

JS::RootedObject rootedObject(GLOBAL_CX, Object.toObjectOrNull());
JS::RootedValue ret(GLOBAL_CX);

if (!JS_CallFunctionName(GLOBAL_CX, rootedObject, "assign", args, &ret)) return NULL;
return pyTypeFactory(GLOBAL_CX, global, &ret)->getPyObject();
}
}

PyObject *JSObjectProxyMethodDefinitions::JSObjectProxy_ior(JSObjectProxy *self, PyObject *other) {
if (!PyDict_Check(self) || !PyDict_Check(other)) {
Py_RETURN_NOTIMPLEMENTED;
}

JS::Rooted<JS::ValueArray<2>> args(GLOBAL_CX);
args[0].setObjectOrNull(self->jsObject);
JS::RootedValue jValueOther(GLOBAL_CX, jsTypeFactory(GLOBAL_CX, other));
args[1].setObject(jValueOther.toObject());

JS::RootedObject *global = new JS::RootedObject(GLOBAL_CX, JS::GetNonCCWObjectGlobal(self->jsObject));

// call Object.assign
JS::RootedValue Object(GLOBAL_CX);
JS_GetProperty(GLOBAL_CX, *global, "Object", &Object);

JS::RootedObject rootedObject(GLOBAL_CX, Object.toObjectOrNull());
JS::RootedValue ret(GLOBAL_CX);
if (!JS_CallFunctionName(GLOBAL_CX, rootedObject, "assign", args, &ret)) return NULL;
Py_INCREF(self);
return (PyObject *)self;
}
1 change: 0 additions & 1 deletion src/modules/pythonmonkey/pythonmonkey.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ PyTypeObject JSObjectProxyType = {
.tp_basicsize = sizeof(JSObjectProxy),
.tp_dealloc = (destructor)JSObjectProxyMethodDefinitions::JSObjectProxy_dealloc,
.tp_repr = (reprfunc)JSObjectProxyMethodDefinitions::JSObjectProxy_repr,
.tp_as_number = &JSObjectProxy_number_methods,
.tp_as_sequence = &JSObjectProxy_sequence_methods,
.tp_as_mapping = &JSObjectProxy_mapping_methods,
.tp_getattro = (getattrofunc)JSObjectProxyMethodDefinitions::JSObjectProxy_get,
Expand Down
47 changes: 1 addition & 46 deletions tests/python/test_dicts_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,49 +137,4 @@ def test_eval_objects_jsproxy_does_not_contain():

def test_eval_objects_jsproxy_does_not_contain_value():
a = pm.eval("({'c':5})")
assert not(5 in a)

def test_eval_objects_jsproxy_or():
a = pm.eval("({'c':5})")
b = pm.eval("({'d':6})")
c = a | b
assert a == {'c': 5.0}
assert c == {'c': 5.0, 'd': 6.0}
assert b == {'d': 6.0}

def test_eval_objects_jsproxy_or_true_dict_right():
a = pm.eval("({'c':5})")
b = {'d': 6.0}
c = a | b
assert a == {'c': 5.0}
assert c == {'c': 5.0, 'd': 6.0}
assert b == {'d': 6.0}

def test_eval_objects_jsproxy_or_true_dict_left():
a = {'c':5}
b = pm.eval("({'d':6})")
c = a | b
assert a == {'c': 5.0}
assert c == {'c': 5.0, 'd': 6.0}
assert b == {'d': 6.0}

def test_eval_objects_jsproxy_inplace_or():
a = pm.eval("({'c':5})")
b = pm.eval("({'d':6})")
a |= b
assert a == {'c': 5.0, 'd': 6.0}
assert b == {'d': 6.0}

def test_eval_objects_jsproxy_inplace_or_true_dict_right():
a = pm.eval("({'c':5})")
b = {'d':6.0}
a |= b
assert a == {'c': 5.0, 'd': 6.0}
assert b == {'d': 6.0}

def test_eval_objects_jsproxy_inplace_or_true_dict_left():
a = {'c':5.0}
b = pm.eval("({'d':6})")
a |= b
assert a == {'c': 5.0, 'd': 6.0}
assert b == {'d': 6.0}
assert not(5 in a)