~jbicha/ubuntu/oneiric/gjs/1.29.18

« back to all changes in this revision

Viewing changes to gjs/stack.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:
46
46
#include <jsdbgapi.h>
47
47
#include "context.h"
48
48
#include "compat.h"
 
49
#include "jsapi-util.h"
49
50
 
50
 
static const char*
 
51
static char*
51
52
jsvalue_to_string(JSContext* cx, jsval val, gboolean* is_string)
52
53
{
53
 
    const char* value = NULL;
 
54
    char* value = NULL;
54
55
    JSString* value_str;
55
56
 
56
57
    (void)JS_EnterLocalRootScope(cx);
57
58
 
58
59
    value_str = JS_ValueToString(cx, val);
59
60
    if (value_str)
60
 
        value = JS_GetStringBytes(value_str);
 
61
        value = gjs_value_debug_string(cx, val);
61
62
    if (value) {
62
63
        const char* found = strstr(value, "function ");
63
 
        if(found && (value == found || value+1 == found || value+2 == found))
64
 
            value = "[function]";
 
64
        if(found && (value == found || value+1 == found || value+2 == found)) {
 
65
            g_free(value);
 
66
            value = g_strdup("[function]");
 
67
        }
65
68
    }
66
69
 
67
70
    if (is_string)
80
83
    JSPropertyDescArray call_props = { 0, NULL };
81
84
    JSObject* this_obj = NULL;
82
85
    JSObject* call_obj = NULL;
83
 
    const char* funname = NULL;
 
86
    char* funname_str = NULL;
84
87
    const char* filename = NULL;
85
88
    guint32 lineno = 0;
86
89
    guint32 named_arg_count = 0;
111
114
        filename = JS_GetScriptFilename(cx, script);
112
115
        lineno =  (guint32) JS_PCToLineNumber(cx, script, pc);
113
116
        fun = JS_GetFrameFunction(cx, fp);
114
 
        if (fun)
115
 
            funname = JS_GetFunctionName(fun);
 
117
        if (fun) {
 
118
#ifdef HAVE_JS_GETFUNCTIONNAME
 
119
            funname_str = g_strdup(JS_GetFunctionName(fun));
 
120
#else
 
121
            JSString* funname = JS_GetFunctionId(fun);
 
122
            if (funname)
 
123
                funname_str = gjs_string_get_ascii(cx, STRING_TO_JSVAL(funname));
 
124
#endif
 
125
        }
116
126
 
117
127
        call_obj = JS_GetFrameCallObject(cx, fp);
118
128
        if (call_obj) {
137
147
 
138
148
    /* print the frame number and function name */
139
149
 
140
 
    if (funname)
141
 
        g_string_append_printf(buf, "%d %s(", num, funname);
 
150
    if (funname_str) {
 
151
        g_string_append_printf(buf, "%d %s(", num, funname_str);
 
152
        g_free(funname_str);
 
153
    }
142
154
    else if (fun)
143
155
        g_string_append_printf(buf, "%d anonymous(", num);
144
156
    else
145
157
        g_string_append_printf(buf, "%d <TOP LEVEL>", num);
146
158
 
147
159
    for (i = 0; i < call_props.length; i++) {
148
 
        const char *name;
149
 
        const char *value;
 
160
        char *name;
 
161
        char *value;
150
162
        JSPropertyDesc* desc = &call_props.array[i];
151
163
        if(desc->flags & JSPD_ARGUMENT) {
152
164
            name = jsvalue_to_string(cx, desc->id, &is_string);
153
 
            if(!is_string)
 
165
            if(!is_string) {
 
166
                g_free(name);
154
167
                name = NULL;
 
168
            }
155
169
            value = jsvalue_to_string(cx, desc->value, &is_string);
156
170
 
157
171
            g_string_append_printf(buf, "%s%s%s%s%s%s",
163
177
                                   is_string ? "\"" : "");
164
178
            named_arg_count++;
165
179
        }
 
180
        g_free(name);
 
181
        g_free(value);
166
182
    }
167
183
 
168
184
    /* print any unnamed trailing args (found in 'arguments' object) */
181
197
                g_snprintf(number, 8, "%d", (int) k);
182
198
 
183
199
                if (JS_GetProperty(cx, args_obj, number, &val)) {
184
 
                    const char *value = jsvalue_to_string(cx, val, &is_string);
 
200
                    char *value = jsvalue_to_string(cx, val, &is_string);
185
201
                    g_string_append_printf(buf, "%s%s%s%s",
186
202
                                           k ? ", " : "",
187
203
                                           is_string ? "\"" : "",
188
204
                                           value ? value : "?unknown?",
189
205
                                           is_string ? "\"" : "");
 
206
                    g_free(value);
190
207
                }
191
208
            }
192
209
        }