Skip to content

Instantly share code, notes, and snippets.

@smspillaz
Created December 22, 2013 22:49
Show Gist options
  • Save smspillaz/8089397 to your computer and use it in GitHub Desktop.
Save smspillaz/8089397 to your computer and use it in GitHub Desktop.
typedef struct _ChangeDebugModeData
{
guint flags;
gboolean enabled;
} ChangeDebugModeData;
typedef void (*LockAction) (JSContext *context,
gpointer user_data);
static void
lock_and_perform_if_unlocked (GjsContext *context,
guint *lock_count,
LockAction action,
gpointer user_data)
{
if ((*lock_count)++ == 0)
{
JSContext *js_context = (JSContext *) gjs_context_get_native_context (context);
(*action) (js_context, user_data);
}
}
static void
unlock_and_perform_if_locked (GjsContext *context,
guint *lock_count,
LockAction action,
gpointer user_data)
{
if (--(*lock_count) == 0)
{
JSContext *js_context = (JSContext *) gjs_context_get_native_context (context);
(*action) (js_context, user_data);
}
}
static void
change_debug_mode (JSContext *context,
gpointer user_data)
{
ChangeDebugModeData *data = (ChangeDebugModeData *) user_data;
JS_BeginRequest (context);
JS_SetOptions (context, data->flags);
JS_SetDebugMode (context, data->enabled);
JS_EndRequest (context);
}
static void
gjs_debug_interrupt_register_lock_debug_mode (GjsDebugInterruptRegister *reg)
{
ChangeDebugModeData data =
{
JSOPTION_METHODJIT | JSOPTION_TYPE_INFERENCE,
TRUE
};
lock_and_perform_if_unlocked (reg->priv->context,
&reg->priv->debug_mode_lock_count,
change_debug_mode,
&data);
}
static void
gjs_debug_interrupt_register_unlock_debug_mode (GjsDebugInterruptRegister *reg)
{
ChangeDebugModeData data =
{
0,
FALSE
};
unlock_and_perform_if_locked (reg->priv->context,
&reg->priv->debug_mode_lock_count,
change_debug_mode,
&data);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment