Now that polkitbackendjsauthority is compiling in C++ mode and the autoconf supports mozjs24, update the module so that it builds with mozjs24.
Signed-off-by: Jeremy Linton <jeremy.lin...@arm.com> --- src/polkitbackend/polkitbackendjsauthority.cpp | 71 ++++++++++++++++++-------- 1 file changed, 51 insertions(+), 20 deletions(-) diff --git a/src/polkitbackend/polkitbackendjsauthority.cpp b/src/polkitbackend/polkitbackendjsauthority.cpp index 2112868..e16f7e1 100644 --- a/src/polkitbackend/polkitbackendjsauthority.cpp +++ b/src/polkitbackend/polkitbackendjsauthority.cpp @@ -92,7 +92,7 @@ struct _PolkitBackendJsAuthorityPrivate }; static JSBool execute_script_with_runaway_killer (PolkitBackendJsAuthority *authority, -#if JS_VERSION == 186 +#if JS_VERSION == 186 || JS_VERSION2 == 24 JSScript *script, #else JSObject *script, @@ -163,7 +163,7 @@ static JSClass js_global_class = { JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, -#if JS_VERSION == 186 +#if JS_VERSION == 186 || JS_VERSION2 == 24 NULL, #else JS_FinalizeStub, @@ -183,7 +183,7 @@ static JSClass js_polkit_class = { JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, -#if JS_VERSION == 186 +#if JS_VERSION == 186 || JS_VERSION2 == 24 NULL, #else JS_FinalizeStub, @@ -300,22 +300,28 @@ load_scripts (PolkitBackendJsAuthority *authority) for (l = files; l != NULL; l = l->next) { const gchar *filename = l->data; -#if JS_VERSION == 186 +#if JS_VERSION2 == 24 + JS::RootedScript script(authority->priv->cx); + JSString * str = JS_NewStringCopyZ(authority->priv->cx, filename); + JS::CompileOptions options(authority->priv->cx); + JS::RootedObject obj(authority->priv->cx,authority->priv->js_global); + options.setUTF8(true); + script = JS::Compile (authority->priv->cx, + obj, options, + JSAutoByteString(authority->priv->cx,str).ptr()); + +#elif JS_VERSION == 186 JSScript *script; -#else - JSObject *script; -#endif - -#if JS_VERSION == 186 script = JS_CompileUTF8File (authority->priv->cx, - authority->priv->js_global, - filename); - + authority->priv->js_global, + filename); #else + JSObject *script; script = JS_CompileFile (authority->priv->cx, - authority->priv->js_global, - filename); + authority->priv->js_global, + filename); #endif + if (script == NULL) { polkit_backend_authority_log (POLKIT_BACKEND_AUTHORITY (authority), @@ -355,6 +361,10 @@ reload_scripts (PolkitBackendJsAuthority *authority) JS_BeginRequest (authority->priv->cx); +#if JS_VERSION2 == 24 + JSAutoCompartment ac(authority->priv->cx, authority->priv->js_global); +#endif + if (!JS_CallFunctionName(authority->priv->cx, authority->priv->js_polkit, "_deleteRules", @@ -369,7 +379,7 @@ reload_scripts (PolkitBackendJsAuthority *authority) polkit_backend_authority_log (POLKIT_BACKEND_AUTHORITY (authority), "Collecting garbage unconditionally..."); -#if JS_VERSION == 186 +#if JS_VERSION == 186 || JS_VERSION2 == 24 JS_GC (authority->priv->rt); #else JS_GC (authority->priv->cx); @@ -465,7 +475,11 @@ polkit_backend_js_authority_constructed (GObject *object) PolkitBackendJsAuthority *authority = POLKIT_BACKEND_JS_AUTHORITY (object); gboolean entered_request = FALSE; +#if JS_VERSION2 == 24 + authority->priv->rt = JS_NewRuntime (8L * 1024L * 1024L,JS_USE_HELPER_THREADS); +#else authority->priv->rt = JS_NewRuntime (8L * 1024L * 1024L); +#endif if (authority->priv->rt == NULL) goto fail; @@ -479,20 +493,28 @@ polkit_backend_js_authority_constructed (GObject *object) JS_SetOptions (authority->priv->cx, JSOPTION_VAROBJFIX /* | JSOPTION_JIT | JSOPTION_METHODJIT*/); +#if JS_VERSION2 != 24 JS_SetVersion(authority->priv->cx, JSVERSION_LATEST); +#endif JS_SetErrorReporter(authority->priv->cx, report_error); JS_SetContextPrivate (authority->priv->cx, authority); JS_BeginRequest(authority->priv->cx); entered_request = TRUE; - authority->priv->js_global = + #if JS_VERSION == 186 - JS_NewGlobalObject (authority->priv->cx, &js_global_class, NULL); + authority->priv->js_global = JS_NewGlobalObject (authority->priv->cx, &js_global_class, NULL); +#elif JS_VERSION2 == 24 + JS::CompartmentOptions compart_opts; + compart_opts.setVersion(JSVERSION_LATEST); + authority->priv->js_global = JS_NewGlobalObject (authority->priv->cx, &js_global_class, NULL, compart_opts); + JSAutoCompartment ac(authority->priv->cx, authority->priv->js_global); #else - JS_NewCompartmentAndGlobalObject (authority->priv->cx, &js_global_class, NULL); + authority->priv->js_global = JS_NewCompartmentAndGlobalObject (authority->priv->cx, &js_global_class, NULL); #endif + if (authority->priv->js_global == NULL) goto fail; JS_AddObjectRoot (authority->priv->cx, &authority->priv->js_global); @@ -892,6 +914,7 @@ action_and_details_to_jsval (PolkitBackendJsAuthority *authority, guint n; src = "new Action();"; + if (!JS_EvaluateScript (authority->priv->cx, authority->priv->js_global, src, strlen (src), @@ -999,7 +1022,7 @@ rkt_on_timeout (gpointer user_data) g_mutex_unlock (&authority->priv->rkt_timeout_pending_mutex); /* Supposedly this is thread-safe... */ -#if JS_VERSION == 186 +#if JS_VERSION == 186 || JS_VERSION2 == 24 JS_TriggerOperationCallback (authority->priv->rt); #else JS_TriggerOperationCallback (authority->priv->cx); @@ -1041,7 +1064,7 @@ runaway_killer_teardown (PolkitBackendJsAuthority *authority) static JSBool execute_script_with_runaway_killer (PolkitBackendJsAuthority *authority, -#if JS_VERSION == 186 +#if JS_VERSION == 186 || JS_VERSION2 == 24 JSScript *script, #else JSObject *script, @@ -1103,6 +1126,10 @@ polkit_backend_js_authority_get_admin_auth_identities (PolkitBackendInteractiveA JS_BeginRequest (authority->priv->cx); +#if JS_VERSION2 == 24 + JSAutoCompartment ac(authority->priv->cx, authority->priv->js_global); +#endif + if (!action_and_details_to_jsval (authority, action_id, details, &argv[0], &error)) { polkit_backend_authority_log (POLKIT_BACKEND_AUTHORITY (authority), @@ -1212,6 +1239,10 @@ polkit_backend_js_authority_check_authorization_sync (PolkitBackendInteractiveAu JS_BeginRequest (authority->priv->cx); +#if JS_VERSION2 == 24 + JSAutoCompartment ac(authority->priv->cx, authority->priv->js_global); +#endif + if (!action_and_details_to_jsval (authority, action_id, details, &argv[0], &error)) { polkit_backend_authority_log (POLKIT_BACKEND_AUTHORITY (authority), -- 2.9.2 _______________________________________________ polkit-devel mailing list polkit-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/polkit-devel