diff --git a/configure.ac b/configure.ac
index 3bda2ce..89c7b7c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -146,6 +146,8 @@ 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_MSG_CHECKING([for mozilla-js >= 2 ])
 if `$PKG_CONFIG --exists $JS_PACKAGE '>=' 2`; then
   AC_MSG_RESULT([yes])
@@ -156,9 +158,6 @@ if `$PKG_CONFIG --exists $JS_PACKAGE '>=' 2`; then
               , [$JS_LIBS])
   AC_CHECK_LIB([mozjs], [JS_EndPC], AC_DEFINE([HAVE_JS_ENDPC], [1], [Define if we have JS_EndPC]),
               , [$JS_LIBS])
-  AC_CHECK_LIB([mozjs], [JS_GetStringBytes], AC_DEFINE([HAVE_JS_GETSTRINGBYTES], [1], [Define if we still have JS_GetStringBytes]),
-              , [$JS_LIBS])
-
 else
   AC_MSG_RESULT([no])
 fi
diff --git a/gjs/jsapi-util-array.c b/gjs/jsapi-util-array.c
index 6c6a1f4..dbbd96e 100644
--- a/gjs/jsapi-util-array.c
+++ b/gjs/jsapi-util-array.c
@@ -321,7 +321,7 @@ gjstest_test_func_gjs_jsapi_util_array(void)
         value = gjs_rooted_array_get(context, array, i);
         g_assert(JSVAL_IS_STRING(value));
         str = JSVAL_TO_STRING(value);
-#if HAVE_JS_GETSTRINGBYTES
+#ifdef HAVE_JS_GETSTRINGBYTES
         ascii = g_strdup(JS_GetStringBytes(str));
 #else
         size_t len = JS_GetStringEncodingLength(context, str);
diff --git a/gjs/jsapi-util-error.c b/gjs/jsapi-util-error.c
index 2f4f46c..7abad88 100644
--- a/gjs/jsapi-util-error.c
+++ b/gjs/jsapi-util-error.c
@@ -228,19 +228,17 @@ gjstest_test_func_gjs_jsapi_util_error_throw(void)
     g_assert(JSVAL_IS_STRING(value));
     str = JSVAL_TO_STRING(value);
 
-#if HAVE_JS_GETSTRINGBYTES
+#ifdef HAVE_JS_GETSTRINGBYTES
     /* JS_GetStringBytes() is broken for non-ASCII but that's OK here */
     s = g_strdup(JS_GetStringBytes(str));
 #else
     size_t len = JS_GetStringEncodingLength(context, str);
-    if (len == (size_t)(-1))
-        goto out;
-
-    s = g_malloc((len + 1) * sizeof(char));
-    JS_EncodeStringToBuffer(str, s, len);
-    s[len] = '\0';
+    if (len != (size_t)(-1)) { 
+        s = g_malloc((len + 1) * sizeof(char));
+        JS_EncodeStringToBuffer(str, s, len);
+        s[len] = '\0';
+    }
 #endif
- out:
     g_assert(s != NULL);
     strcmp_result = strcmp(s, "This is an exception 42");
     free(s);
diff --git a/gjs/jsapi-util-string.c b/gjs/jsapi-util-string.c
index 76b44c4..5443920 100644
--- a/gjs/jsapi-util-string.c
+++ b/gjs/jsapi-util-string.c
@@ -260,7 +260,7 @@ gjs_string_get_ascii(JSContext       *context,
 
     str = JSVAL_TO_STRING(value);
 
-#if HAVE_JS_GETSTRINGBYTES
+#ifdef HAVE_JS_GETSTRINGBYTES
     return g_strdup(JS_GetStringBytes(str));
 #else
     char *ascii;
@@ -325,7 +325,7 @@ gjs_string_get_binary_data(JSContext       *context,
 
     str = JSVAL_TO_STRING(value);
 
-#if HAVE_JS_GETSTRINGBYTES
+#ifdef HAVE_JS_GETSTRINGBYTES
     const char *js_data = JS_GetStringBytes(str);
 
     /* GetStringLength returns number of 16-bit jschar;
@@ -453,7 +453,7 @@ gjs_get_string_id (JSContext       *context,
 
     if (JSVAL_IS_STRING(id_val)) {
         str = JSVAL_TO_STRING(id_val);
-#if HAVE_JS_GETSTRINGBYTES
+#ifdef HAVE_JS_GETSTRINGBYTES
         *name_p = g_strdup(JS_GetStringBytes(str));
 #else
         size_t len = JS_GetStringEncodingLength(context, str);
diff --git a/gjs/jsapi-util.c b/gjs/jsapi-util.c
index 7c1a82f..b546a32 100644
--- a/gjs/jsapi-util.c
+++ b/gjs/jsapi-util.c
@@ -791,7 +791,7 @@ gjs_value_debug_string(JSContext      *context,
 
     g_assert(str != NULL);
 
-#if HAVE_JS_GETSTRINGBYTES
+#ifdef HAVE_JS_GETSTRINGBYTES
     bytes = g_strdup(JS_GetStringBytes(str));
 #else
     size_t len = JS_GetStringEncodingLength(context, str);
