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



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

    WIP - stuff

 gjs/byteArray.cpp     |   37 +++++++++++++++++--------------------
 gjs/jsapi-util-args.h |    3 +--
 gjs/jsapi-util.h      |    2 +-
 3 files changed, 19 insertions(+), 23 deletions(-)
---
diff --git a/gjs/byteArray.cpp b/gjs/byteArray.cpp
index e1e5c38..831e8c8 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;
@@ -770,9 +768,9 @@ gjs_byte_array_from_bytes (JSContext *context,
     g_return_val_if_fail(context != NULL, NULL);
     g_return_val_if_fail(bytes != 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;
@@ -855,13 +853,12 @@ bool
 gjs_define_byte_array_stuff(JSContext  *context,
                             JSObject  **module_out)
 {
-    JSObject *module;
     JSObject *prototype;
-
-    module = JS_NewObject (context, NULL, NULL, NULL);
+    JS::RootedObject module(context,
+                            JS_NewObject(context, NULL, JS::NullPtr(), JS::NullPtr()));
 
     prototype = JS_InitClass(context, module,
-                             NULL,
+                             JS::NullPtr(),
                              &gjs_byte_array_class,
                              gjs_byte_array_constructor,
                              0,
diff --git a/gjs/jsapi-util-args.h b/gjs/jsapi-util-args.h
index 5f0bd2e..45a7e1b 100644
--- a/gjs/jsapi-util-args.h
+++ b/gjs/jsapi-util-args.h
@@ -104,8 +104,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 cb97a24..30f457f 100644
--- a/gjs/jsapi-util.h
+++ b/gjs/jsapi-util.h
@@ -264,7 +264,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]