[gjs/wip/ptomato/mozjs31prep] WIP - Replace JS_ValueToInt32 - buggy
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/wip/ptomato/mozjs31prep] WIP - Replace JS_ValueToInt32 - buggy
- Date: Sat, 1 Oct 2016 01:22:31 +0000 (UTC)
commit 90e9f7e3d88a1a1fb556261df885b1a682183395
Author: Philip Chimento <philip endlessm com>
Date: Fri Sep 30 18:19:37 2016 -0700
WIP - Replace JS_ValueToInt32 - buggy
This changes rounding behaviour when converting JS number values to ints
during JS->GI marshalling!
A test is failing that expected failure while marshalling an array to an
int, whereas now the operation succeeds with 0. The offending change
seems to be arg.cpp:1213. However, this behaviour would seem to be normal
in JS:
gjs> let a = Int32Array(1);
gjs> a[0] = ['this', 'is', 'fine'];
this,is,fine
gjs> a[0]
0
NEWS | 8 ++++++++
gi/arg.cpp | 6 +++---
gi/value.cpp | 6 +++---
installed-tests/js/testGDBus.js | 2 +-
4 files changed, 15 insertions(+), 7 deletions(-)
---
diff --git a/NEWS b/NEWS
index 330db9d..6f5d2c1 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,11 @@
+NEXT
+----
+- The rounding of signed integers when marshalling JavaScript number values into
+ GObject introspection integer values has changed to match the ECMA standard: instead of floor(x + 0.5), we
now round as signum(x) * floor(abs(x)).
+ Basically this means 10.5 will round to 10, not 11 as it would have in
+ previous GJS versions.
+ http://www.ecma-international.org/ecma-262/7.0/index.html#sec-toint32
+
Version 1.46.0
--------------
diff --git a/gi/arg.cpp b/gi/arg.cpp
index b7ea873..af3a9a7 100644
--- a/gi/arg.cpp
+++ b/gi/arg.cpp
@@ -1173,7 +1173,7 @@ gjs_value_to_g_argument(JSContext *context,
case GI_TYPE_TAG_INT8: {
gint32 i;
- if (!JS_ValueToInt32(context, value, &i))
+ if (!JS::ToInt32(context, value, &i))
wrong = true;
if (i > G_MAXINT8 || i < G_MININT8)
out_of_range = true;
@@ -1191,7 +1191,7 @@ gjs_value_to_g_argument(JSContext *context,
}
case GI_TYPE_TAG_INT16: {
gint32 i;
- if (!JS_ValueToInt32(context, value, &i))
+ if (!JS::ToInt32(context, value, &i))
wrong = true;
if (i > G_MAXINT16 || i < G_MININT16)
out_of_range = true;
@@ -1210,7 +1210,7 @@ gjs_value_to_g_argument(JSContext *context,
}
case GI_TYPE_TAG_INT32:
- if (!JS_ValueToInt32(context, value, &arg->v_int))
+ if (!JS::ToInt32(context, value, &arg->v_int))
wrong = true;
break;
diff --git a/gi/value.cpp b/gi/value.cpp
index d5c2282..46f5117 100644
--- a/gi/value.cpp
+++ b/gi/value.cpp
@@ -414,7 +414,7 @@ gjs_value_to_g_value_internal(JSContext *context,
}
} else if (gtype == G_TYPE_CHAR) {
gint32 i;
- if (JS_ValueToInt32(context, value, &i) && i >= SCHAR_MIN && i <= SCHAR_MAX) {
+ if (JS::ToInt32(context, value, &i) && i >= SCHAR_MIN && i <= SCHAR_MAX) {
g_value_set_schar(gvalue, (signed char)i);
} else {
gjs_throw(context,
@@ -434,7 +434,7 @@ gjs_value_to_g_value_internal(JSContext *context,
}
} else if (gtype == G_TYPE_INT) {
gint32 i;
- if (JS_ValueToInt32(context, value, &i)) {
+ if (JS::ToInt32(context, value, &i)) {
g_value_set_int(gvalue, i);
} else {
gjs_throw(context,
@@ -717,7 +717,7 @@ gjs_value_to_g_value_internal(JSContext *context,
* e.g. ClutterUnit.
*/
gint32 i;
- if (JS_ValueToInt32(context, value, &i)) {
+ if (JS::ToInt32(context, value, &i)) {
GValue int_value = { 0, };
g_value_init(&int_value, G_TYPE_INT);
g_value_set_int(&int_value, i);
diff --git a/installed-tests/js/testGDBus.js b/installed-tests/js/testGDBus.js
index 4e5c8ec..eff6765 100644
--- a/installed-tests/js/testGDBus.js
+++ b/installed-tests/js/testGDBus.js
@@ -591,7 +591,7 @@ function testDictSignatures() {
JSUnit.assertNotNull(theResult);
// verify the fractional part was dropped off int
- JSUnit.assertEquals(11, theResult['anInteger'].deep_unpack());
+ JSUnit.assertEquals(10, theResult['anInteger'].deep_unpack());
// and not dropped off a double
JSUnit.assertEquals(10.5, theResult['aDoubleBeforeAndAfter'].deep_unpack());
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]