Commit 25242465 authored by Ray Strode's avatar Ray Strode

jsauthority: fix up set_property methods

Signed-off-by: Ray Strode's avatarRay Strode <rstrode@redhat.com>

https://bugs.freedesktop.org/show_bug.cgi?id=105865
parent f5644560
...@@ -660,66 +660,75 @@ polkit_backend_js_authority_class_init (PolkitBackendJsAuthorityClass *klass) ...@@ -660,66 +660,75 @@ polkit_backend_js_authority_class_init (PolkitBackendJsAuthorityClass *klass)
/* authority->priv->cx must be within a request */ /* authority->priv->cx must be within a request */
static void static void
set_property_str (PolkitBackendJsAuthority *authority, set_property_str (PolkitBackendJsAuthority *authority,
JSObject *obj, JS::HandleObject obj,
const gchar *name, const gchar *name,
const gchar *value) const gchar *value)
{ {
JSString *value_jsstr; JS::RootedValue value_jsval(authority->priv->cx);
JS::Value value_jsval; if (value)
value_jsstr = JS_NewStringCopyZ (authority->priv->cx, value); {
value_jsval = JS::StringValue (value_jsstr); JS::ConstUTF8CharsZ chars(value, strlen(value));
JS_SetProperty (authority->priv->cx, obj, name, &value_jsval); JS::RootedString str(authority->priv->cx, JS_NewStringCopyUTF8Z(authority->priv->cx, chars));
value_jsval = JS::StringValue (str);
}
else
value_jsval = JS::NullValue ();
JS_SetProperty (authority->priv->cx, obj, name, value_jsval);
} }
/* authority->priv->cx must be within a request */ /* authority->priv->cx must be within a request */
static void static void
set_property_strv (PolkitBackendJsAuthority *authority, set_property_strv (PolkitBackendJsAuthority *authority,
JSObject *obj, JS::HandleObject obj,
const gchar *name, const gchar *name,
GPtrArray *value) GPtrArray *value)
{ {
JS::Value value_jsval; JS::RootedValue value_jsval(authority->priv->cx);
JSObject *array_object; JS::AutoValueVector elems(authority->priv->cx);
guint n; guint n;
array_object = JS_NewArrayObject (authority->priv->cx, 0, NULL); elems.resize(value->len);
for (n = 0; n < value->len; n++) for (n = 0; n < value->len; n++)
{ {
JSString *jsstr; const char *c_string = (const char *) g_ptr_array_index(value, n);
JS::Value val; if (c_string)
{
jsstr = JS_NewStringCopyZ (authority->priv->cx, (char *)g_ptr_array_index(value, n)); JS::ConstUTF8CharsZ chars(c_string, strlen(c_string));
val = JS::StringValue (jsstr); JS::RootedString str(authority->priv->cx, JS_NewStringCopyUTF8Z(authority->priv->cx, chars));
JS_SetElement (authority->priv->cx, array_object, n, &val); elems[n].setString(str);
}
else
elems[n].setNull ();
} }
JS::RootedObject array_object(authority->priv->cx, JS_NewArrayObject (authority->priv->cx, elems));
value_jsval = JS::ObjectValue (*array_object); value_jsval = JS::ObjectValue (*array_object);
JS_SetProperty (authority->priv->cx, obj, name, &value_jsval); JS_SetProperty (authority->priv->cx, obj, name, value_jsval);
} }
/* authority->priv->cx must be within a request */ /* authority->priv->cx must be within a request */
static void static void
set_property_int32 (PolkitBackendJsAuthority *authority, set_property_int32 (PolkitBackendJsAuthority *authority,
JSObject *obj, JS::HandleObject obj,
const gchar *name, const gchar *name,
gint32 value) gint32 value)
{ {
JS::Value value_jsval; JS::RootedValue value_jsval(authority->priv->cx);
value_jsval = INT_TO_JSVAL ((gint32) value); value_jsval = JS::Int32Value ((gint32) value);
JS_SetProperty (authority->priv->cx, obj, name, &value_jsval); JS_SetProperty (authority->priv->cx, obj, name, value_jsval);
} }
/* authority->priv->cx must be within a request */ /* authority->priv->cx must be within a request */
static void static void
set_property_bool (PolkitBackendJsAuthority *authority, set_property_bool (PolkitBackendJsAuthority *authority,
JSObject *obj, JS::HandleObject obj,
const gchar *name, const gchar *name,
gboolean value) gboolean value)
{ {
JS::Value value_jsval; JS::RootedValue value_jsval(authority->priv->cx);
value_jsval = BOOLEAN_TO_JSVAL ((bool) value); value_jsval = JS::BooleanValue ((bool) value);
JS_SetProperty (authority->priv->cx, obj, name, &value_jsval); JS_SetProperty (authority->priv->cx, obj, name, value_jsval);
} }
/* ---------------------------------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------------------------------------- */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment