diff options
author | Xi Ruoyao <xry111@mengyan1223.wang> | 2022-04-07 12:30:53 +0000 |
---|---|---|
committer | Jan Rybar <jrybar@redhat.com> | 2022-04-07 12:30:53 +0000 |
commit | 56bde409579052c3c5c1f4372cd9c3782845b807 (patch) | |
tree | 98049ca24e5488e1d4609b7911af11bf3aa94b96 /src/polkitbackend | |
parent | 3583a1d25a50f68fa67d2ec0866e2c5e1bb23710 (diff) | |
download | polkit-56bde409579052c3c5c1f4372cd9c3782845b807.tar.gz |
jsauthority: use JS::CompileUtf8Path instead of custom code reading file
Diffstat (limited to 'src/polkitbackend')
-rw-r--r-- | src/polkitbackend/polkitbackendjsauthority.cpp | 31 |
1 files changed, 3 insertions, 28 deletions
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<mozilla::Utf8Unit> 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++; } |