[gjs/wip/ptomato/mozjs31: 15/17] js: Remove deprecated JS_ValueToString()



commit 91da5b9ed4623525e76b56c59c539c4ae9b4e71f
Author: Philip Chimento <philip endlessm com>
Date:   Tue Oct 18 13:52:52 2016 -0700

    js: Remove deprecated JS_ValueToString()
    
    In mozjs31 this is replaced with JS::ToString().

 gi/arg.cpp          |    2 +-
 gjs/context.cpp     |   31 ++++++++++++++-----------------
 gjs/coverage.cpp    |    9 ++++-----
 gjs/jsapi-util.cpp  |    5 ++---
 modules/console.cpp |    6 +++---
 5 files changed, 24 insertions(+), 29 deletions(-)
---
diff --git a/gi/arg.cpp b/gi/arg.cpp
index 831ae9b..12c5bbf 100644
--- a/gi/arg.cpp
+++ b/gi/arg.cpp
@@ -2418,7 +2418,7 @@ gjs_object_from_g_hash (JSContext             *context,
                                        true))
             goto out;
 
-        keystr = JS_ValueToString(context, keyjs);
+        keystr = JS::ToString(context, keyjs);
         if (!keystr)
             goto out;
 
diff --git a/gjs/context.cpp b/gjs/context.cpp
index 434367d..70c4b7a 100644
--- a/gjs/context.cpp
+++ b/gjs/context.cpp
@@ -110,7 +110,6 @@ gjs_log(JSContext *context,
     JS::CallArgs argv = JS::CallArgsFromVp (argc, vp);
     char *s;
     JSExceptionState *exc_state;
-    JSString *jstr;
 
     if (argc != 1) {
         gjs_throw(context, "Must pass a single argument to log()");
@@ -119,12 +118,12 @@ gjs_log(JSContext *context,
 
     JS_BeginRequest(context);
 
-    /* JS_ValueToString might throw, in which we will only
-     *log that the value could be converted to string */
+    /* 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);
-    jstr = JS_ValueToString(context, argv[0]);
+    JS::RootedString jstr(context, JS::ToString(context, argv[0]));
     if (jstr != NULL)
-        argv[0] = JS::StringValue(jstr);    // GC root
+        argv[0].setString(jstr);  // GC root
     JS_RestoreExceptionState(context, exc_state);
 
     if (jstr == NULL) {
@@ -153,7 +152,6 @@ gjs_log_error(JSContext *context,
 {
     JS::CallArgs argv = JS::CallArgsFromVp (argc, vp);
     JSExceptionState *exc_state;
-    JSString *jstr;
 
     if ((argc != 1 && argc != 2) || !argv[0].isObject()) {
         gjs_throw(context, "Must pass an exception and optionally a message to logError()");
@@ -162,16 +160,16 @@ gjs_log_error(JSContext *context,
 
     JS_BeginRequest(context);
 
+    JS::RootedString jstr(context, NULL);
+
     if (argc == 2) {
-        /* JS_ValueToString might throw, in which we will only
-         *log that the value could be converted to string */
+        /* JS::ToString might throw, in which case we will only log that the
+         * value could be converted to string */
         exc_state = JS_SaveExceptionState(context);
-        jstr = JS_ValueToString(context, argv[1]);
+        jstr = JS::ToString(context, argv[1]);
         if (jstr != NULL)
-            argv[1] = JS::StringValue(jstr);    // GC root
+            argv[1].setString(jstr);  // GC root
         JS_RestoreExceptionState(context, exc_state);
-    } else {
-        jstr = NULL;
     }
 
     gjs_log_exception_full(context, argv[0], jstr);
@@ -195,15 +193,14 @@ gjs_print_parse_args(JSContext *context,
     str = g_string_new("");
     for (n = 0; n < argv.length(); ++n) {
         JSExceptionState *exc_state;
-        JSString *jstr;
 
-        /* JS_ValueToString might throw, in which we will only
-         * log that the value could be converted to string */
+        /* 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);
 
-        jstr = JS_ValueToString(context, argv[n]);
+        JS::RootedString jstr(context, JS::ToString(context, argv[n]));
         if (jstr != NULL)
-            argv[n] = JS::StringValue(jstr); // GC root
+            argv[n].setString(jstr);  // GC root
 
         JS_RestoreExceptionState(context, exc_state);
 
diff --git a/gjs/coverage.cpp b/gjs/coverage.cpp
index 385604c..3f1cdeb 100644
--- a/gjs/coverage.cpp
+++ b/gjs/coverage.cpp
@@ -1321,7 +1321,6 @@ coverage_log(JSContext *context,
     JS::CallArgs argv = JS::CallArgsFromVp (argc, vp);
     char *s;
     JSExceptionState *exc_state;
-    JSString *jstr;
 
     if (argc != 1) {
         gjs_throw(context, "Must pass a single argument to log()");
@@ -1336,12 +1335,12 @@ coverage_log(JSContext *context,
         return true;
     }
 
-    /* JS_ValueToString might throw, in which we will only
-     *log that the value could be converted to string */
+    /* 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);
-    jstr = JS_ValueToString(context, argv[0]);
+    JS::RootedString jstr(context, JS::ToString(context, argv[0]));
     if (jstr != NULL)
-        argv[0] = JS::StringValue(jstr);    // GC root
+        argv[0].setString(jstr);  // GC root
     JS_RestoreExceptionState(context, exc_state);
 
     if (jstr == NULL) {
diff --git a/gjs/jsapi-util.cpp b/gjs/jsapi-util.cpp
index 3d1539d..2433f53 100644
--- a/gjs/jsapi-util.cpp
+++ b/gjs/jsapi-util.cpp
@@ -343,7 +343,6 @@ char*
 gjs_value_debug_string(JSContext      *context,
                        JS::Value       value)
 {
-    JSString *str;
     char *bytes;
     char *debugstr;
 
@@ -354,7 +353,7 @@ gjs_value_debug_string(JSContext      *context,
 
     JS_BeginRequest(context);
 
-    str = JS_ValueToString(context, value);
+    JS::RootedString str(context, JS::ToString(context, value));
 
     if (str == NULL) {
         if (value.isObject()) {
@@ -405,7 +404,7 @@ utf8_exception_from_non_gerror_value(JSContext *cx,
                                      JS::Value  exc)
 {
     char *utf8_exception = NULL;
-    JSString *exc_str = JS_ValueToString(cx, exc);
+    JS::RootedString exc_str(cx, JS::ToString(cx, exc));
     if (exc_str != NULL)
         gjs_string_to_utf8(cx, JS::StringValue(exc_str), &utf8_exception);
     return utf8_exception;
diff --git a/modules/console.cpp b/modules/console.cpp
index e04d599..5cf05fa 100644
--- a/modules/console.cpp
+++ b/modules/console.cpp
@@ -161,7 +161,7 @@ gjs_console_interact(JSContext *context,
     GJS_GET_THIS(context, argc, vp, argv, object);
     bool eof = false;
     JS::Value result;
-    JSString *str;
+    JS::RootedString(str, context);
     GString *buffer = NULL;
     char *temp_buf = NULL;
     int lineno;
@@ -201,12 +201,12 @@ gjs_console_interact(JSContext *context,
         gjs_schedule_gc_if_needed(context);
 
         if (JS_GetPendingException(context, &result)) {
-            str = JS_ValueToString(context, result);
+            str = JS::ToString(context, result);
             JS_ClearPendingException(context);
         } else if (result.isUndefined()) {
             goto next;
         } else {
-            str = JS_ValueToString(context, result);
+            str = JS::ToString(context, result);
         }
 
         if (str) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]