[gjs/wip/ptomato/mozjs31prep: 4/4] js: Root gjs_value_to_g_value()
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/wip/ptomato/mozjs31prep: 4/4] js: Root gjs_value_to_g_value()
- Date: Thu, 3 Nov 2016 22:21:58 +0000 (UTC)
commit 8c6e7de4819a137796f34a3b63f608770a4c6f9c
Author: Philip Chimento <philip endlessm com>
Date: Wed Nov 2 19:46:08 2016 -0700
js: Root gjs_value_to_g_value()
Converting gjs_value_to_g_value() and gjs_value_to_g_value_no_copy() to
use exact rooting has a small cascade effect into object.cpp.
https://bugzilla.gnome.org/show_bug.cgi?id=742249
gi/object.cpp | 18 +++++++-------
gi/value.cpp | 70 +++++++++++++++++++++++++++++---------------------------
gi/value.h | 12 +++++-----
3 files changed, 51 insertions(+), 49 deletions(-)
---
diff --git a/gi/object.cpp b/gi/object.cpp
index e44c888..6000473 100644
--- a/gi/object.cpp
+++ b/gi/object.cpp
@@ -186,12 +186,12 @@ throw_priv_is_null_error(JSContext *context)
}
static ValueFromPropertyResult
-init_g_param_from_property(JSContext *context,
- const char *js_prop_name,
- JS::Value js_value,
- GType gtype,
- GParameter *parameter,
- bool constructing)
+init_g_param_from_property(JSContext *context,
+ const char *js_prop_name,
+ JS::HandleValue value,
+ GType gtype,
+ GParameter *parameter,
+ bool constructing)
{
char *gname;
GParamSpec *param_spec;
@@ -231,7 +231,7 @@ init_g_param_from_property(JSContext *context,
js_prop_name, param_spec->name);
g_value_init(¶meter->value, G_PARAM_SPEC_VALUE_TYPE(param_spec));
- if (!gjs_value_to_g_value(context, js_value, ¶meter->value)) {
+ if (!gjs_value_to_g_value(context, value, ¶meter->value)) {
g_value_unset(¶meter->value);
return SOME_ERROR_OCCURRED;
}
@@ -1711,9 +1711,9 @@ emit_func(JSContext *context,
g_value_init(value, signal_query.param_types[i] & ~G_SIGNAL_TYPE_STATIC_SCOPE);
if ((signal_query.param_types[i] & G_SIGNAL_TYPE_STATIC_SCOPE) != 0)
- failed = !gjs_value_to_g_value_no_copy(context, argv[i+1], value);
+ failed = !gjs_value_to_g_value_no_copy(context, argv.handleOrUndefinedAt(i + 1), value);
else
- failed = !gjs_value_to_g_value(context, argv[i+1], value);
+ failed = !gjs_value_to_g_value(context, argv.handleOrUndefinedAt(i + 1), value);
if (failed)
break;
diff --git a/gi/value.cpp b/gi/value.cpp
index 85099ee..bb27e1c 100644
--- a/gi/value.cpp
+++ b/gi/value.cpp
@@ -351,10 +351,10 @@ gjs_value_guess_g_type(JSContext *context,
}
static bool
-gjs_value_to_g_value_internal(JSContext *context,
- JS::Value value,
- GValue *gvalue,
- bool no_copy)
+gjs_value_to_g_value_internal(JSContext *context,
+ JS::HandleValue value,
+ GValue *gvalue,
+ bool no_copy)
{
GType gtype;
@@ -491,36 +491,38 @@ gjs_value_to_g_value_internal(JSContext *context,
if (value.isNull()) {
/* do nothing */
- } else if (JS_HasPropertyById(context, &value.toObject(), length_name, &found_length) &&
- found_length) {
+ } else {
JS::RootedObject array_obj(context, &value.toObject());
- guint32 length;
-
- if (!gjs_object_require_converted_property_value(context, array_obj,
- NULL, length_name,
- &length)) {
- JS_ClearPendingException(context);
+ if (JS_HasPropertyById(context, array_obj, length_name, &found_length) &&
+ found_length) {
+ guint32 length;
+
+ if (!gjs_object_require_converted_property_value(context, array_obj,
+ NULL, length_name,
+ &length)) {
+ JS_ClearPendingException(context);
+ gjs_throw(context,
+ "Wrong type %s; strv expected",
+ gjs_get_type_name(value));
+ return false;
+ } else {
+ void *result;
+ char **strv;
+
+ if (!gjs_array_to_strv (context,
+ value,
+ length, &result))
+ return false;
+ /* cast to strv in a separate step to avoid type-punning */
+ strv = (char**) result;
+ g_value_take_boxed (gvalue, strv);
+ }
+ } else {
gjs_throw(context,
"Wrong type %s; strv expected",
gjs_get_type_name(value));
return false;
- } else {
- void *result;
- char **strv;
-
- if (!gjs_array_to_strv (context,
- value,
- length, &result))
- return false;
- /* cast to strv in a separate step to avoid type-punning */
- strv = (char**) result;
- g_value_take_boxed (gvalue, strv);
}
- } else {
- gjs_throw(context,
- "Wrong type %s; strv expected",
- gjs_get_type_name(value));
- return false;
}
} else if (g_type_is_a(gtype, G_TYPE_BOXED)) {
void *gboxed;
@@ -731,17 +733,17 @@ gjs_value_to_g_value_internal(JSContext *context,
}
bool
-gjs_value_to_g_value(JSContext *context,
- JS::Value value,
- GValue *gvalue)
+gjs_value_to_g_value(JSContext *context,
+ JS::HandleValue value,
+ GValue *gvalue)
{
return gjs_value_to_g_value_internal(context, value, gvalue, false);
}
bool
-gjs_value_to_g_value_no_copy(JSContext *context,
- JS::Value value,
- GValue *gvalue)
+gjs_value_to_g_value_no_copy(JSContext *context,
+ JS::HandleValue value,
+ GValue *gvalue)
{
return gjs_value_to_g_value_internal(context, value, gvalue, true);
}
diff --git a/gi/value.h b/gi/value.h
index f7613f9..d6f3c42 100644
--- a/gi/value.h
+++ b/gi/value.h
@@ -30,12 +30,12 @@
G_BEGIN_DECLS
-bool gjs_value_to_g_value (JSContext *context,
- JS::Value value,
- GValue *gvalue);
-bool gjs_value_to_g_value_no_copy (JSContext *context,
- JS::Value value,
- GValue *gvalue);
+bool gjs_value_to_g_value (JSContext *context,
+ JS::HandleValue value,
+ GValue *gvalue);
+bool gjs_value_to_g_value_no_copy (JSContext *context,
+ JS::HandleValue value,
+ GValue *gvalue);
bool gjs_value_from_g_value(JSContext *context,
JS::MutableHandleValue value_p,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]