diff --git a/src/jsTypeFactory.cc b/src/jsTypeFactory.cc index 60834188..3e4f89d3 100644 --- a/src/jsTypeFactory.cc +++ b/src/jsTypeFactory.cc @@ -382,7 +382,7 @@ bool callPyFunc(JSContext *cx, unsigned int argc, JS::Value *vp) { if (PyMethod_Check(pyFunc)) { f = PyMethod_Function(pyFunc); // borrowed reference nNormalArgs -= 1; // don't include the implicit `self` of the method as an argument - } + } PyCodeObject *bytecode = (PyCodeObject *)PyFunction_GetCode(f); // borrowed reference PyObject *defaults = PyFunction_GetDefaults(f); // borrowed reference nDefaultArgs = defaults ? PyTuple_Size(defaults) : 0; @@ -393,7 +393,7 @@ bool callPyFunc(JSContext *cx, unsigned int argc, JS::Value *vp) { } // use faster calling if no arguments are needed - if (((nNormalArgs + nDefaultArgs) == 0 && !varargs)) { + if (((nNormalArgs + nDefaultArgs) <= 0 && !varargs)) { #if PY_VERSION_HEX >= 0x03090000 pyRval = PyObject_CallNoArgs(pyFunc); #else diff --git a/tests/python/test_functions_this.py b/tests/python/test_functions_this.py index dc20f416..d9cbf528 100644 --- a/tests/python/test_functions_this.py +++ b/tests/python/test_functions_this.py @@ -202,3 +202,17 @@ def pyFunc(): pm.collect() # this should collect the JS proxy to pyFunc, which should decref pyFunc # pyFunc should be collected by now assert ref[0]() is None + + +def test_method_no_self(): + class What: + def some_method(): + return 3 + + obj = What() + + try: + pm.eval('x => x.some_method()')(obj) + assert (False) + except pm.SpiderMonkeyError as e: + assert 'takes 0 positional arguments but 1 was given' in str(e) \ No newline at end of file