After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 593245 - Support input arrays of float and double
Support input arrays of float and double
Status: RESOLVED FIXED
Product: gjs
Classification: Bindings
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: gjs-maint
gjs-maint
Depends on:
Blocks: 591763
 
 
Reported: 2009-08-27 01:41 UTC by Colin Walters
Modified: 2016-11-29 05:41 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Support input arrays of float and double (2.80 KB, patch)
2009-08-27 01:41 UTC, Colin Walters
none Details | Review
add float/double arrays in gi (3.67 KB, patch)
2009-09-21 11:24 UTC, Damien Lespiau
none Details | Review

Description Colin Walters 2009-08-27 01:41:42 UTC
Convert JavaScript arrays to C float/double.
Comment 1 Colin Walters 2009-08-27 01:41:45 UTC
Created attachment 141814 [details] [review]
Support input arrays of float and double
Comment 2 Johan Bilien 2009-08-31 13:54:20 UTC
 static JSBool
+gjs_array_to_floatarray(JSContext   *context,
+                        jsval        array_value,
+                        unsigned int length,
+                        void       **arr_p,
+                        gboolean     is_double)


Havoc would say boolean arguments to functions are evil, maybe you could pass the type tag here instead?


+        if (!JS_GetElement(context, JSVAL_TO_OBJECT(array_value),
+                           i, &elem)) {
+            g_free(result);
+            gjs_throw(context,
+                      "Missing array element %u",
+                      i);
+            return JS_FALSE;
+        }
+
+        if (!JS_ValueToNumber(context, elem, &value)) {
+            g_free(result);
+            gjs_throw(context,
+                      "Invalid element in string array");
+            return JS_FALSE;
+        }
+


I think JS_ValueToNumber and JS_GetElement would already have thrown an exception if they return FALSE, so you don't need to throw another one.


Looks good to me otherwise
Comment 3 Damien Lespiau 2009-09-21 11:22:31 UTC
Hey,

Wanting to try to use Cogl instrospection data with Gjs, I've written a small patch to support float/double arrays arguments. it's only *after* doing so that I realized that someone could have already done it and indeed someone had. Stupid me.

As it's done, I'm just adding it here, a few notes:

* I chose to have 2 separate functions to handle float and double arrays.
* JS_GetElement() and JS_ValueToNumber() documentation state: "If the search fails with an error or exception, JS_GetElement returns JS_FALSE". gjs_throw() checks if there's a pending exception before throwing a new one.
* There's a small typo in the "Invalid element in string array", it should be float/double array
* I've added an exception in the case we are trying to convert an array to a float array with numbers that just don't fit in a float.
Comment 4 Damien Lespiau 2009-09-21 11:24:57 UTC
Created attachment 143583 [details] [review]
add float/double arrays in gi
Comment 5 Philip Chimento 2016-11-29 05:41:30 UTC
It seems Giovanni committed this a long time ago.