From f564456063fc2e6554a8e764e0ad0414fb0577b2 Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Thu, 22 Mar 2018 13:00:33 -0400 Subject: [PATCH] jsauthority: use JS::Evaluate instead of JS_EvaluateScript JS_EvaluateScript is no longer in the API set, so use JS::Evaluate instead. Signed-off-by: Ray Strode https://bugs.freedesktop.org/show_bug.cgi?id=105865 --- src/polkitbackend/polkitbackendjsauthority.cpp | 49 +++++++++++--------------- 1 file changed, 21 insertions(+), 28 deletions(-) diff --git a/src/polkitbackend/polkitbackendjsauthority.cpp b/src/polkitbackend/polkitbackendjsauthority.cpp index a19e926..022ba7c 100644 --- a/src/polkitbackend/polkitbackendjsauthority.cpp +++ b/src/polkitbackend/polkitbackendjsauthority.cpp @@ -480,66 +480,66 @@ polkit_backend_js_authority_constructed (GObject *object) global = authority->priv->js_global->get (); if (global == NULL) goto fail; authority->priv->ac = new JSAutoCompartment(authority->priv->cx, global); if (authority->priv->ac == NULL) goto fail; if (!JS_InitStandardClasses (authority->priv->cx, global)) goto fail; JS::RootedObject polkit(authority->priv->cx); authority->priv->js_polkit = new JS::Heap (JS_NewObject (authority->priv->cx, &js_polkit_class)); polkit = authority->priv->js_polkit->get (); if (polkit == NULL) goto fail; if (!JS_DefineProperty(authority->priv->cx, global, "polkit", polkit, JSPROP_ENUMERATE)) goto fail; if (!JS_DefineFunctions (authority->priv->cx, polkit, js_polkit_functions)) goto fail; - if (!JS_EvaluateScript (authority->priv->cx, - global, - init_js, strlen (init_js), /* init.js */ - "init.js", /* filename */ - 0, /* lineno */ - NULL)) /* rval */ + JS::CompileOptions options(authority->priv->cx, JSVERSION_UNKNOWN); + JS::RootedValue rval(authority->priv->cx); + if (!JS::Evaluate (authority->priv->cx, + options, + init_js, strlen (init_js), /* init.js */ + &rval)) /* rval */ { goto fail; } if (authority->priv->rules_dirs == NULL) { authority->priv->rules_dirs = g_new0 (gchar *, 3); authority->priv->rules_dirs[0] = g_strdup (PACKAGE_SYSCONF_DIR "/polkit-1/rules.d"); authority->priv->rules_dirs[1] = g_strdup (PACKAGE_DATA_DIR "/polkit-1/rules.d"); } authority->priv->rkt_context = g_main_context_new (); authority->priv->rkt_loop = g_main_loop_new (authority->priv->rkt_context, FALSE); g_mutex_init (&authority->priv->rkt_timeout_pending_mutex); authority->priv->runaway_killer_thread = g_thread_new ("runaway-killer-thread", runaway_killer_thread_func, authority); setup_file_monitors (authority); load_scripts (authority); } JS_EndRequest (authority->priv->cx); entered_request = FALSE; G_OBJECT_CLASS (polkit_backend_js_authority_parent_class)->constructed (object); return; fail: @@ -704,88 +704,87 @@ set_property_int32 (PolkitBackendJsAuthority *authority, JSObject *obj, const gchar *name, gint32 value) { JS::Value value_jsval; value_jsval = INT_TO_JSVAL ((gint32) value); JS_SetProperty (authority->priv->cx, obj, name, &value_jsval); } /* authority->priv->cx must be within a request */ static void set_property_bool (PolkitBackendJsAuthority *authority, JSObject *obj, const gchar *name, gboolean value) { JS::Value value_jsval; value_jsval = BOOLEAN_TO_JSVAL ((bool) value); JS_SetProperty (authority->priv->cx, obj, name, &value_jsval); } /* ---------------------------------------------------------------------------------------------------- */ /* authority->priv->cx must be within a request */ static gboolean subject_to_jsval (PolkitBackendJsAuthority *authority, PolkitSubject *subject, PolkitIdentity *user_for_subject, gboolean subject_is_local, gboolean subject_is_active, - JS::Value *out_jsval, + JS::MutableHandleValue out_jsval, GError **error) { gboolean ret = FALSE; - JS::Value ret_jsval; + JS::CompileOptions options(authority->priv->cx, JSVERSION_UNKNOWN); const char *src; JS::RootedObject obj(authority->priv->cx); pid_t pid; uid_t uid; gchar *user_name = NULL; GPtrArray *groups = NULL; struct passwd *passwd; char *seat_str = NULL; char *session_str = NULL; JS::RootedObject global(authority->priv->cx, authority->priv->js_global->get ()); src = "new Subject();"; - if (!JS_EvaluateScript (authority->priv->cx, - global, - src, strlen (src), - __FILE__, __LINE__, - &ret_jsval)) + if (!JS::Evaluate (authority->priv->cx, + options, + src, strlen (src), + out_jsval)) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Evaluating '%s' failed", src); goto out; } - obj = ret_jsval.toObjectOrNull(); + obj = out_jsval.toObjectOrNull(); if (POLKIT_IS_UNIX_PROCESS (subject)) { pid = polkit_unix_process_get_pid (POLKIT_UNIX_PROCESS (subject)); } else if (POLKIT_IS_SYSTEM_BUS_NAME (subject)) { PolkitSubject *process; process = polkit_system_bus_name_get_process_sync (POLKIT_SYSTEM_BUS_NAME (subject), NULL, error); if (process == NULL) goto out; pid = polkit_unix_process_get_pid (POLKIT_UNIX_PROCESS (process)); g_object_unref (process); } else { g_assert_not_reached (); } #ifdef HAVE_LIBSYSTEMD if (sd_pid_get_session (pid, &session_str) == 0) { if (sd_session_get_seat (session_str, &seat_str) == 0) { /* do nothing */ } } #endif /* HAVE_LIBSYSTEMD */ g_assert (POLKIT_IS_UNIX_USER (user_for_subject)); @@ -822,117 +821,111 @@ subject_to_jsval (PolkitBackendJsAuthority *authority, group = getgrgid (gids[n]); if (group == NULL) { g_ptr_array_add (groups, g_strdup_printf ("%d", (gint) gids[n])); } else { g_ptr_array_add (groups, g_strdup (group->gr_name)); } } } } set_property_int32 (authority, obj, "pid", pid); set_property_str (authority, obj, "user", user_name); set_property_strv (authority, obj, "groups", groups); set_property_str (authority, obj, "seat", seat_str); set_property_str (authority, obj, "session", session_str); set_property_bool (authority, obj, "local", subject_is_local); set_property_bool (authority, obj, "active", subject_is_active); ret = TRUE; out: free (session_str); free (seat_str); g_free (user_name); if (groups != NULL) g_ptr_array_unref (groups); - if (ret && out_jsval != NULL) - *out_jsval = ret_jsval; - return ret; } /* ---------------------------------------------------------------------------------------------------- */ /* authority->priv->cx must be within a request */ static gboolean action_and_details_to_jsval (PolkitBackendJsAuthority *authority, const gchar *action_id, PolkitDetails *details, - JS::Value *out_jsval, + JS::MutableHandleValue out_jsval, GError **error) { gboolean ret = FALSE; - JS::Value ret_jsval; + JS::CompileOptions options(authority->priv->cx, JSVERSION_UNKNOWN); const char *src; JS::RootedObject obj(authority->priv->cx); gchar **keys; guint n; JS::RootedObject global(authority->priv->cx, authority->priv->js_global->get ()); src = "new Action();"; - if (!JS_EvaluateScript (authority->priv->cx, - global, - src, strlen (src), - __FILE__, __LINE__, - &ret_jsval)) + + if (!JS::Evaluate (authority->priv->cx, + options, + src, strlen (src), + out_jsval)) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Evaluating '%s' failed", src); goto out; } - obj = ret_jsval.toObjectOrNull(); + obj = out_jsval.toObjectOrNull(); set_property_str (authority, obj, "id", action_id); keys = polkit_details_get_keys (details); for (n = 0; keys != NULL && keys[n] != NULL; n++) { gchar *key; const gchar *value; key = g_strdup_printf ("_detail_%s", keys[n]); value = polkit_details_lookup (details, keys[n]); set_property_str (authority, obj, key, value); g_free (key); } g_strfreev (keys); ret = TRUE; out: - if (ret && out_jsval != NULL) - *out_jsval = ret_jsval; - return ret; } /* ---------------------------------------------------------------------------------------------------- */ static gpointer runaway_killer_thread_func (gpointer user_data) { PolkitBackendJsAuthority *authority = POLKIT_BACKEND_JS_AUTHORITY (user_data); g_main_context_push_thread_default (authority->priv->rkt_context); g_main_loop_run (authority->priv->rkt_loop); g_main_context_pop_thread_default (authority->priv->rkt_context); return NULL; } /* ---------------------------------------------------------------------------------------------------- */ static bool js_operation_callback (JSContext *cx) { PolkitBackendJsAuthority *authority = POLKIT_BACKEND_JS_AUTHORITY (JS_GetContextPrivate (cx)); JSString *val_str; JS::RootedValue val(cx); /* This callback can be called by the runtime at any time without us causing * it by JS_TriggerOperationCallback(). */ g_mutex_lock (&authority->priv->rkt_timeout_pending_mutex); if (!authority->priv->rkt_timeout_pending) -- 2.16.2