~jbicha/ubuntu/oneiric/gjs/1.29.18

« back to all changes in this revision

Viewing changes to gjs/console.c

  • Committer: Bazaar Package Importer
  • Author(s): Laurent Bigonville
  • Date: 2011-02-06 13:01:02 UTC
  • mfrom: (1.3.10 experimental)
  • Revision ID: james.westby@ubuntu.com-20110206130102-69xpqq0gql9fob01
Tags: 0.7.10-1
* New upstream release.
* debian/control.in:
  - Drop build-depend on libmozjs-dev
  - Make libgjs-dev depend on xulrunner-dev and libdbus-1-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
 
31
31
static char **include_path = NULL;
32
32
static char *command = NULL;
 
33
static char *js_version= NULL;
33
34
 
34
35
static GOptionEntry entries[] = {
35
36
    { "command", 'c', 0, G_OPTION_ARG_STRING, &command, "Program passed in as a string", "COMMAND" },
36
37
    { "include-path", 'I', 0, G_OPTION_ARG_STRING_ARRAY, &include_path, "Add the directory DIR to the list of directories to search for js files.", "DIR" },
 
38
    { "js-version", 0, 0, G_OPTION_ARG_STRING, &js_version, "JavaScript version (e.g. \"default\", \"1.8\"", "JSVERSION" },
37
39
    { NULL }
38
40
};
39
41
 
48
50
    const char *filename;
49
51
    gsize len;
50
52
    int code;
 
53
    const char *source_js_version;
51
54
 
52
55
    g_thread_init(NULL);
53
56
 
67
70
    g_debug("Command line: %s", command_line);
68
71
    g_free(command_line);
69
72
 
70
 
    g_debug("Creating new context to eval console script");
71
 
    js_context = gjs_context_new_with_search_path(include_path);
72
 
 
73
 
    /* prepare command line arguments */
74
 
    if (!gjs_context_define_string_array(js_context, "ARGV",
75
 
                                         argc - 2, (const char**)argv + 2,
76
 
                                         &error)) {
77
 
        g_printerr("Failed to defined ARGV: %s", error->message);
78
 
        exit(1);
79
 
    }
80
 
 
81
73
    if (command != NULL) {
82
74
        script = command;
 
75
        source_js_version = gjs_context_scan_buffer_for_js_version(script, 1024);
83
76
        len = strlen(script);
84
77
        filename = "<command line>";
85
78
    } else if (argc <= 1) {
 
79
        source_js_version = "default";
86
80
        script = g_strdup("const Console = imports.console; Console.interact();");
87
81
        len = strlen(script);
88
82
        filename = "<stdin>";
92
86
            g_printerr("%s\n", error->message);
93
87
            exit(1);
94
88
        }
 
89
        source_js_version = gjs_context_scan_buffer_for_js_version(script, 1024);
95
90
        filename = argv[1];
96
91
    }
97
92
 
 
93
    g_debug("Creating new context to eval console script");
 
94
    /* If user explicitly specifies a version, use it */
 
95
    if (js_version != NULL)
 
96
        source_js_version = js_version;
 
97
    js_context = g_object_new(GJS_TYPE_CONTEXT, "search-path", include_path,
 
98
                              "js-version", source_js_version, NULL);
 
99
 
 
100
    /* prepare command line arguments */
 
101
    if (!gjs_context_define_string_array(js_context, "ARGV",
 
102
                                         argc - 2, (const char**)argv + 2,
 
103
                                         &error)) {
 
104
        g_printerr("Failed to defined ARGV: %s", error->message);
 
105
        exit(1);
 
106
    }
 
107
 
98
108
    /* evaluate the script */
99
109
    error = NULL;
100
110
    if (!gjs_context_eval(js_context, script, len,