summaryrefslogtreecommitdiff
path: root/gjs/jsapi-util-error.cpp
diff options
context:
space:
mode:
authorPhilip Chimento <philip.chimento@gmail.com>2017-06-10 18:13:23 -0700
committerPhilip Chimento <philip.chimento@gmail.com>2017-07-09 13:01:23 -0700
commit34c8449b90a96a39d0eb357fa057bf0f923a645f (patch)
tree603bf81738c0e78c4208a52fe5e4845fba89c05b /gjs/jsapi-util-error.cpp
parent751010e5e86710985422463033b3f2d26eeebe86 (diff)
downloadgjs-34c8449b90a96a39d0eb357fa057bf0f923a645f.tar.gz
js: Replace error reporter callbacks
JS_SetErrorReporter() goes away in SpiderMonkey 52, and is replaced by JS::SetWarningReporter(). Errors should now be reported manually after each call into JS code. (We don't actually have to change much, since we already used the DontReportUncaught option and reported uncaught exceptions manually already. This is now the only choice.) https://bugzilla.gnome.org/show_bug.cgi?id=784196
Diffstat (limited to 'gjs/jsapi-util-error.cpp')
-rw-r--r--gjs/jsapi-util-error.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/gjs/jsapi-util-error.cpp b/gjs/jsapi-util-error.cpp
index ce1bbd59..1196bd0e 100644
--- a/gjs/jsapi-util-error.cpp
+++ b/gjs/jsapi-util-error.cpp
@@ -202,3 +202,32 @@ gjs_throw_g_error (JSContext *context,
JS_EndRequest(context);
}
+
+/**
+ * gjs_format_stack_trace:
+ * @cx: the #JSContext
+ * @saved_frame: a SavedFrame #JSObject
+ *
+ * Formats a stack trace as a string in filename encoding, suitable for
+ * printing to stderr. Ignores any errors.
+ *
+ * Returns: unique string in filename encoding, or nullptr if no stack trace
+ */
+GjsAutoChar
+gjs_format_stack_trace(JSContext *cx,
+ JS::HandleObject saved_frame)
+{
+ JS::AutoSaveExceptionState saved_exc(cx);
+
+ JS::RootedString stack_trace(cx);
+ GjsAutoJSChar stack_utf8(cx);
+ if (JS::BuildStackString(cx, saved_frame, &stack_trace, 2))
+ stack_utf8.reset(cx, JS_EncodeStringToUTF8(cx, stack_trace));
+
+ saved_exc.restore();
+
+ if (!stack_utf8)
+ return nullptr;
+
+ return g_filename_from_utf8(stack_utf8, -1, nullptr, nullptr, nullptr);
+}