Create and release script context for --run/ -r only when needed

This commit is contained in:
Christian Dywan 2010-01-29 21:12:14 +01:00
parent 9785317a88
commit 218a05049c

View file

@ -1448,24 +1448,24 @@ midori_load_session (gpointer data)
static gint static gint
midori_run_script (const gchar* filename) midori_run_script (const gchar* filename)
{ {
gchar* exception;
gchar* script;
GError* error;
if (!(filename)) if (!(filename))
{ {
g_print ("%s - %s\n", _("Midori"), _("No filename specified")); g_print ("%s - %s\n", _("Midori"), _("No filename specified"));
return 1; return 1;
} }
JSGlobalContextRef js_context; error = NULL;
gchar* exception;
gchar* script;
GError* error = NULL;
js_context = JSGlobalContextCreateInGroup (NULL, NULL);
if (g_file_get_contents (filename, &script, NULL, &error)) if (g_file_get_contents (filename, &script, NULL, &error))
{ {
JSGlobalContextRef js_context = JSGlobalContextCreateInGroup (NULL, NULL);
if (sokoke_js_script_eval (js_context, script, &exception)) if (sokoke_js_script_eval (js_context, script, &exception))
exception = NULL; exception = NULL;
g_free (script); g_free (script);
JSGlobalContextRelease (js_context);
} }
else if (error) else if (error)
{ {
@ -1475,7 +1475,6 @@ midori_run_script (const gchar* filename)
else else
exception = g_strdup (_("An unknown error occured.")); exception = g_strdup (_("An unknown error occured."));
JSGlobalContextRelease (js_context);
if (!exception) if (!exception)
return 0; return 0;