summaryrefslogtreecommitdiff
path: root/meta-openembedded/meta-oe/recipes-extended/polkit/polkit/0003-jsauthority-ensure-to-call-JS_Init-and-JS_ShutDown-e.patch
blob: 9e9755e44f36a59e4e46e55564ffd04bad62b4ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
From 7799441b9aa55324160deefbc65f9d918b8c94c1 Mon Sep 17 00:00:00 2001
From: Xi Ruoyao <xry111@mengyan1223.wang>
Date: Tue, 10 Aug 2021 18:52:56 +0800
Subject: [PATCH] jsauthority: ensure to call JS_Init() and JS_ShutDown()
 exactly once

Before this commit, we were calling JS_Init() in
polkit_backend_js_authority_class_init and never called JS_ShutDown.
This is actually a misusage of SpiderMonkey API.  Quote from a comment
in js/Initialization.h (both mozjs-78 and mozjs-91):

    It is currently not possible to initialize SpiderMonkey multiple
    times (that is, calling JS_Init/JSAPI methods/JS_ShutDown in that
    order, then doing so again).

This misusage does not cause severe issues with mozjs-78.  However, when
we eventually port jsauthority to use mozjs-91, bad thing will happen:
see the test failure mentioned in #150.

This commit is tested with both mozjs-78 and mozjs-91, all tests pass
with it.

Upstream-Status: Submitted [https://gitlab.freedesktop.org/polkit/polkit/-/merge_requests/91]
Signed-off-by: Alexander Kanavin <alex@linutronix.de>
---
 src/polkitbackend/polkitbackendjsauthority.cpp | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/polkitbackend/polkitbackendjsauthority.cpp b/src/polkitbackend/polkitbackendjsauthority.cpp
index 41d8d5c..38dc001 100644
--- a/src/polkitbackend/polkitbackendjsauthority.cpp
+++ b/src/polkitbackend/polkitbackendjsauthority.cpp
@@ -75,6 +75,13 @@
 
 /* ---------------------------------------------------------------------------------------------------- */
 
+static class JsInitHelperType
+{
+public:
+	JsInitHelperType() { JS_Init(); }
+	~JsInitHelperType() { JS_ShutDown(); }
+} JsInitHelper;
+
 struct _PolkitBackendJsAuthorityPrivate
 {
   gchar **rules_dirs;
@@ -589,7 +596,6 @@ polkit_backend_js_authority_finalize (GObject *object)
   delete authority->priv->js_polkit;
 
   JS_DestroyContext (authority->priv->cx);
-  /* JS_ShutDown (); */
 
   G_OBJECT_CLASS (polkit_backend_js_authority_parent_class)->finalize (object);
 }
@@ -665,8 +671,6 @@ polkit_backend_js_authority_class_init (PolkitBackendJsAuthorityClass *klass)
 
 
   g_type_class_add_private (klass, sizeof (PolkitBackendJsAuthorityPrivate));
-
-  JS_Init ();
 }
 
 /* ---------------------------------------------------------------------------------------------------- */