Skip to content

Commit 2ed42d9

Browse files
Merge pull request #439 from Distributive-Network/philippe/fix-436
Fix method python method call without self
2 parents ee8a0f5 + 58dafa4 commit 2ed42d9

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/jsTypeFactory.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ bool callPyFunc(JSContext *cx, unsigned int argc, JS::Value *vp) {
382382
if (PyMethod_Check(pyFunc)) {
383383
f = PyMethod_Function(pyFunc); // borrowed reference
384384
nNormalArgs -= 1; // don't include the implicit `self` of the method as an argument
385-
}
385+
}
386386
PyCodeObject *bytecode = (PyCodeObject *)PyFunction_GetCode(f); // borrowed reference
387387
PyObject *defaults = PyFunction_GetDefaults(f); // borrowed reference
388388
nDefaultArgs = defaults ? PyTuple_Size(defaults) : 0;
@@ -393,7 +393,7 @@ bool callPyFunc(JSContext *cx, unsigned int argc, JS::Value *vp) {
393393
}
394394

395395
// use faster calling if no arguments are needed
396-
if (((nNormalArgs + nDefaultArgs) == 0 && !varargs)) {
396+
if (((nNormalArgs + nDefaultArgs) <= 0 && !varargs)) {
397397
#if PY_VERSION_HEX >= 0x03090000
398398
pyRval = PyObject_CallNoArgs(pyFunc);
399399
#else

tests/python/test_functions_this.py

+14
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,17 @@ def pyFunc():
202202
pm.collect() # this should collect the JS proxy to pyFunc, which should decref pyFunc
203203
# pyFunc should be collected by now
204204
assert ref[0]() is None
205+
206+
207+
def test_method_no_self():
208+
class What:
209+
def some_method():
210+
return 3
211+
212+
obj = What()
213+
214+
try:
215+
pm.eval('x => x.some_method()')(obj)
216+
assert (False)
217+
except pm.SpiderMonkeyError as e:
218+
assert 'takes 0 positional arguments but 1 was given' in str(e)

0 commit comments

Comments
 (0)