From cef9c0835bfd8be105ff8905083d6b51d9010b8f Mon Sep 17 00:00:00 2001 From: Marc-Antoine Perennou Date: Fri, 1 Apr 2011 21:04:57 +0200 Subject: [PATCH 1/4] Conditionally adapt to JS_DestroyScript removal Upstream changed the behaviour of several things about JSScripts in http://hg.mozilla.org/mozilla-central/rev/c919a7271ac1 We now have to use a JSObject instead of a JSScript in certain circumstances, and we no longer have to call JS_DestroyScript which no longer exists https://bugzilla.gnome.org/show_bug.cgi?id=646471 Conflicts: configure.ac --- configure.ac | 1 + modules/console.c | 6 ++++++ 2 files changed, 7 insertions(+), 0 deletions(-) diff --git a/configure.ac b/configure.ac index 715f2c3..f81704b 100644 --- a/configure.ac +++ b/configure.ac @@ -160,6 +160,7 @@ AC_CHECK_LIB([mozjs], [JS_GetFunctionName], AC_DEFINE([HAVE_JS_GETFUNCTIONNAME], AC_CHECK_LIB([mozjs], [JS_GetStringChars], AC_DEFINE([HAVE_JS_GETSTRINGCHARS], [1], [Define if we still have JS_GetStringChars]),, [$JS_LIBS]) AC_CHECK_LIB([mozjs], [JS_StrictPropertyStub], AC_DEFINE([HAVE_JS_STRICTPROPERTYSTUB], [1], [Define if we have JS_StrictPropertyStub]),, [$JS_LIBS]) AC_CHECK_LIB([mozjs], [JS_GetGlobalForScopeChain], AC_DEFINE([HAVE_JS_GETGLOBALFORSCOPECHAIN], [1], [Define if we have JS_GetGlobalForScopeChain]),, [$JS_LIBS]) +AC_CHECK_LIB([mozjs], [JS_DestroyScript], AC_DEFINE([HAVE_JS_DESTROYSCRIPT], [1], [Define if we still have JS_DestroyScript]),, [$JS_LIBS]) AC_MSG_CHECKING([for mozilla-js >= 2 ]) if `$PKG_CONFIG --exists $JS_PACKAGE '>=' 2`; then diff --git a/modules/console.c b/modules/console.c index 49f891b..e6945be 100644 --- a/modules/console.c +++ b/modules/console.c @@ -161,7 +161,11 @@ gjs_console_interact(JSContext *context, { JSObject *object = JS_THIS_OBJECT(context, vp); gboolean eof = FALSE; +#ifdef HAVE_JS_DESTROYSCRIPT JSScript *script = NULL; +#else + JSObject *script = NULL; +#endif jsval result; JSString *str; GString *buffer = NULL; @@ -219,8 +223,10 @@ gjs_console_interact(JSContext *context, } next: +#ifdef HAVE_JS_DESTROYSCRIPT if (script) JS_DestroyScript(context, script); +#endif g_string_free(buffer, TRUE); } while (!eof); -- 1.7.5.4 From 3c8396821c78e362c8b3a89a27dcf4d32e25ee05 Mon Sep 17 00:00:00 2001 From: Marc-Antoine Perennou Date: Fri, 29 Apr 2011 01:01:03 +0200 Subject: [PATCH 2/4] conditonally adapt to JS_BufferIsCompilableUnit changes Upstream added an argument to JS_BufferIsCompilableUnit in commit http://hg.mozilla.org/mozilla-central/rev/a773890b676f We now have to tell if the bytes are utf8 or not. https://bugzilla.gnome.org/show_bug.cgi?id=646471 --- configure.ac | 1 + modules/console.c | 4 ++++ 2 files changed, 5 insertions(+), 0 deletions(-) diff --git a/configure.ac b/configure.ac index f81704b..270bc46 100644 --- a/configure.ac +++ b/configure.ac @@ -161,6 +161,7 @@ AC_CHECK_LIB([mozjs], [JS_GetStringChars], AC_DEFINE([HAVE_JS_GETSTRINGCHARS], [ AC_CHECK_LIB([mozjs], [JS_StrictPropertyStub], AC_DEFINE([HAVE_JS_STRICTPROPERTYSTUB], [1], [Define if we have JS_StrictPropertyStub]),, [$JS_LIBS]) AC_CHECK_LIB([mozjs], [JS_GetGlobalForScopeChain], AC_DEFINE([HAVE_JS_GETGLOBALFORSCOPECHAIN], [1], [Define if we have JS_GetGlobalForScopeChain]),, [$JS_LIBS]) AC_CHECK_LIB([mozjs], [JS_DestroyScript], AC_DEFINE([HAVE_JS_DESTROYSCRIPT], [1], [Define if we still have JS_DestroyScript]),, [$JS_LIBS]) +AC_CHECK_LIB([mozjs], [JS_DecodeUTF8], AC_DEFINE([HAVE_JS_DECODEUTF8], [1], [Define if we have JS_DecodeUTF8]),, [$JS_LIBS]) AC_MSG_CHECKING([for mozilla-js >= 2 ]) if `$PKG_CONFIG --exists $JS_PACKAGE '>=' 2`; then diff --git a/modules/console.c b/modules/console.c index e6945be..8e20db3 100644 --- a/modules/console.c +++ b/modules/console.c @@ -196,7 +196,11 @@ gjs_console_interact(JSContext *context, g_string_append(buffer, temp_buf); g_free(temp_buf); lineno++; +#ifdef HAVE_JS_DECODEUTF8 + } while (!JS_BufferIsCompilableUnit(context, JS_TRUE, object, buffer->str, buffer->len)); +#else } while (!JS_BufferIsCompilableUnit(context, object, buffer->str, buffer->len)); +#endif script = JS_CompileScript(context, object, buffer->str, buffer->len, "typein", startline); -- 1.7.5.4 From 00dd38de7ac8e82ac35c40909707fa91665c3102 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Thu, 5 May 2011 12:49:09 -0400 Subject: [PATCH 3/4] JS_CLASS_TRACE is a preprocessor macro, can't use AC_CHECK_LIB Conflicts: configure.ac --- configure.ac | 24 ++++++++++++++++++++++++ 1 files changed, 24 insertions(+), 0 deletions(-) diff --git a/configure.ac b/configure.ac index 270bc46..d259471 100644 --- a/configure.ac +++ b/configure.ac @@ -230,6 +230,30 @@ if test "$have_jslocale_to_unicode_const" = yes; then AC_DEFINE([JS_LOCALETOUNICODE_NEEDS_CONST_CHAR], [1], [Define if JSLocaleToUnicode takes a const char* for its src]) fi +save_CFLAGS="$CFLAGS" +CFLAGS="$CFLAGS $JS_CFLAGS" +AC_MSG_CHECKING([for JS_CLASS_TRACE macro]) +AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[ + #include + #ifndef JS_CLASS_TRACE + #error "No JS_CLASS_TRACE" + #endif + ]], + [[(void) 0;]] + )], + [have_js_class_trace=yes], + [have_js_class_trace=no]) + +if test "x$have_js_class_trace" = xyes; then + AC_MSG_RESULT([yes]) + AC_DEFINE([HAVE_JS_CLASS_TRACE], [1], [Define if we still have JS_CLASS_TRACE]) +else + AC_MSG_RESULT([no]) +fi +CFLAGS="$save_CFLAGS" + common_packages="gobject-2.0 >= gobject_required_version $JS_PACKAGE" gjs_packages="gmodule-2.0 gthread-2.0 $common_packages" gjs_gi_packages="gobject-introspection-1.0 >= 0.10.1 $common_packages" -- 1.7.5.4 From 5553cdd691ffddae3e3ffa5cc75e6575a237d0b7 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Wed, 4 May 2011 14:14:18 -0400 Subject: [PATCH 4/4] Support compilation with standalone mozjs185 release Adjust the detection logic so that we look for mozjs-185.pc first. If we have this, we can skip all kinds of insanity. See https://bugzilla.mozilla.org/show_bug.cgi?id=628723 for the discussion about creating this release. https://bugzilla.gnome.org/show_bug.cgi?id=646369 Conflicts: configure.ac --- configure.ac | 218 ++++++++++++++++++++++++++++++++-------------------------- 1 files changed, 121 insertions(+), 97 deletions(-) diff --git a/configure.ac b/configure.ac index d259471..cb54ffc 100644 --- a/configure.ac +++ b/configure.ac @@ -91,124 +91,148 @@ m4_define(gobject_required_version, 2.18.0) AC_CHECK_HEADERS([malloc.h]) AC_CHECK_FUNCS(mallinfo) -# Look for Spidermonkey. If js-config exists, use that; -# otherwise we try some pkgconfig files from various distributions. +# First, try separate mozjs185 release +AC_MSG_CHECKING([for standalone mozjs]) +PKG_CHECK_EXISTS([mozjs185], JS_PACKAGE=mozjs185,) +if test x$JS_PACKAGE != x; then + FIREFOX_JS_LIBDIR=`$PKG_CONFIG --variable=libdir $JS_PACKAGE` + MOZJS_IS_STANDALONE=yes + MOZJS_LIB=mozjs185 + AC_MSG_RESULT([yes]) + PKG_CHECK_MODULES(JS, $JS_PACKAGE) +else + AC_MSG_RESULT([no]) + MOZJS_LIB=mozjs +fi + +# If we didn't find mozjs185 (the standalone spidermonkey); look for +# one from Firefox/XULRunner. If js-config exists, use that; otherwise +# we try some pkgconfig files from various distributions. AC_ARG_VAR([JS_CONFIG], [The js-config program to use]) -if test "$ac_cv_env_JS_CONFIG_set" != "set"; then +if test x$JS_PACKAGE = x && test "$ac_cv_env_JS_CONFIG_set" != "set"; then AC_PATH_PROG([JS_CONFIG], [js-config], []) fi -if test -n "$JS_CONFIG"; then - JS_CFLAGS="$($JS_CONFIG --cflags)" - JS_LIBS="$($JS_CONFIG --libs)" - FIREFOX_JS_LIBDIR="$($JS_CONFIG --libdir)" - JS_PACKAGE= - - # js-config gives almost usable CFLAGS, we must define one of XP_BEOS, - # XP_OS2, XP_WIN or XP_UNIX - JS_CFLAGS="$JS_CFLAGS -DXP_UNIX" -else - ## spidermonkey .pc file name varies across distributions and Gecko version - ## - ## mozilla-js: Gecko 1.9, all distributions - ## xulrunner-js: Gecko 1.8 (and earlier?) Debian/Ubuntu - ## firefox-js: ??? - ## - ## Checking for mozilla-js first will hopefully get us the newest version - ## of spidermonkey. - PKG_CHECK_EXISTS([mozilla-js], [JS_PACKAGE=mozilla-js], - [PKG_CHECK_EXISTS([xulrunner-js], [JS_PACKAGE=xulrunner-js], [JS_PACKAGE=firefox-js])]) - - PKG_CHECK_MODULES(JS, $JS_PACKAGE) - - ## some flavors of Firefox .pc only set sdkdir, not libdir - FIREFOX_JS_SDKDIR=`$PKG_CONFIG --variable=sdkdir $JS_PACKAGE` - FIREFOX_JS_LIBDIR=`$PKG_CONFIG --variable=libdir $JS_PACKAGE` +if test x$JS_PACKAGE = x; then + if test -n "$JS_CONFIG"; then + JS_CFLAGS="$($JS_CONFIG --cflags)" + JS_LIBS="$($JS_CONFIG --libs)" + FIREFOX_JS_LIBDIR="$($JS_CONFIG --libdir)" + JS_PACKAGE= + + # js-config gives almost usable CFLAGS, we must define one of XP_BEOS, + # XP_OS2, XP_WIN or XP_UNIX + JS_CFLAGS="$JS_CFLAGS -DXP_UNIX" + else + ## spidermonkey .pc file name varies across distributions and Gecko version + ## + ## mozilla-js: Gecko 1.9, all distributions + ## xulrunner-js: Gecko 1.8 (and earlier?) Debian/Ubuntu + ## firefox-js: ??? + ## + ## Checking for mozilla-js first will hopefully get us the newest version + ## of spidermonkey. + if test x$JS_PACKAGE = x; then + PKG_CHECK_EXISTS([mozilla-js], [JS_PACKAGE=mozilla-js],) + + fi + if test x$JS_PACKAGE = x; then + PKG_CHECK_EXISTS([xulrunner-js], [JS_PACKAGE=xulrunner-js]) + fi + if test x$JS_PACKAGE = x; then + PKG_CHECK_EXISTS([firefox-js], [JS_PACKAGE=firefox-js]) + fi + if test x$JS_PACKAGE = x; then + AC_MSG_ERROR([Unable to find spidermonkey package]) + fi + + PKG_CHECK_MODULES(JS, $JS_PACKAGE) + + ## some flavors of Firefox .pc only set sdkdir, not libdir + FIREFOX_JS_SDKDIR=`$PKG_CONFIG --variable=sdkdir $JS_PACKAGE` + FIREFOX_JS_LIBDIR=`$PKG_CONFIG --variable=libdir $JS_PACKAGE` + + ## Ubuntu does not set libdir in mozilla-js.pc + if test x"$FIREFOX_JS_LIBDIR" = x ; then + ## Ubuntu returns xulrunner-devel as the sdkdir, but for the + ## libdir we want the runtime location on the target system, + ## so can't use -devel. + ## The library is in the non-devel directory also. + ## Don't ask me why it's in two places. + FIREFOX_JS_LIBDIR=`echo "$FIREFOX_JS_SDKDIR" | sed -e 's/-devel//g'` + + if ! test -d "$FIREFOX_JS_LIBDIR" ; then + FIREFOX_JS_LIBDIR= + fi + fi + fi - ## Ubuntu does not set libdir in mozilla-js.pc if test x"$FIREFOX_JS_LIBDIR" = x ; then - ## Ubuntu returns xulrunner-devel as the sdkdir, but for the - ## libdir we want the runtime location on the target system, - ## so can't use -devel. - ## The library is in the non-devel directory also. - ## Don't ask me why it's in two places. - FIREFOX_JS_LIBDIR=`echo "$FIREFOX_JS_SDKDIR" | sed -e 's/-devel//g'` - - if ! test -d "$FIREFOX_JS_LIBDIR" ; then - FIREFOX_JS_LIBDIR= - fi + AC_MSG_ERROR([Could not figure out where Firefox JavaScript library lives]) fi -fi -if test x"$FIREFOX_JS_LIBDIR" = x ; then - AC_MSG_ERROR([Could not figure out where Firefox JavaScript library lives]) + ## workaround for Ubuntu Hardy bug where mozilla-js.pc gives CFLAGS + ## -I.../stable while jsapi.h is in .../unstable + AC_MSG_CHECKING([if SpiderMonkey needs extra compiler flags]) + save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS $JS_CFLAGS" + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include ]])], + [js_extra_cflags_needed=no], + [js_extra_cflags_needed=yes]) + CFLAGS="$save_CFLAGS" + AC_MSG_RESULT([$js_extra_cflags_needed]) + + JS_EXTRA_CFLAGS= + if test "$js_extra_cflags_needed" = yes; then + try_cflags="-I`$PKG_CONFIG --variable=includedir $JS_PACKAGE`/unstable" + AC_MSG_CHECKING([if $try_cflags works]) + save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS $JS_CFLAGS $try_cflags" + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include ]])], + [AC_MSG_RESULT([yes]) + JS_EXTRA_CFLAGS="$try_cflags"], + [AC_MSG_RESULT([no])]) + CFLAGS="$save_CFLAGS" + + if test x"$JS_EXTRA_CFLAGS" = x; then + AC_MSG_ERROR([Unable to determine extra compiler flags needed]) + fi + fi + AC_SUBST([JS_EXTRA_CFLAGS]) + + AC_MSG_CHECKING([for mozilla-js >= 1.9.2 ]) + if `$PKG_CONFIG --exists $JS_PACKAGE '>=' 1.9.2`; then + AC_MSG_RESULT([yes]) + else + AC_MSG_ERROR([$JS_PACKAGE >= 1.9.2 is required]) + fi fi AC_SUBST(JS_PACKAGE) AC_SUBST(FIREFOX_JS_LIBDIR) -AC_MSG_CHECKING([for mozilla-js >= 1.9.2 ]) -if `$PKG_CONFIG --exists $JS_PACKAGE '>=' 1.9.2`; then - AC_MSG_RESULT([yes]) -else - AC_MSG_ERROR([$JS_PACKAGE >= 1.9.2 is required]) -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_CHECK_LIB([mozjs], [JS_GetStringChars], AC_DEFINE([HAVE_JS_GETSTRINGCHARS], [1], [Define if we still have JS_GetStringChars]),, [$JS_LIBS]) -AC_CHECK_LIB([mozjs], [JS_StrictPropertyStub], AC_DEFINE([HAVE_JS_STRICTPROPERTYSTUB], [1], [Define if we have JS_StrictPropertyStub]),, [$JS_LIBS]) -AC_CHECK_LIB([mozjs], [JS_GetGlobalForScopeChain], AC_DEFINE([HAVE_JS_GETGLOBALFORSCOPECHAIN], [1], [Define if we have JS_GetGlobalForScopeChain]),, [$JS_LIBS]) -AC_CHECK_LIB([mozjs], [JS_DestroyScript], AC_DEFINE([HAVE_JS_DESTROYSCRIPT], [1], [Define if we still have JS_DestroyScript]),, [$JS_LIBS]) -AC_CHECK_LIB([mozjs], [JS_DecodeUTF8], AC_DEFINE([HAVE_JS_DECODEUTF8], [1], [Define if we have JS_DecodeUTF8]),, [$JS_LIBS]) - -AC_MSG_CHECKING([for mozilla-js >= 2 ]) -if `$PKG_CONFIG --exists $JS_PACKAGE '>=' 2`; then - AC_MSG_RESULT([yes]) - AC_DEFINE(HAVE_MOZJS_2, [1], [Define if mozilla-js is at least 2]) - AC_CHECK_LIB([mozjs], [JS_FreezeObject], AC_DEFINE([HAVE_JS_FREEZEOBJECT], [1], [Define if we have JS_FreezeObject]), +AC_CHECK_LIB([$MOZJS_LIB], [JS_GetStringBytes], AC_DEFINE([HAVE_JS_GETSTRINGBYTES], [1], [Define if we still have JS_GetStringBytes]),, [$JS_LIBS]) +AC_CHECK_LIB([$MOZJS_LIB], [JS_GetFunctionName], AC_DEFINE([HAVE_JS_GETFUNCTIONNAME], [1], [Define if we still have JS_GetFunctionName]),, [$JS_LIBS]) +AC_CHECK_LIB([$MOZJS_LIB], [JS_GetStringChars], AC_DEFINE([HAVE_JS_GETSTRINGCHARS], [1], [Define if we still have JS_GetStringChars]),, [$JS_LIBS]) +AC_CHECK_LIB([$MOZJS_LIB], [JS_StrictPropertyStub], AC_DEFINE([HAVE_JS_STRICTPROPERTYSTUB], [1], [Define if we have JS_StrictPropertyStub]),, [$JS_LIBS]) +AC_CHECK_LIB([$MOZJS_LIB], [JS_GetGlobalForScopeChain], AC_DEFINE([HAVE_JS_GETGLOBALFORSCOPECHAIN], [1], [Define if we have JS_GetGlobalForScopeChain]),, [$JS_LIBS]) +AC_CHECK_LIB([$MOZJS_LIB], [JS_CLASS_TRACE], AC_DEFINE([HAVE_JS_CLASS_TRACE], [1], [Define if we still have JS_CLASS_TRACE]),, [$JS_LIBS]) +AC_CHECK_LIB([$MOZJS_LIB], [JS_DestroyScript], AC_DEFINE([HAVE_JS_DESTROYSCRIPT], [1], [Define if we still have JS_DestroyScript]),, [$JS_LIBS]) +AC_CHECK_LIB([$MOZJS_LIB], [JS_DecodeUTF8], AC_DEFINE([HAVE_JS_DECODEUTF8], [1], [Define if we have JS_DecodeUTF8]),, [$JS_LIBS]) +AC_CHECK_LIB([$MOZJS_LIB], [JS_FreezeObject], AC_DEFINE([HAVE_JS_FREEZEOBJECT], [1], [Define if we have JS_FreezeObject]), , [$JS_LIBS]) - AC_CHECK_LIB([mozjs], [JS_IsScriptFrame], AC_DEFINE([HAVE_JS_ISSCRIPTFRAME], [1], [Define if we have JS_IsScriptFrame]), +AC_CHECK_LIB([$MOZJS_LIB], [JS_IsScriptFrame], AC_DEFINE([HAVE_JS_ISSCRIPTFRAME], [1], [Define if we have JS_IsScriptFrame]), , [$JS_LIBS]) - AC_CHECK_LIB([mozjs], [JS_EndPC], AC_DEFINE([HAVE_JS_ENDPC], [1], [Define if we have JS_EndPC]), +AC_CHECK_LIB([$MOZJS_LIB], [JS_EndPC], AC_DEFINE([HAVE_JS_ENDPC], [1], [Define if we have JS_EndPC]), , [$JS_LIBS]) - AC_CHECK_LIB([mozjs], [JS_NewCompartmentAndGlobalObject], +AC_CHECK_LIB([$MOZJS_LIB], [JS_NewCompartmentAndGlobalObject], AC_DEFINE([HAVE_JS_NEWCOMPARTMENTANDGLOBALOBJECT], [1], [Define if we have JS_NewCompartmentAndGlobalObject]), , [$JS_LIBS]) -else - AC_MSG_RESULT([no]) -fi - -## workaround for Ubuntu Hardy bug where mozilla-js.pc gives CFLAGS -## -I.../stable while jsapi.h is in .../unstable -AC_MSG_CHECKING([if SpiderMonkey needs extra compiler flags]) -save_CFLAGS="$CFLAGS" -CFLAGS="$CFLAGS $JS_CFLAGS" -AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include ]])], - [js_extra_cflags_needed=no], - [js_extra_cflags_needed=yes]) -CFLAGS="$save_CFLAGS" -AC_MSG_RESULT([$js_extra_cflags_needed]) - -JS_EXTRA_CFLAGS= -if test "$js_extra_cflags_needed" = yes; then - try_cflags="-I`$PKG_CONFIG --variable=includedir $JS_PACKAGE`/unstable" - AC_MSG_CHECKING([if $try_cflags works]) - save_CFLAGS="$CFLAGS" - CFLAGS="$CFLAGS $JS_CFLAGS $try_cflags" - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include ]])], - [AC_MSG_RESULT([yes]) - JS_EXTRA_CFLAGS="$try_cflags"], - [AC_MSG_RESULT([no])]) - CFLAGS="$save_CFLAGS" - - if test x"$JS_EXTRA_CFLAGS" = x; then - AC_MSG_ERROR([Unable to determine extra compiler flags needed]) - fi +if test x$MOZJS_IS_STANDALONE = xyes || `$PKG_CONFIG --exists $JS_PACKAGE '>=' 2`; then + AC_DEFINE(HAVE_MOZJS_2, [1], [Define if mozilla-js is at least 2]) fi -AC_SUBST([JS_EXTRA_CFLAGS]) AC_MSG_CHECKING([whether JSLocaleToUnicode takes a const char*]) save_CFLAGS="$CFLAGS" -- 1.7.5.4