Support xulrunner 1.9.3+

Add small wrappers around JS_AddValueRoot.
Add JS_BeginRequest in our custom code.

https://bugzilla.gnome.org/show_bug.cgi?id=630539
This commit is contained in:
Colin Walters 2010-09-24 14:02:04 -04:00 committed by Owen W. Taylor
parent 61c906807b
commit 11db188fe9
4 changed files with 70 additions and 17 deletions

View File

@ -77,13 +77,12 @@ PKG_CHECK_MODULES(MUTTER_PLUGIN, gio-2.0 >= $GIO_MIN_VERSION
libstartup-notification-1.0
gobject-introspection-1.0 >= $GOBJECT_INTROSPECTION_MIN_VERSION)
# This is for the newly added application id bits, we can replace this with
# a version check later
saved_CFLAGS=$CFLAGS
saved_LIBS=$LIBS
CFLAGS=$MUTTER_PLUGIN_CFLAGS
LIBS=$MUTTER_PLUGIN_LIBS
AC_CHECK_FUNCS(sn_startup_sequence_get_application_id)
# sn_startup_sequence_get_application_id, we can replace with a version check later
AC_CHECK_FUNCS(JS_NewGlobalObject sn_startup_sequence_get_application_id)
CFLAGS=$saved_CFLAGS
LIBS=$saved_LIBS

View File

@ -87,6 +87,7 @@ libgnome_shell_la_SOURCES = \
shell-app-private.h \
shell-embedded-window-private.h \
shell-global-private.h \
shell-jsapi-compat-private.h \
shell-window-tracker-private.h \
shell-wm-private.h \
gnome-shell-plugin.c \

View File

@ -27,6 +27,7 @@
#ifdef HAVE_SYS_RESOURCE_H
#include <sys/resource.h>
#endif
#include "shell-jsapi-compat-private.h"
#define SHELL_DBUS_SERVICE "org.gnome.Shell"
#define MAGNIFIER_DBUS_SERVICE "org.gnome.Magnifier"
@ -810,6 +811,8 @@ shell_global_add_extension_importer (ShellGlobal *global,
JSContext *context = gjs_context_get_native_context (global->js_context);
char *search_path[2] = { 0, 0 };
JS_BeginRequest (context);
// This is a bit of a hack; ideally we'd be able to pass our target
// object directly into this function, but introspection doesn't
// support that at the moment. Instead evaluate a string to get it.
@ -829,18 +832,22 @@ shell_global_add_extension_importer (ShellGlobal *global,
G_IO_ERROR_FAILED,
"%s", message ? message : "(unknown)");
g_free(message);
return FALSE;
goto out_error;
}
if (!JSVAL_IS_OBJECT (target_object))
{
g_error ("shell_global_add_extension_importer: invalid target object");
return FALSE;
goto out_error;
}
search_path[0] = (char*)directory;
importer = gjs_define_importer (context, JSVAL_TO_OBJECT (target_object), target_property, (const char **)search_path, FALSE);
JS_EndRequest (context);
return TRUE;
out_error:
JS_EndRequest (context);
return FALSE;
}
/* Code to close all file descriptors before we exec; copied from gspawn.c in GLib.
@ -1604,7 +1611,8 @@ shell_global_set_property_mutable (ShellGlobal *global,
jsuint attrs;
JSBool found;
JS_AddRoot (context, &val);
JS_BeginRequest (context);
JS_AddValueRoot (context, &val);
parts = g_strsplit (object, ".", -1);
obj = JS_GetGlobalObject (context);
@ -1613,30 +1621,31 @@ shell_global_set_property_mutable (ShellGlobal *global,
if (!JS_GetProperty (context, obj, parts[i], &val))
{
g_strfreev (parts);
JS_RemoveRoot (context, &val);
gjs_log_exception (context, NULL);
return FALSE;
goto out_error;
}
obj = JSVAL_TO_OBJECT (val);
}
g_strfreev (parts);
if (!JS_GetPropertyAttributes (context, obj, property, &attrs, &found) || !found)
{
JS_RemoveRoot (context, &val);
gjs_log_exception (context, NULL);
return FALSE;
}
goto out_error;
if (mutable)
attrs &= ~(JSPROP_PERMANENT | JSPROP_READONLY);
else
attrs |= (JSPROP_PERMANENT | JSPROP_READONLY);
JS_SetPropertyAttributes (context, obj, property, attrs, &found);
if (!JS_SetPropertyAttributes (context, obj, property, attrs, &found))
goto out_error;
JS_RemoveRoot (context, &val);
return !gjs_log_exception (context, NULL);
JS_RemoveValueRoot (context, &val);
JS_EndRequest (context);
return TRUE;
out_error:
gjs_log_exception (context, NULL);
JS_RemoveValueRoot (context, &val);
JS_EndRequest (context);
return FALSE;
}
typedef struct

View File

@ -0,0 +1,44 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
/*
* shell-jsapi-compat.h: Compatibility wrapper for older Spidermonkey
*
* Copyright 2010 Red Hat, Inc.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU Lesser General Public License,
* version 2.1, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
* more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
* Boston, MA 02111-1307, USA.
*
*/
#ifndef __SHELL_JSAPI_COMPAT_H__
#define __SHELL_JSAPI_COMPAT_H__
#include "config.h"
#ifndef HAVE_JS_NEWGLOBALOBJECT
/* The old JS_AddRoot accepted anything via void *, new
* api is stricter.
*/
#define JS_AddValueRoot JS_AddRoot
#define JS_AddObjectRoot JS_AddRoot
#define JS_AddStringRoot JS_AddRoot
#define JS_AddGCThingRoot JS_AddRoot
#define JS_RemoveValueRoot JS_RemoveRoot
#define JS_RemoveObjectRoot JS_RemoveRoot
#define JS_RemoveStringRoot JS_RemoveRoot
#define JS_RemoveGCThingRoot JS_RemoveRoot
#endif
#endif