summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Chimento <philip.chimento@gmail.com>2017-04-04 00:40:34 -0700
committerPhilip Chimento <philip.chimento@gmail.com>2017-04-17 21:41:11 -0700
commit56e8665408c617963d42485b5335151cc37e717b (patch)
tree697a08ef847d71221d3f505d2715c1acebea8835
parent93a13dc8b12bac8a7d2daa0415a7aaeaa63512cb (diff)
downloadgjs-56e8665408c617963d42485b5335151cc37e717b.tar.gz
context: Use JS::AutoSaveExceptionState
JS_SaveExceptionState() seems to be broken in SpiderMonkey 45, but in any case we can work around it by using the more modern RAII version. Since we are using JS::RootedString here we can also get rid of the trick of stuffing the string into one of the JS::CallArgs' slots to root it. https://bugzilla.gnome.org/show_bug.cgi?id=781429
-rw-r--r--gjs/context.cpp24
1 files changed, 6 insertions, 18 deletions
diff --git a/gjs/context.cpp b/gjs/context.cpp
index d7b06d74..1d77a398 100644
--- a/gjs/context.cpp
+++ b/gjs/context.cpp
@@ -120,7 +120,6 @@ gjs_log(JSContext *context,
{
JS::CallArgs argv = JS::CallArgsFromVp (argc, vp);
char *s;
- JSExceptionState *exc_state;
if (argc != 1) {
gjs_throw(context, "Must pass a single argument to log()");
@@ -131,11 +130,9 @@ gjs_log(JSContext *context,
/* JS::ToString might throw, in which case we will only log that the value
* could not be converted to string */
- exc_state = JS_SaveExceptionState(context);
+ JS::AutoSaveExceptionState exc_state(context);
JS::RootedString jstr(context, JS::ToString(context, argv[0]));
- if (jstr != NULL)
- argv[0].setString(jstr); // GC root
- JS_RestoreExceptionState(context, exc_state);
+ exc_state.restore();
if (jstr == NULL) {
g_message("JS LOG: <cannot convert value to string>");
@@ -162,7 +159,6 @@ gjs_log_error(JSContext *context,
JS::Value *vp)
{
JS::CallArgs argv = JS::CallArgsFromVp (argc, vp);
- JSExceptionState *exc_state;
if ((argc != 1 && argc != 2) || !argv[0].isObject()) {
gjs_throw(context, "Must pass an exception and optionally a message to logError()");
@@ -176,11 +172,9 @@ gjs_log_error(JSContext *context,
if (argc == 2) {
/* JS::ToString might throw, in which case we will only log that the
* value could be converted to string */
- exc_state = JS_SaveExceptionState(context);
+ JS::AutoSaveExceptionState exc_state(context);
jstr = JS::ToString(context, argv[1]);
- if (jstr != NULL)
- argv[1].setString(jstr); // GC root
- JS_RestoreExceptionState(context, exc_state);
+ exc_state.restore();
}
gjs_log_exception_full(context, argv[0], jstr);
@@ -203,17 +197,11 @@ gjs_print_parse_args(JSContext *context,
str = g_string_new("");
for (n = 0; n < argv.length(); ++n) {
- JSExceptionState *exc_state;
-
/* JS::ToString might throw, in which case we will only log that the
* value could not be converted to string */
- exc_state = JS_SaveExceptionState(context);
-
+ JS::AutoSaveExceptionState exc_state(context);
JS::RootedString jstr(context, JS::ToString(context, argv[n]));
- if (jstr != NULL)
- argv[n].setString(jstr); // GC root
-
- JS_RestoreExceptionState(context, exc_state);
+ exc_state.restore();
if (jstr != NULL) {
if (!gjs_string_to_utf8(context, JS::StringValue(jstr), &s)) {