[gjs] xulrunner2: Conditionnaly adapt to JS_GetFunctionName removal
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs] xulrunner2: Conditionnaly adapt to JS_GetFunctionName removal
- Date: Wed, 15 Dec 2010 22:20:02 +0000 (UTC)
commit aa8e8aa60a172f13757d5f0e374c009ffdb9ccfa
Author: Marc-Antoine Perennou <Marc-Antoine Perennou com>
Date: Tue Dec 14 18:23:29 2010 +0100
xulrunner2: Conditionnaly adapt to JS_GetFunctionName removal
Upstream removed JS_GetFunctionName in commit:
http://hg.mozilla.org/mozilla-central/changeset/e35b70ffed69
We now have to use JS_GetFunctionId which returns a JSString*
instead of a const char*
https://bugzilla.gnome.org/show_bug.cgi?id=637246
configure.ac | 1 +
gjs/profiler.c | 27 ++++++++++++++++++++++-----
gjs/stack.c | 23 +++++++++++++++++++----
3 files changed, 42 insertions(+), 9 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 9d3f829..13db4f5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -147,6 +147,7 @@ else
fi
AC_CHECK_LIB([mozjs], [JS_GetStringBytes], AC_DEFINE([HAVE_JS_GETSTRINGBYTES], [1], [Define if we still have JS_GetStringBytes]),, [$JS_LIBS])
+AC_CHECK_LIB([mozjs], [JS_GetFunctionName], AC_DEFINE([HAVE_JS_GETFUNCTIONNAME], [1], [Define if we still have JS_GetFunctionName]),, [$JS_LIBS])
AC_MSG_CHECKING([for mozilla-js >= 2 ])
if `$PKG_CONFIG --exists $JS_PACKAGE '>=' 2`; then
diff --git a/gjs/profiler.c b/gjs/profiler.c
index c579400..327a33a 100644
--- a/gjs/profiler.c
+++ b/gjs/profiler.c
@@ -26,6 +26,7 @@
#include "profiler.h"
#include <jsdbgapi.h>
#include "compat.h"
+#include "jsapi-util.h"
#include <signal.h>
#include <sys/types.h>
@@ -109,7 +110,8 @@ gjs_profile_function_new(GjsProfileFunctionKey *key)
self = g_slice_new0(GjsProfileFunction);
self->key.filename = g_strdup(key->filename);
self->key.lineno = key->lineno;
- self->key.function_name = g_strdup(key->function_name);
+ // Pass ownership of function_name from key to the new function
+ self->key.function_name = key->function_name;
g_assert(self->key.filename != NULL);
g_assert(self->key.function_name != NULL);
@@ -132,6 +134,7 @@ gjs_profile_function_key_from_js(JSContext *cx,
{
JSScript *script;
JSFunction *function;
+ JSString *function_name = NULL;
/* We're not using the JSScript or JSFunction as the key since the script
* could be unloaded and addresses reused.
@@ -151,8 +154,15 @@ gjs_profile_function_key_from_js(JSContext *cx,
* (or other object with a 'call' method) and would be good to somehow
* figure out the name of the called function.
*/
- key->function_name = (char*)(function != NULL ? JS_GetFunctionName(function) : "(unknown)");
-
+#ifdef HAVE_JS_GETFUNCTIONNAME
+ key->function_name = g_strdup(function != NULL ? JS_GetFunctionName(function) : "(unknown)");
+#else
+ function_name = JS_GetFunctionId(function);
+ if (function_name)
+ key->function_name = gjs_string_get_ascii(cx, STRING_TO_JSVAL(function_name));
+ else
+ key->function_name = g_strdup("(unknown)");
+#endif
g_assert(key->filename != NULL);
g_assert(key->function_name != NULL);
@@ -171,16 +181,23 @@ gjs_profiler_lookup_function(GjsProfiler *self,
function = g_hash_table_lookup(self->by_file, &key);
if (function)
- return function;
+ goto error;
if (!create_if_missing)
- return NULL;
+ goto error;
function = gjs_profile_function_new(&key);
g_hash_table_insert(self->by_file, &function->key, function);
+ /* Don't free key.function_name if we get here since we passed its
+ * ownership to the new function.
+ */
return function;
+
+ error:
+ g_free(key.function_name);
+ return NULL;
}
static void
diff --git a/gjs/stack.c b/gjs/stack.c
index 6e2b987..6c852c1 100644
--- a/gjs/stack.c
+++ b/gjs/stack.c
@@ -83,7 +83,8 @@ format_frame(JSContext* cx, JSStackFrame* fp,
JSPropertyDescArray call_props = { 0, NULL };
JSObject* this_obj = NULL;
JSObject* call_obj = NULL;
- const char* funname = NULL;
+ JSString* funname = NULL;
+ char* funname_str = NULL;
const char* filename = NULL;
guint32 lineno = 0;
guint32 named_arg_count = 0;
@@ -115,7 +116,11 @@ format_frame(JSContext* cx, JSStackFrame* fp,
lineno = (guint32) JS_PCToLineNumber(cx, script, pc);
fun = JS_GetFrameFunction(cx, fp);
if (fun)
- funname = JS_GetFunctionName(fun);
+#ifdef HAVE_JS_GETFUNCTIONNAME
+ funname_str = JS_GetFunctionName(fun);
+#else
+ funname = JS_GetFunctionId(fun);
+#endif
call_obj = JS_GetFrameCallObject(cx, fp);
if (call_obj) {
@@ -140,8 +145,18 @@ format_frame(JSContext* cx, JSStackFrame* fp,
/* print the frame number and function name */
- if (funname)
- g_string_append_printf(buf, "%d %s(", num, funname);
+#ifndef HAVE_JS_GETFUNCTIONNAME
+ if (funname) {
+ funname_str = gjs_string_get_ascii(cx, STRING_TO_JSVAL(funname));
+ g_string_append_printf(buf, "%d %s(", num, funname_str);
+ }
+#endif
+ if (funname_str) {
+ g_string_append_printf(buf, "%d %s(", num, funname_str);
+#ifndef HAVE_JS_GETFUNCTIONNAME
+ g_free(funname_str);
+#endif
+ }
else if (fun)
g_string_append_printf(buf, "%d anonymous(", num);
else
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]