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



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

    WIP - stuff

 gjs/byteArray.cpp |   74 ++++++++++++++++++++++++++--------------------------
 gjs/jsapi-util.h  |    2 +-
 2 files changed, 38 insertions(+), 38 deletions(-)
---
diff --git a/gjs/byteArray.cpp b/gjs/byteArray.cpp
index e582eca..edcea12 100644
--- a/gjs/byteArray.cpp
+++ b/gjs/byteArray.cpp
@@ -63,8 +63,7 @@ struct JSClass gjs_byte_array_class = {
     JS_EnumerateStub,
     JS_ResolveStub,
     JS_ConvertStub,
-    byte_array_finalize,
-    JSCLASS_NO_OPTIONAL_MEMBERS
+    byte_array_finalize
 };
 
 bool
@@ -200,7 +199,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 */
@@ -218,17 +217,24 @@ byte_array_get_prop(JSContext *context,
     return true;
 }
 
+#define THIS_BYTE_ARRAY(cx, argc, vp, args, priv)         \
+    JS::CallArgs args = JS::CallArgsFromVp(argc, vp);     \
+    JS::RootedValue thisv(cx, args.thisv());              \
+    if (!thisv.isObject()) {                              \
+        gjs_throw(cx, "Invalid byte array this object");  \
+        return false;                                     \
+    }                                                     \
+    JS::RootedObject thisobj(cx, &thisv.toObject());      \
+    ByteArrayInstance *priv = priv_from_js (cx, thisobj)
+
 static bool
 byte_array_length_getter(JSContext *context,
-                         JS::HandleObject obj,
-                         JS::HandleId id,
-                         JS::MutableHandleValue value_p)
+                         unsigned   argc,
+                         JS::Value *vp)
 {
-    ByteArrayInstance *priv;
+    THIS_BYTE_ARRAY(context, argc, vp, args, priv);
     gsize len = 0;
 
-    priv = priv_from_js(context, obj);
-
     if (priv == NULL)
         return true; /* prototype, not an instance. */
 
@@ -236,33 +242,30 @@ byte_array_length_getter(JSContext *context,
         len = priv->array->len;
     else if (priv->bytes != NULL)
         len = g_bytes_get_size (priv->bytes);
-    value_p.set(gjs_value_from_gsize(len));
+    args.rval().set(gjs_value_from_gsize(len));
     return true;
 }
 
 static bool
 byte_array_length_setter(JSContext *context,
-                         JS::HandleObject obj,
-                         JS::HandleId id,
-                         bool strict,
-                         JS::MutableHandleValue value_p)
+                         unsigned   argc,
+                         JS::Value *vp)
 {
-    ByteArrayInstance *priv;
+    THIS_BYTE_ARRAY(context, argc, vp, args, priv);
     gsize len = 0;
 
-    priv = priv_from_js(context, obj);
-
     if (priv == NULL)
         return true; /* prototype, not instance */
 
     byte_array_ensure_array(priv);
 
-    if (!gjs_value_to_gsize(context, value_p, &len)) {
+    if (!gjs_value_to_gsize(context, args[0], &len)) {
         gjs_throw(context,
                   "Can't set ByteArray length to non-integer");
         return false;
     }
     g_byte_array_set_size(priv->array, len);
+    args.rval().setUndefined();
     return true;
 }
 
@@ -313,7 +316,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 */
@@ -552,9 +555,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);
 
@@ -682,13 +685,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;
@@ -701,7 +705,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
              */
@@ -761,9 +765,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;
@@ -788,9 +792,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;
@@ -851,11 +855,8 @@ gjs_byte_array_peek_data (JSContext       *context,
 }
 
 JSPropertySpec gjs_byte_array_proto_props[] = {
-    { "length", 0,
-      JSPROP_PERMANENT,
-      JSOP_WRAPPER ((JSPropertyOp) byte_array_length_getter),
-      JSOP_WRAPPER ((JSStrictPropertyOp) byte_array_length_setter),
-    },
+    JS_PSGS("length", byte_array_length_getter, byte_array_length_setter,
+        JSPROP_PERMANENT),
     JS_PS_END
 };
 
@@ -876,13 +877,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.h b/gjs/jsapi-util.h
index 7d45ca4..d5c9618 100644
--- a/gjs/jsapi-util.h
+++ b/gjs/jsapi-util.h
@@ -228,7 +228,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]