From 56bde409579052c3c5c1f4372cd9c3782845b807 Mon Sep 17 00:00:00 2001 From: Xi Ruoyao Date: Thu, 7 Apr 2022 12:30:53 +0000 Subject: jsauthority: use JS::CompileUtf8Path instead of custom code reading file --- src/polkitbackend/polkitbackendjsauthority.cpp | 31 +++----------------------- 1 file changed, 3 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/polkitbackend/polkitbackendjsauthority.cpp b/src/polkitbackend/polkitbackendjsauthority.cpp index 660407f..2568e8e 100644 --- a/src/polkitbackend/polkitbackendjsauthority.cpp +++ b/src/polkitbackend/polkitbackendjsauthority.cpp @@ -216,39 +216,16 @@ load_scripts (PolkitBackendJsAuthority *authority) for (l = files; l != NULL; l = l->next) { const gchar *filename = (gchar *)l->data; - GFile *file = g_file_new_for_path (filename); - char *contents; - gsize len; - if (!g_file_load_contents (file, NULL, &contents, &len, NULL, NULL)) - { - polkit_backend_authority_log (POLKIT_BACKEND_AUTHORITY (authority), - "Error compiling script %s", - filename); - g_object_unref (file); - continue; - } - - g_object_unref (file); - - JS::SourceText source; - if (!source.init (authority->priv->cx, contents, len, - JS::SourceOwnership::Borrowed)) - { - polkit_backend_authority_log (POLKIT_BACKEND_AUTHORITY (authority), - "Error compiling script %s", - filename); - g_free (contents); - continue; - } JS::CompileOptions options(authority->priv->cx); JS::RootedScript script(authority->priv->cx, - JS::Compile (authority->priv->cx, options, source)); + JS::CompileUtf8Path (authority->priv->cx, + options, + filename)); if (!script) { polkit_backend_authority_log (POLKIT_BACKEND_AUTHORITY (authority), "Error compiling script %s", filename); - g_free (contents); continue; } @@ -261,13 +238,11 @@ load_scripts (PolkitBackendJsAuthority *authority) polkit_backend_authority_log (POLKIT_BACKEND_AUTHORITY (authority), "Error executing script %s", filename); - g_free (contents); continue; } //g_print ("Successfully loaded and evaluated script `%s'\n", filename); - g_free (contents); num_scripts++; } -- cgit v1.2.1