| 16 | #include "test/gjs-test-common.h" |
| 17 | |
| 18 | char* gjs_test_get_exception_message(JSContext* cx) { |
| 19 | if (!JS_IsExceptionPending(cx)) |
| 20 | return nullptr; |
| 21 | |
| 22 | JS::RootedValue v_exc(cx); |
| 23 | g_assert_true(JS_GetPendingException(cx, &v_exc)); |
| 24 | g_assert_true(v_exc.isObject()); |
| 25 | |
| 26 | JS::RootedObject exc(cx, &v_exc.toObject()); |
| 27 | JSErrorReport* report = JS_ErrorFromException(cx, exc); |
| 28 | g_assert_nonnull(report); |
| 29 | |
| 30 | char* retval = g_strdup(report->message().c_str()); |
| 31 | g_assert_nonnull(retval); |
| 32 | JS_ClearPendingException(cx); |
| 33 | return retval; |
| 34 | } |
no test coverage detected