Add a hack to block calls to certain introspected functions
This is useful for keeping people from using methods that only fail in certain circumstances, by making them fail in all circumstances instead. https://bugzilla.gnome.org/show_bug.cgi?id=618918
This commit is contained in:
@ -1327,3 +1327,68 @@ shell_global_create_app_launch_context (ShellGlobal *global)
|
||||
|
||||
return (GAppLaunchContext *)context;
|
||||
}
|
||||
|
||||
/**
|
||||
* shell_global_set_property_mutable:
|
||||
* @global: the #ShellGlobal
|
||||
* @object: the "path" to a JS object, starting from the root object.
|
||||
* (Eg, "global.stage" or "imports.gi.Gtk.Window.prototype")
|
||||
* @property: a property on @object
|
||||
* @mutable: %TRUE or %FALSE
|
||||
*
|
||||
* If @mutable is %TRUE, this clears the "permanent" and "readonly" flags
|
||||
* on @property of @object. If @mutable is %FALSE, it sets them.
|
||||
*
|
||||
* You can use this to make it possible to modify properties that
|
||||
* would otherwise be read-only from JavaScript.
|
||||
*
|
||||
* Return value: success or failure.
|
||||
*/
|
||||
gboolean
|
||||
shell_global_set_property_mutable (ShellGlobal *global,
|
||||
const char *object,
|
||||
const char *property,
|
||||
gboolean mutable)
|
||||
{
|
||||
JSContext *context = gjs_context_get_native_context (global->js_context);
|
||||
char **parts;
|
||||
JSObject *obj;
|
||||
jsval val = JSVAL_VOID;
|
||||
int i;
|
||||
jsuint attrs;
|
||||
JSBool found;
|
||||
|
||||
JS_AddRoot (context, &val);
|
||||
|
||||
parts = g_strsplit (object, ".", -1);
|
||||
obj = JS_GetGlobalObject (context);
|
||||
for (i = 0; parts[i]; i++)
|
||||
{
|
||||
if (!JS_GetProperty (context, obj, parts[i], &val))
|
||||
{
|
||||
g_strfreev (parts);
|
||||
JS_RemoveRoot (context, &val);
|
||||
gjs_log_exception (context, NULL);
|
||||
return FALSE;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
if (mutable)
|
||||
attrs &= ~(JSPROP_PERMANENT | JSPROP_READONLY);
|
||||
else
|
||||
attrs |= (JSPROP_PERMANENT | JSPROP_READONLY);
|
||||
|
||||
JS_SetPropertyAttributes (context, obj, property, attrs, &found);
|
||||
|
||||
JS_RemoveRoot (context, &val);
|
||||
return !gjs_log_exception (context, NULL);
|
||||
}
|
||||
|
Reference in New Issue
Block a user