[gjs/wip/ptomato/mozjs31] WIP - coverage.cpp



commit d229173c98a8db2dfb7154bdf534d4354b5ce49c
Author: Philip Chimento <philip endlessm com>
Date:   Fri Oct 21 19:09:32 2016 -0700

    WIP - coverage.cpp

 gjs/coverage.cpp |   71 +++++++++++++++++++++++++++++-------------------------
 1 files changed, 38 insertions(+), 33 deletions(-)
---
diff --git a/gjs/coverage.cpp b/gjs/coverage.cpp
index 3f1cdeb..d2eb1a4 100644
--- a/gjs/coverage.cpp
+++ b/gjs/coverage.cpp
@@ -391,13 +391,13 @@ get_absolute_path(const char *path)
     return absolute_path;
 }
 
-typedef bool (*ConvertAndInsertJSVal) (GArray    *array,
-                                       JSContext *context,
-                                       JS::Value *element);
+typedef bool (*ConvertAndInsertJSVal) (GArray         *array,
+                                       JSContext      *context,
+                                       JS::HandleValue element);
 
 static bool
 get_array_from_js_value(JSContext             *context,
-                        JS::Value             *value,
+                        JS::HandleValue        value,
                         size_t                 array_element_size,
                         GDestroyNotify         element_clear_func,
                         ConvertAndInsertJSVal  inserter,
@@ -406,9 +406,7 @@ get_array_from_js_value(JSContext             *context,
     g_return_val_if_fail(out_array != NULL, false);
     g_return_val_if_fail(*out_array == NULL, false);
 
-    JSObject *js_array = &value->toObject();
-
-    if (!JS_IsArrayObject(context, js_array)) {
+    if (!JS_IsArrayObject(context, value)) {
         g_critical("Returned object from is not an array");
         return false;
     }
@@ -418,21 +416,22 @@ get_array_from_js_value(JSContext             *context,
      * preallocate to. */
     GArray *c_side_array = g_array_new(true, true, array_element_size);
     u_int32_t js_array_len;
+    JS::RootedObject js_array(context, &value.toObject());
 
     if (element_clear_func)
         g_array_set_clear_func(c_side_array, element_clear_func);
 
     if (JS_GetArrayLength(context, js_array, &js_array_len)) {
         u_int32_t i = 0;
+        JS::RootedValue element(context);
         for (; i < js_array_len; ++i) {
-            JS::Value element;
             if (!JS_GetElement(context, js_array, i, &element)) {
                 g_array_unref(c_side_array);
                 gjs_throw(context, "Failed to get function names array element %d", i);
                 return false;
             }
 
-            if (!(inserter(c_side_array, context, &element))) {
+            if (!(inserter(c_side_array, context, element))) {
                 g_array_unref(c_side_array);
                 gjs_throw(context, "Failed to convert array element %d", i);
                 return false;
@@ -446,17 +445,17 @@ get_array_from_js_value(JSContext             *context,
 }
 
 static bool
-convert_and_insert_unsigned_int(GArray    *array,
-                                JSContext *context,
-                                JS::Value *element)
+convert_and_insert_unsigned_int(GArray         *array,
+                                JSContext      *context,
+                                JS::HandleValue element)
 {
-    if (!element->isInt32() && !element->isUndefined() && !element->isNull()) {
+    if (!element.isInt32() && !element.isUndefined() && !element.isNull()) {
         g_critical("Array element is not an integer or undefined or null");
         return false;
     }
 
-    if (element->isInt32()) {
-        unsigned int element_integer = element->toInt32();
+    if (element.isInt32()) {
+        unsigned int element_integer = element.toInt32();
         g_array_append_val(array, element_integer);
     } else {
         int not_executable = -1;
@@ -469,17 +468,21 @@ convert_and_insert_unsigned_int(GArray    *array,
 static GArray *
 get_executed_lines_for(JSContext        *context,
                        JS::HandleObject  coverage_statistics,
-                       JS::Value        *filename_value)
+                       JS::HandleValue   filename_value)
 {
     GArray *array = NULL;
-    JS::Value rval;
+    JS::RootedValue rval(context);
+    JS::AutoValueArray<1> args(context);
+    args[0].set(filename_value);
 
-    if (!JS_CallFunctionName(context, coverage_statistics, "getExecutedLinesFor", 1, filename_value, &rval)) 
{
+    if (!JS_CallFunctionName(context, coverage_statistics, "getExecutedLinesFor",
+                             args, &rval)) {
         gjs_log_exception(context);
         return NULL;
     }
 
-    if (!get_array_from_js_value(context, &rval, sizeof(unsigned int), NULL, 
convert_and_insert_unsigned_int, &array)) {
+    if (!get_array_from_js_value(context, rval, sizeof(unsigned int), NULL,
+        convert_and_insert_unsigned_int, &array)) {
         gjs_log_exception(context);
         return NULL;
     }
@@ -506,19 +509,17 @@ clear_coverage_function(gpointer info_location)
 }
 
 static bool
-convert_and_insert_function_decl(GArray    *array,
-                                 JSContext *context,
-                                 JS::Value *element)
+convert_and_insert_function_decl(GArray         *array,
+                                 JSContext      *context,
+                                 JS::HandleValue element)
 {
-    JSObject *object;
-
-    if (!element->isObject()) {
+    if (!element.isObject()) {
         gjs_throw(context, "Function element is not an object");
         return false;
     }
-    object = &element->toObject();
 
-    JS::Value function_name_property_value;
+    JS::RootedObject object(context, &element.toObject());
+    JS::RootedValue function_name_property_value(context);
 
     if (!JS_GetProperty(context, object, "name", &function_name_property_value)) {
         gjs_throw(context, "Failed to get name property for function object");
@@ -541,14 +542,14 @@ convert_and_insert_function_decl(GArray    *array,
         return false;
     }
 
-    JS::Value hit_count_property_value;
+    JS::RootedValue hit_count_property_value(context);
     if (!JS_GetProperty(context, object, "hitCount", &hit_count_property_value) ||
         !hit_count_property_value.isInt32()) {
         gjs_throw(context, "Failed to get hitCount property for function object");
         return false;
     }
 
-    JS::Value line_number_property_value;
+    JS::RootedValue line_number_property_value(context);
     if (!JS_GetProperty(context, object, "line", &line_number_property_value) ||
         !line_number_property_value.isInt32()) {
         gjs_throw(context, "Failed to get line property for function object");
@@ -572,17 +573,21 @@ convert_and_insert_function_decl(GArray    *array,
 static GArray *
 get_functions_for(JSContext        *context,
                   JS::HandleObject  coverage_statistics,
-                  JS::Value        *filename_value)
+                  JS::HandleValue   filename_value)
 {
     GArray *array = NULL;
-    JS::Value rval;
+    JS::RootedValue rval(context);
+    JS::AutoValueArray<1> args(context);
+    args[0].set(filename_value);
 
-    if (!JS_CallFunctionName(context, coverage_statistics, "getFunctionsFor", 1, filename_value, &rval)) {
+    if (!JS_CallFunctionName(context, coverage_statistics, "getFunctionsFor",
+        args, &rval)) {
         gjs_log_exception(context);
         return NULL;
     }
 
-    if (!get_array_from_js_value(context, &rval, sizeof(GjsCoverageFunction), clear_coverage_function, 
convert_and_insert_function_decl, &array)) {
+    if (!get_array_from_js_value(context, rval, sizeof(GjsCoverageFunction),
+        clear_coverage_function, convert_and_insert_function_decl, &array)) {
         gjs_log_exception(context);
         return NULL;
     }


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