[gjs/wip/ptomato/mozjs31: 7/7] WIP - stuff



commit 9fcb5060574020001ff3fdac11635e9785a8baf8
Author: Philip Chimento <philip chimento gmail com>
Date:   Wed Oct 5 21:44:25 2016 -0700

    WIP - stuff

 gjs/byteArray.cpp     |   31 ++++++++++++++-----------------
 gjs/context.cpp       |    9 ++++-----
 gjs/importer.cpp      |   45 +++++++++++++++++++--------------------------
 gjs/jsapi-util-args.h |    3 +--
 gjs/jsapi-util.h      |    2 +-
 5 files changed, 39 insertions(+), 51 deletions(-)
---
diff --git a/gjs/byteArray.cpp b/gjs/byteArray.cpp
index 9b5e235..5f3586d 100644
--- a/gjs/byteArray.cpp
+++ b/gjs/byteArray.cpp
@@ -64,8 +64,7 @@ struct JSClass gjs_byte_array_class = {
     JS_EnumerateStub,
     JS_ResolveStub,
     JS_ConvertStub,
-    byte_array_finalize,
-    JSCLASS_NO_OPTIONAL_MEMBERS
+    byte_array_finalize
 };
 
 bool
@@ -201,7 +200,7 @@ byte_array_get_prop(JSContext *context,
         return true; /* prototype, not an instance. */
 
     JS::RootedValue id_value(context);
-    if (!JS_IdToValue(context, id, id_value.address()))
+    if (!JS_IdToValue(context, id, &id_value))
         return false;
 
     /* First handle array indexing */
@@ -251,9 +250,7 @@ byte_array_length_setter(JSContext *context,
 
     byte_array_ensure_array(priv);
 
-    // COMPAT: Indexing JS::CallArgs should provide a handle in mozjs31
-    JS::RootedValue arg(context, args[0]);
-    if (!gjs_value_to_gsize(context, arg, &len)) {
+    if (!gjs_value_to_gsize(context, args[0], &len)) {
         gjs_throw(context,
                   "Can't set ByteArray length to non-integer");
         return false;
@@ -310,7 +307,7 @@ byte_array_set_prop(JSContext *context,
         return true; /* prototype, not an instance. */
 
     JS::RootedValue id_value(context);
-    if (!JS_IdToValue(context, id, id_value.address()))
+    if (!JS_IdToValue(context, id, &id_value))
         return false;
 
     /* First handle array indexing */
@@ -534,9 +531,9 @@ byte_array_new(JSContext *context)
 {
     ByteArrayInstance *priv;
 
+    JS::RootedObject proto(context, byte_array_get_prototype(context));
     JS::RootedObject array(context,
-                           JS_NewObject(context, &gjs_byte_array_class,
-                                        byte_array_get_prototype(context), NULL));
+        JS_NewObject(context, &gjs_byte_array_class, proto, JS::NullPtr()));
 
     priv = g_slice_new0(ByteArrayInstance);
 
@@ -664,13 +661,14 @@ from_array_func(JSContext *context,
 
     priv->array = gjs_g_byte_array_new(0);
 
-    if (!JS_IsArrayObject(context, &argv[0].toObject())) {
+    JS::RootedObject array_obj(context, &argv[0].toObject());
+    if (!JS_IsArrayObject(context, array_obj)) {
         gjs_throw(context,
                   "byteArray.fromArray() called with non-array as first arg");
         return false;
     }
 
-    if (!JS_GetArrayLength(context, &argv[0].toObject(), &len)) {
+    if (!JS_GetArrayLength(context, array_obj, &len)) {
         gjs_throw(context,
                   "byteArray.fromArray() can't get length of first array arg");
         return false;
@@ -683,7 +681,7 @@ from_array_func(JSContext *context,
         guint8 b;
 
         elem = JS::UndefinedValue();
-        if (!JS_GetElement(context, &argv[0].toObject(), i, elem.address())) {
+        if (!JS_GetElement(context, array_obj, i, &elem)) {
             /* this means there was an exception, while elem.isUndefined()
              * means no element found
              */
@@ -743,9 +741,9 @@ gjs_byte_array_from_byte_array (JSContext *context,
     g_return_val_if_fail(context != NULL, NULL);
     g_return_val_if_fail(array != NULL, NULL);
 
+    JS::RootedObject proto(context, byte_array_get_prototype(context));
     JS::RootedObject object(context,
-                            JS_NewObject(context, &gjs_byte_array_class,
-                                         byte_array_get_prototype(context), NULL));
+        JS_NewObject(context, &gjs_byte_array_class, proto, JS::NullPtr()));
     if (!object) {
         gjs_throw(context, "failed to create byte array");
         return NULL;
@@ -832,10 +830,9 @@ gjs_define_byte_array_stuff(JSContext              *context,
 {
     JSObject *prototype;
 
-    module.set(JS_NewObject(context, NULL, NULL, NULL));
+    module.set(JS_NewObject(context, NULL, JS::NullPtr(), JS::NullPtr()));
 
-    prototype = JS_InitClass(context, module,
-                             NULL,
+    prototype = JS_InitClass(context, module, JS::NullPtr(),
                              &gjs_byte_array_class,
                              gjs_byte_array_constructor,
                              0,
diff --git a/gjs/context.cpp b/gjs/context.cpp
index af4b1ec..61938e1 100644
--- a/gjs/context.cpp
+++ b/gjs/context.cpp
@@ -339,7 +339,7 @@ gjs_context_dispose(GObject *object)
 
         JS_BeginRequest(js_context->context);
 
-        JS_RemoveObjectRoot(js_context->context, js_context->global.unsafeGet());
+        JS::RemoveObjectRoot(js_context->context, &js_context->global);
         js_context->global.set(NULL);
 
         /* Do a full GC here before tearing down, since once we do
@@ -437,7 +437,6 @@ gjs_context_constructed(GObject *object)
     JS::RootedValue v_global(js_context->context, JS::ObjectValue(*global));
     if (!JS_DefineProperty(js_context->context, global,
                            "window", v_global,
-                           NULL, NULL,
                            JSPROP_READONLY | JSPROP_PERMANENT))
         g_error("No memory to export global object as 'window'");
 
@@ -445,8 +444,8 @@ gjs_context_constructed(GObject *object)
         g_error("Failed to define properties on the global object");
 
     js_context->global.set(global);
-    JS_AddNamedObjectRoot(js_context->context, js_context->global.unsafeGet(),
-                          "global object");
+    JS::AddNamedObjectRoot(js_context->context, &js_context->global,
+                           "global object");
 
     /* We create the global-to-runtime root importer with the
      * passed-in search path. If someone else already created
@@ -763,7 +762,7 @@ gjs_object_get_property_const(JSContext             *cx,
                               JS::MutableHandleValue value_p)
 {
     JS::RootedId pname(cx, gjs_context_get_const_string(cx, property_name));
-    return JS_GetPropertyById(cx, obj, pname, value_p.address());
+    return JS_GetPropertyById(cx, obj, pname, value_p);
 }
 
 /**
diff --git a/gjs/importer.cpp b/gjs/importer.cpp
index b25a97e..43bcc4a 100644
--- a/gjs/importer.cpp
+++ b/gjs/importer.cpp
@@ -74,7 +74,6 @@ define_meta_properties(JSContext       *context,
         JS::RootedValue file_val(context,
             JS::StringValue(JS_NewStringCopyZ(context, full_path)));
         if (!JS_DefineProperty(context, module_obj, "__file__", file_val,
-                               NULL, NULL,
                                /* don't set ENUMERATE since we wouldn't want to copy
                                 * this symbol to any other object for example.
                                 */
@@ -91,7 +90,6 @@ define_meta_properties(JSContext       *context,
 
     if (!JS_DefineProperty(context, module_obj,
                            "__moduleName__", module_name_val,
-                           NULL, NULL,
                            /* don't set ENUMERATE since we wouldn't want to copy
                             * this symbol to any other object for example.
                             */
@@ -100,7 +98,6 @@ define_meta_properties(JSContext       *context,
 
     if (!JS_DefineProperty(context, module_obj,
                            "__parentModule__", parent_module_val,
-                           NULL, NULL,
                            /* don't set ENUMERATE since we wouldn't want to copy
                             * this symbol to any other object for example.
                             */
@@ -138,7 +135,6 @@ define_import(JSContext       *context,
 {
     JS::RootedValue module_val(context, JS::ObjectValue(*module_obj));
     if (!JS_DefineProperty(context, obj, name, module_val,
-                           NULL, NULL,
                            GJS_MODULE_PROP_FLAGS & ~JSPROP_PERMANENT)) {
         gjs_debug(GJS_DEBUG_IMPORTER,
                   "Failed to define '%s' in importer",
@@ -242,13 +238,13 @@ import_native_file(JSContext       *context,
 
     JS::RootedValue v_module(context, JS::ObjectValue(*module_obj));
     return JS_DefineProperty(context, obj, name, v_module,
-                             NULL, NULL, GJS_MODULE_PROP_FLAGS);
+                             GJS_MODULE_PROP_FLAGS);
 }
 
 static JSObject *
 create_module_object(JSContext *context)
 {
-    return JS_NewObject(context, NULL, NULL, NULL);
+    return JS_NewObject(context, NULL, JS::NullPtr(), JS::NullPtr());
 }
 
 static bool
@@ -306,10 +302,8 @@ load_module_init(JSContext       *context,
         gjs_context_get_const_string(context, GJS_STRING_MODULE_INIT));
     if (JS_HasPropertyById(context, in_object, module_init_name, &found) && found) {
         JS::RootedValue module_obj_val(context);
-        if (JS_GetPropertyById(context,
-                               in_object,
-                               module_init_name,
-                               module_obj_val.address())) {
+        if (JS_GetPropertyById(context, in_object,
+                               module_init_name, &module_obj_val)) {
             return &module_obj_val.toObject();
         }
     }
@@ -464,7 +458,7 @@ do_import(JSContext       *context,
 
     for (i = 0; i < search_path_len; ++i) {
         elem.setUndefined();
-        if (!JS_GetElement(context, search_path, i, elem.address())) {
+        if (!JS_GetElement(context, search_path, i, &elem)) {
             /* this means there was an exception, while elem.isUndefined()
              * means no element found
              */
@@ -498,14 +492,9 @@ do_import(JSContext       *context,
         module_obj.set(load_module_init(context, obj, full_path));
         if (module_obj != NULL) {
             JS::RootedValue obj_val(context);
-            if (JS_GetProperty(context,
-                               module_obj,
-                               name,
-                               obj_val.address())) {
+            if (JS_GetProperty(context, module_obj, name, &obj_val)) {
                 if (!obj_val.isUndefined() &&
-                    JS_DefineProperty(context, obj,
-                                      name, obj_val,
-                                      NULL, NULL,
+                    JS_DefineProperty(context, obj, name, obj_val,
                                       GJS_MODULE_PROP_FLAGS & ~JSPROP_PERMANENT)) {
                     result = true;
                     goto out;
@@ -709,7 +698,7 @@ importer_new_enumerate(JSContext  *context,
             GDir *dir = NULL;
 
             elem = JS::UndefinedValue();
-            if (!JS_GetElement(context, search_path, i, elem.address())) {
+            if (!JS_GetElement(context, search_path, i, &elem)) {
                 /* this means there was an exception, while elem.isUndefined()
                  * means no element found
                  */
@@ -775,7 +764,13 @@ importer_new_enumerate(JSContext  *context,
             g_free(dirname);
         }
 
-        statep.get().setPrivate(iter);
+        /* FIXME: setPrivate() is not in js::MutableValueOperations (see
+         * Value.h) and now SpiderMonkey is stricter with const for
+         * Handle::get(); how to do this correctly? This code might allow
+         * statep_private to get GC'd before going into statep. */
+        JS::Value statep_private;
+        statep_private.setPrivate(iter);
+        statep.set(statep_private);
 
         idp.set(INT_TO_JSID(iter->elements->len));
 
@@ -797,7 +792,7 @@ importer_new_enumerate(JSContext  *context,
                                          &element_val))
                 return false;
 
-            if (!JS_ValueToId(context, element_val, idp.address()))
+            if (!JS_ValueToId(context, element_val, idp))
                 return false;
 
             break;
@@ -910,8 +905,7 @@ struct JSClass gjs_importer_class = {
     (JSEnumerateOp) importer_new_enumerate, /* needs cast since it's the new enumerate signature */
     (JSResolveOp) importer_new_resolve, /* needs cast since it's the new resolve signature */
     JS_ConvertStub,
-    importer_finalize,
-    JSCLASS_NO_OPTIONAL_MEMBERS
+    importer_finalize
 };
 
 JSPropertySpec gjs_importer_proto_props[] = {
@@ -941,7 +935,7 @@ importer_new(JSContext *context,
                                   * prototype; NULL for
                                   * Object.prototype
                                   */
-                                 NULL,
+                                 JS::NullPtr(),
                                  &gjs_importer_class,
                                  /* constructor for instances (NULL for
                                   * none - just name the prototype like
@@ -966,7 +960,7 @@ importer_new(JSContext *context,
     }
 
     JS::RootedObject importer(context,
-        JS_NewObject(context, &gjs_importer_class, NULL, global));
+        JS_NewObject(context, &gjs_importer_class, JS::NullPtr(), global));
     if (importer == NULL)
         g_error("No memory to create importer importer");
 
@@ -1089,7 +1083,6 @@ gjs_define_importer(JSContext       *context,
 
     JS::RootedValue v_importer(context, JS::ObjectValue(*importer));
     if (!JS_DefineProperty(context, in_object, importer_name, v_importer,
-                           NULL, NULL,
                            GJS_MODULE_PROP_FLAGS))
         g_error("no memory to define importer property");
 
diff --git a/gjs/jsapi-util-args.h b/gjs/jsapi-util-args.h
index a3bad22..2e0cf95 100644
--- a/gjs/jsapi-util-args.h
+++ b/gjs/jsapi-util-args.h
@@ -245,8 +245,7 @@ parse_call_args_helper(JSContext    *cx,
     }
 
     try {
-        /* COMPAT: JS::CallArgs::operator[] will yield Handle in mozjs31 */
-        assign(cx, *fchar, nullable, args.handleOrUndefinedAt(param_ix), param_ref);
+        assign(cx, *fchar, nullable, args[param_ix], param_ref);
     } catch (char *message) {
         /* Our error messages are going to be more useful than whatever was
          * thrown by the various conversion functions */
diff --git a/gjs/jsapi-util.h b/gjs/jsapi-util.h
index b406570..1a29cce 100644
--- a/gjs/jsapi-util.h
+++ b/gjs/jsapi-util.h
@@ -265,7 +265,7 @@ gjs_##name##_constructor(JSContext  *context,           \
             gjs_throw_constructor_error(context);                              \
             return false;                                                      \
         }                                                                      \
-        object = JS_NewObjectForConstructor(context, &gjs_##name##_class, vp); \
+        object = JS_NewObjectForConstructor(context, &gjs_##name##_class, argv); \
         if (object == NULL)                                                    \
             return false;                                                      \
     }


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