diff --git a/src/run-js-test.c b/src/run-js-test.c index ba5e875e8..b2cbd82b7 100644 --- a/src/run-js-test.c +++ b/src/run-js-test.c @@ -36,13 +36,6 @@ #include "shell-global.h" #include "shell-global-private.h" -static char *command = NULL; - -static GOptionEntry entries[] = { - { "command", 'c', 0, G_OPTION_ARG_STRING, &command, "Program passed in as a string", "COMMAND" }, - { NULL } -}; - int main(int argc, char **argv) { @@ -50,10 +43,8 @@ main(int argc, char **argv) GError *error = NULL; ShellGlobal *global; GjsContext *js_context; - char *script; const char *filename; char *title; - gsize len; int code; context = g_option_context_new (NULL); @@ -61,7 +52,6 @@ main(int argc, char **argv) /* pass unknown through to the JS script */ g_option_context_set_ignore_unknown_options (context, TRUE); - g_option_context_add_main_entries (context, entries, NULL); if (!g_option_context_parse (context, &argc, &argv, &error)) g_error ("option parsing failed: %s", error->message); @@ -79,32 +69,21 @@ main(int argc, char **argv) exit (1); } - if (command != NULL) { - script = command; - len = strlen (script); - filename = ""; - } else if (argc <= 1) { - script = g_strdup ("const Console = imports.console; Console.interact();"); - len = strlen (script); - filename = ""; - } else /*if (argc >= 2)*/ { - error = NULL; - if (!g_file_get_contents (argv[1], &script, &len, &error)) { - g_printerr ("%s\n", error->message); - exit (1); - } - filename = argv[1]; + if (argc < 2) { + g_printerr ("Missing filename"); + exit(1); } + filename = argv[1]; title = g_filename_display_basename (filename); g_set_prgname (title); g_free (title); - /* evaluate the script */ error = NULL; - if (!gjs_context_eval (js_context, script, len, - filename, &code, &error)) { - g_free (script); + + /* evaluate the script */ + bool success = gjs_context_eval_file(js_context, filename, &code, &error); + if (!success) { g_printerr ("%s\n", error->message); exit (1); } @@ -113,6 +92,5 @@ main(int argc, char **argv) gjs_context_gc (js_context); g_object_unref (js_context); - g_free (script); exit (code); }