Skip to content
This repository has been archived by the owner on Apr 6, 2020. It is now read-only.

Commit

Permalink
Merge aa6f4ae into 67704c9
Browse files Browse the repository at this point in the history
  • Loading branch information
flaviut committed Aug 25, 2018
2 parents 67704c9 + aa6f4ae commit a5b3416
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/conversions.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,23 @@ static duk_ret_t python_function_caller(duk_context *ctx)
err_occured = PyErr_Occurred() != NULL;
get_repr(func, buf1, 200);
if (!err_occured) {
get_repr(func, buf1, 200);
if (gil_acquired) {
dctx->py_thread_state = PyEval_SaveThread();
gil_acquired = 0;
}
get_repr(func, buf1, 200);
duk_error(ctx, DUK_ERR_ERROR, "Function (%s) failed", buf1);
return duk_error(ctx, DUK_ERR_ERROR, "Function (%s) failed", buf1);
}
PyErr_Fetch(&ptype, &pval, &tb);
if (!get_repr(pval, buf2, 1024)) get_repr(ptype, buf2, 1024);
Py_XDECREF(ptype); Py_XDECREF(pval); Py_XDECREF(tb);
PyErr_Clear(); /* In case there was an error in get_repr() */
get_repr(func, buf1, 200);
if (gil_acquired) {
dctx->py_thread_state = PyEval_SaveThread();
gil_acquired = 0;
}
get_repr(func, buf1, 200);
duk_error(ctx, DUK_ERR_ERROR, "Function (%s) failed with error: %s", buf1, buf2);
return duk_error(ctx, DUK_ERR_ERROR, "Function (%s) failed with error: %s", buf1, buf2);

}
python_to_duk(ctx, result);
Expand Down
15 changes: 15 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@ def test_eval(self):
def test_eval_file(self):
pass

def test_pyfunc_success(self):
self.g.foo = lambda x: 213 + x
result = self.ctx.eval('foo(3)')
self.assertEqual(result, 213 + 3)

def test_pyfunc_exception(self):
def throw_exception():
raise ValueError('failure!')

self.g.throw_exception = throw_exception
with self.assertRaises(JSError) as err_ctx:
self.ctx.eval('throw_exception()')
self.assertIn("ValueError('failure!'",
err_ctx.exception.args[0]['message'])

def test_undefined(self):
self.assertEqual(repr(undefined), 'undefined')

Expand Down

0 comments on commit a5b3416

Please sign in to comment.