diff --git a/src/duktape/proxy.c b/src/duktape/proxy.c index 4d24e3710d..070cec10cb 100644 --- a/src/duktape/proxy.c +++ b/src/duktape/proxy.c @@ -396,14 +396,13 @@ PyObject* DukFunction_call(DukObject *self, PyObject *args, PyObject *kw) { duk_context *ctx = self->context->ctx; Py_ssize_t nargs, i; - int return_none = 0; - PyObject *result; + int return_none = 0, ret = 0; + PyObject *result, *temp; /* NULL if no parent */ PyObject *this = (PyObject *)self->parent; if (kw) { - PyObject *temp; temp = PyDict_GetItemString(kw, "this"); if (temp) @@ -435,9 +434,19 @@ PyObject* DukFunction_call(DukObject *self, PyObject *args, PyObject *kw) } if (this) - duk_call_method(ctx, (duk_idx_t)nargs); + ret = duk_pcall_method(ctx, (duk_idx_t)nargs); else - duk_call(ctx, (duk_idx_t)nargs); + ret = duk_pcall(ctx, (duk_idx_t)nargs); + + if (ret != DUK_EXEC_SUCCESS) { + temp = duk_to_python(ctx, -1); + duk_pop(ctx); + if (temp) { + PyErr_SetObject(JSError, temp); + Py_DECREF(temp); + } else PyErr_SetString(PyExc_RuntimeError, "The was an error during call(), but the error could not be read of the stack"); + return NULL; + } if (return_none) { /* Always return None. This saves converting the function's diff --git a/src/duktape/tests.py b/src/duktape/tests.py index 8f12b84909..bbc11e4a90 100644 --- a/src/duktape/tests.py +++ b/src/duktape/tests.py @@ -106,6 +106,14 @@ class ValueTests(unittest.TestCase): self.g.obj1 = {'a': 42} self.g.obj2 = self.g.obj1 self.assertEqual(self.g.obj1.a, self.g.obj2.a) + self.ctx.eval('function f() {nonexistent()}') + try: + self.g.f() + self.assert_('No error raised for bad function') + except JSError as e: + e = e.args[0] + self.assertEqual('ReferenceError', e.name) + self.assertIn('nonexistent', e.toString()) class EvalTests(unittest.TestCase):