diff options
author | Ray Strode <rstrode@redhat.com> | 2018-03-22 13:00:33 -0400 |
---|---|---|
committer | Ray Strode <rstrode@redhat.com> | 2018-04-03 14:16:40 -0400 |
commit | 84bfad02e91a529d63b44e7f27f62cce6e559a70 (patch) | |
tree | f64b0a2e11902e1007713e353a2027838d3e9110 /src/polkitbackend | |
parent | b69e2f7cff4f93dad29ec629aca1a0a0d604f557 (diff) | |
download | polkit-84bfad02e91a529d63b44e7f27f62cce6e559a70.tar.gz |
jsauthority: redo how global objects are set up
This commit drops usage of JS_AddObjectRoot and switches
the global object over to being wrapped in a JS::Heap
pointer. It stops using JS_DefineObject which no longer
seems to be available, and adds a new JS::FireOnNewGlobalHook
which seems to be required.
Signed-off-by: Ray Strode <rstrode@redhat.com>
https://bugs.freedesktop.org/show_bug.cgi?id=105865
Diffstat (limited to 'src/polkitbackend')
-rw-r--r-- | src/polkitbackend/polkitbackendjsauthority.cpp | 48 |
1 files changed, 25 insertions, 23 deletions
diff --git a/src/polkitbackend/polkitbackendjsauthority.cpp b/src/polkitbackend/polkitbackendjsauthority.cpp index 830f5cd..be83df8 100644 --- a/src/polkitbackend/polkitbackendjsauthority.cpp +++ b/src/polkitbackend/polkitbackendjsauthority.cpp @@ -75,9 +75,9 @@ struct _PolkitBackendJsAuthorityPrivate GFileMonitor **dir_monitors; /* NULL-terminated array of GFileMonitor instances */ JSContext *cx; - JSObject *js_global; + JS::Heap<JSObject*> *js_global; JSAutoCompartment *ac; - JSObject *js_polkit; + JS::Heap<JSObject*> *js_polkit; GThread *runaway_killer_thread; GMainContext *rkt_context; @@ -478,38 +478,42 @@ polkit_backend_js_authority_constructed (GObject *object) { JS::CompartmentOptions compart_opts; compart_opts.behaviors().setVersion(JSVERSION_LATEST); - authority->priv->js_global = JS_NewGlobalObject (authority->priv->cx, &js_global_class, NULL, compart_opts); + JS::RootedObject global(authority->priv->cx); - if (authority->priv->js_global == NULL) + authority->priv->js_global = new JS::Heap<JSObject*> (JS_NewGlobalObject (authority->priv->cx, &js_global_class, NULL, JS::FireOnNewGlobalHook, compart_opts)); + + global = authority->priv->js_global->get (); + + if (global == NULL) goto fail; - authority->priv->ac = new JSAutoCompartment(authority->priv->cx, authority->priv->js_global); + authority->priv->ac = new JSAutoCompartment(authority->priv->cx, global); if (authority->priv->ac == NULL) goto fail; - JS_AddObjectRoot (authority->priv->cx, &authority->priv->js_global); + if (!JS_InitStandardClasses (authority->priv->cx, global)) + goto fail; + + JS::RootedObject polkit(authority->priv->cx); + + authority->priv->js_polkit = new JS::Heap<JSObject *> (JS_NewObject (authority->priv->cx, &js_polkit_class)); - if (!JS_InitStandardClasses (authority->priv->cx, authority->priv->js_global)) + polkit = authority->priv->js_polkit->get (); + + if (polkit == NULL) goto fail; - authority->priv->js_polkit = JS_DefineObject (authority->priv->cx, - authority->priv->js_global, - "polkit", - &js_polkit_class, - NULL, - JSPROP_ENUMERATE); - if (authority->priv->js_polkit == NULL) + if (!JS_DefineProperty(authority->priv->cx, global, "polkit", polkit, JSPROP_ENUMERATE)) goto fail; - JS_AddObjectRoot (authority->priv->cx, &authority->priv->js_polkit); if (!JS_DefineFunctions (authority->priv->cx, - authority->priv->js_polkit, + polkit, js_polkit_functions)) goto fail; if (!JS_EvaluateScript (authority->priv->cx, - authority->priv->js_global, + global, init_js, strlen (init_js), /* init.js */ "init.js", /* filename */ 0, /* lineno */ @@ -573,11 +577,7 @@ polkit_backend_js_authority_finalize (GObject *object) g_free (authority->priv->dir_monitors); g_strfreev (authority->priv->rules_dirs); - JS_BeginRequest (authority->priv->cx); - JS_RemoveObjectRoot (authority->priv->cx, &authority->priv->js_polkit); delete authority->priv->ac; - JS_RemoveObjectRoot (authority->priv->cx, &authority->priv->js_global); - JS_EndRequest (authority->priv->cx); JS_DestroyContext (authority->priv->cx); /* JS_ShutDown (); */ @@ -750,10 +750,11 @@ subject_to_jsval (PolkitBackendJsAuthority *authority, 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, - authority->priv->js_global, + global, src, strlen (src), __FILE__, __LINE__, &ret_jsval)) @@ -875,10 +876,11 @@ action_and_details_to_jsval (PolkitBackendJsAuthority *authority, JSObject *obj; gchar **keys; guint n; + JS::RootedObject global(authority->priv->cx, authority->priv->js_global->get ()); src = "new Action();"; if (!JS_EvaluateScript (authority->priv->cx, - authority->priv->js_global, + global, src, strlen (src), __FILE__, __LINE__, &ret_jsval)) |