duktape: Fix error in js function called via proxy causing abort

This commit is contained in:
Kovid Goyal 2015-06-26 20:57:25 +05:30
parent 4cd3bc037f
commit 0d30acf9ee
2 changed files with 22 additions and 5 deletions

View File

@ -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

View File

@ -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):