summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorGiovanni Campagna <gcampagna@src.gnome.org>2012-08-26 00:23:24 +0200
committerPhilip Chimento <philip.chimento@gmail.com>2017-09-18 20:14:08 -0700
commitc3e4ae6eef0e3615b5ba8903c6b1cd4bbf7c4eae (patch)
treee88fc1a9199d697a63f601e6828a5bbb6e6a88d0 /util
parentd3f810ad291ac812ecdec8c5154194a405a5090d (diff)
downloadgjs-c3e4ae6eef0e3615b5ba8903c6b1cd4bbf7c4eae.tar.gz
Add marshalling for native JS errors
Introduce a GError domain for representing native JS errors (such as TypeError or ReferenceError) throw by JS code, to be reported to calling C code. Introduce also a way to retrieve something similar to the original C error from this GError, in case it comes through a called C function unmodified. https://bugzilla.gnome.org/show_bug.cgi?id=682701
Diffstat (limited to 'util')
-rw-r--r--util/error.cpp34
-rw-r--r--util/error.h22
2 files changed, 55 insertions, 1 deletions
diff --git a/util/error.cpp b/util/error.cpp
index 8c8b5868..b653b089 100644
--- a/util/error.cpp
+++ b/util/error.cpp
@@ -22,6 +22,9 @@
*/
#include <config.h>
+
+#include <glib-object.h>
+
#include "error.h"
GQuark
@@ -29,3 +32,34 @@ gjs_error_quark (void)
{
return g_quark_from_static_string ("gjs-error-quark");
}
+
+GQuark
+gjs_js_error_quark(void)
+{
+ return g_quark_from_static_string("gjs-js-error-quark");
+}
+
+GType
+gjs_js_error_get_type(void)
+{
+ static volatile GType g_type_id;
+
+ if (g_once_init_enter(&g_type_id)) {
+ static GEnumValue errors[] = {
+ { GJS_JS_ERROR_ERROR, "Error", "error" },
+ { GJS_JS_ERROR_EVAL_ERROR, "EvalError", "eval-error" },
+ { GJS_JS_ERROR_INTERNAL_ERROR, "InternalError", "internal-error" },
+ { GJS_JS_ERROR_RANGE_ERROR, "RangeError", "range-error" },
+ { GJS_JS_ERROR_REFERENCE_ERROR, "ReferenceError", "reference-error" },
+ { GJS_JS_ERROR_STOP_ITERATION, "StopIteration", "stop-iteration" },
+ { GJS_JS_ERROR_SYNTAX_ERROR, "SyntaxError", "syntax-error" },
+ { GJS_JS_ERROR_TYPE_ERROR, "TypeError", "type-error" },
+ { GJS_JS_ERROR_URI_ERROR, "URIError", "uri-error" },
+ { 0, nullptr, nullptr }
+ };
+
+ g_type_id = g_enum_register_static("GjsJSError", errors);
+ }
+
+ return g_type_id;
+}
diff --git a/util/error.h b/util/error.h
index 08a3128c..9f97eb5b 100644
--- a/util/error.h
+++ b/util/error.h
@@ -24,7 +24,7 @@
#ifndef __GJS_UTIL_ERROR_H__
#define __GJS_UTIL_ERROR_H__
-#include <glib.h>
+#include <glib-object.h>
#include <gjs/macros.h>
@@ -39,6 +39,26 @@ typedef enum {
GJS_ERROR_SYSTEM_EXIT,
} GjsError;
+GJS_EXPORT
+GQuark gjs_js_error_quark(void);
+#define GJS_JS_ERROR gjs_js_error_quark()
+
+GJS_EXPORT
+GType gjs_js_error_get_type(void);
+#define GJS_TYPE_JS_ERROR gjs_js_error_get_type()
+
+typedef enum {
+ GJS_JS_ERROR_ERROR,
+ GJS_JS_ERROR_EVAL_ERROR,
+ GJS_JS_ERROR_INTERNAL_ERROR,
+ GJS_JS_ERROR_RANGE_ERROR,
+ GJS_JS_ERROR_REFERENCE_ERROR,
+ GJS_JS_ERROR_STOP_ITERATION,
+ GJS_JS_ERROR_SYNTAX_ERROR,
+ GJS_JS_ERROR_TYPE_ERROR,
+ GJS_JS_ERROR_URI_ERROR,
+} GjsJSError;
+
G_END_DECLS
#endif /* __GJS_UTIL_ERROR_H__ */