Permalink
Browse files

Fix CouchJS compatibility with older Spidermonkey.

The recent patch to enable support for SM 1.8.5 broke support for
1.7.0. This patch updates couchjs to work with all of the major
variants of Spidermonkey.

Versions tested:

    1.7.0
    1.8.0rc1
    1.8.5
    1.9.2.something (XULRunner)

Various combinations have been tested on OS X, Ubuntu, FreeBSD and
Windows.

Fixes COUCHDB-1260



git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@1164346 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
1 parent 7d1a814 commit 4a6ac642cb0df70a90bf0a9418e470c8e02e0af7 @davisp davisp committed Sep 2, 2011
View
@@ -185,37 +185,31 @@ AM_CONDITIONAL([WINDOWS], [test x$IS_WINDOWS = xTRUE])
OLD_LIBS="$LIBS"
LIBS="$JS_LIBS $LIBS"
AC_CHECK_LIB([mozjs185], [JS_NewContext], [JS_LIB_BASE=mozjs185], [
- AC_CHECK_LIB([mozjs], [JS_NewContext], [JS_LIB_BASE=mozjs], [
- AC_CHECK_LIB([js], [JS_NewContext], [JS_LIB_BASE=js], [
- AC_CHECK_LIB([js3250], [JS_NewContext], [JS_LIB_BASE=js3250], [
- AC_CHECK_LIB([js32], [JS_NewContext], [JS_LIB_BASE=js32], [
- AC_MSG_ERROR([Could not find the js library.
+ AC_CHECK_LIB([mozjs185-1.0], [JS_NewContext], [JS_LIB_BASE=mozjs185-1.0], [
+ AC_CHECK_LIB([mozjs], [JS_NewContext], [JS_LIB_BASE=mozjs], [
+ AC_CHECK_LIB([js], [JS_NewContext], [JS_LIB_BASE=js], [
+ AC_CHECK_LIB([js3250], [JS_NewContext], [JS_LIB_BASE=js3250], [
+ AC_CHECK_LIB([js32], [JS_NewContext], [JS_LIB_BASE=js32], [
+ AC_MSG_ERROR([Could not find the js library.
-Is the Mozilla SpiderMonkey library installed?])])])])])])
+Is the Mozilla SpiderMonkey library installed?])])])])])])])
-AC_CHECK_LIB([$JS_LIB_BASE], [JS_FreezeObject],
- AC_DEFINE([HAVE_JS_FREEZE_OBJECT], [1],
- [Define whether we have JS_FreezeObject]))
+# Figure out what version of SpiderMonkey to use
-AC_CHECK_LIB([$JS_LIB_BASE], [JS_NewGlobalObject],
- AC_DEFINE([HAVE_JS_NEW_GLOBAL_OBJECT], [1],
- [Define whether we have JS_NewGlobalObject]))
+AC_CHECK_LIB([$JS_LIB_BASE], [JS_NewCompartmentAndGlobalObject],
+ AC_DEFINE([SM185], [1],
+ [Use SpiderMonkey 1.8.5]))
+
+AC_CHECK_LIB([$JS_LIB_BASE], [JS_ThrowStopIteration],
+ AC_DEFINE([SM180], [1],
+ [Use SpiderMonkey 1.8.0]))
AC_CHECK_LIB([$JS_LIB_BASE], [JS_GetStringCharsAndLength],
AC_DEFINE([HAVE_JS_GET_STRING_CHARS_AND_LENGTH], [1],
- [Define whether we have JS_GetStringCharsAndLength]))
-
-AC_CHECK_LIB([$JS_LIB_BASE], [JS_NewCompartmentAndGlobalObject],
- AC_DEFINE([HAVE_COMPARTMENTS], [1],
- [Define whether we have JS_NewCompartmentAndGlobalObject]))
+ [Use newer JS_GetCharsAndLength function.]))
-AC_CHECK_LIB([$JS_LIB_BASE], [JS_StrictPropertyStub],
- AC_DEFINE([HAVE_JS_STRICT_PROPERTY_STUB], [1],
- [Define whether we have JS_StrictPropertyStub]))
-AC_CHECK_LIB([$JS_LIB_BASE], [JS_DestroyScript],
- AC_DEFINE([HAVE_SCRIPT_TYPE], [1],
- [Define whether scripts have a special JSScript type]))
+# Else, hope that 1.7.0 works
LIBS="$OLD_LIBS"
if test x${IS_WINDOWS} = xTRUE; then
@@ -261,7 +255,7 @@ if test x${IS_WINDOWS} = xTRUE; then
fi
fi
-JS_LIBS="-l$JS_LIB_BASE $JS_LIBS"
+JS_LIBS="-l$JS_LIB_BASE -lm $JS_LIBS"
AC_SUBST(JS_LIBS)
OLD_CPPFLAGS="$CPPFLAGS"
@@ -278,38 +272,6 @@ Are the Mozilla SpiderMonkey headers installed?])
])])
CPPFLAGS="$OLD_CPPFLAGS"
-AC_LANG_PUSH(C)
-OLDCFLAGS="$CFLAGS"
-CFLAGS="-Werror-implicit-function-declaration $JS_CFLAGS $OLDCFLAGS"
-AC_COMPILE_IFELSE(
- [AC_LANG_PROGRAM(
- [[#include <jsapi.h>]],
- [[JS_SetOperationCallback(0, 0);]]
- )],
- AC_DEFINE([USE_JS_SETOPCB], [], [Use new JS_SetOperationCallback])
-)
-CFLAGS="$JS_CFLAGS $OLDCFLAGS"
-AC_COMPILE_IFELSE(
- [AC_LANG_PROGRAM(
- [[#include <jsapi.h>]],
- [[static JSFunctionSpec fs;
- fs.extra = 0;]]
- )],
- AC_DEFINE([JS_FS_HAS_EXTRA], [1], [JSFunctionSpec has an extra member])
-)
-CFLAGS="$JS_CFLAGS $OLDCFLAGS -Werror"
-AC_COMPILE_IFELSE(
- [AC_LANG_PROGRAM(
- [[#include <jsapi.h>
- static JSBool op(JSContext* cx, JSObject* obj, jsid id, jsval* vp) {}]],
- [[static JSPropertySpec spec;
- spec.getter = op;]]
- )],
- AC_DEFINE([JS_PROPERTY_OP_HAS_ID_AS_JSID], [1],
- [The type of "id" in the prototype for JSPropertyOp is a jsid])
-)
-CFLAGS="$OLD_CFLAGS"
-AC_LANG_POP(C)
AC_ARG_WITH([win32-icu-binaries], [AC_HELP_STRING([--with-win32-icu-binaries=PATH],
[set PATH to the Win32 native ICU binaries directory])], [
View
@@ -29,7 +29,7 @@ function init_sandbox() {
sandbox.getRow = Render.getRow;
sandbox.isArray = isArray;
} catch (e) {
- log(e.toSource());
+ //log(e.toSource());
}
};
init_sandbox();
@@ -97,7 +97,7 @@ var Mimeparse = (function() {
if ((type == targetType || type == "*" || targetType == "*") &&
(subtype == targetSubtype || subtype == "*" || targetSubtype == "*")) {
var matchCount = 0;
- for (param in targetParams) {
+ for (var param in targetParams) {
if (param != 'q' && params[param] && params[param] == targetParams[param]) {
matchCount += 1;
}
View
@@ -69,7 +69,7 @@ var Couch = {
if(typeof CoffeeScript === "undefined") {
return evalFunction(source, sandbox);
} else {
- coffee = CoffeeScript.compile(source, {bare: true});
+ var coffee = CoffeeScript.compile(source, {bare: true});
return evalFunction(coffee, sandbox);
}
}
@@ -414,9 +414,22 @@ function waitForSuccess(fun, tag) {
function waitForRestart() {
var waiting = true;
- while (waiting) {
+ // Wait for the server to go down but don't
+ // wait too long because we might miss the
+ // the unavailable period.
+ var count = 25;
+ while (waiting && count > 0) {
+ count--;
try {
CouchDB.request("GET", "/");
+ } catch(e) {
+ waiting = false;
+ }
+ }
+ // Wait for it to come back up
+ waiting = true;
+ while (waiting) {
+ try {
CouchDB.request("GET", "/");
waiting = false;
} catch(e) {
@@ -17,7 +17,10 @@ couchprivlibdir = $(couchlibdir)/priv/lib
EXTRA_DIST = \
spawnkillable/couchspawnkillable.sh \
stat_descriptions.cfg.in \
- couch_ejson_compare/erl_nif_compat.h
+ couch_ejson_compare/erl_nif_compat.h \
+ couch_js/sm170.c \
+ couch_js/sm180.c \
+ couch_js/sm185.c
CLEANFILES = stat_descriptions.cfg
@@ -44,14 +47,15 @@ endif
COUCHJS_SRCS = \
couch_js/http.c \
couch_js/http.h \
- couch_js/jscompat.h \
couch_js/main.c \
couch_js/utf8.c \
- couch_js/utf8.h
+ couch_js/utf8.h \
+ couch_js/util.h \
+ couch_js/util.c
locallibbin_PROGRAMS = couchjs
couchjs_SOURCES = $(COUCHJS_SRCS)
-couchjs_CFLAGS = -D_BSD_SOURCE $(CURL_CFLAGS) $(JS_CFLAGS)
+couchjs_CFLAGS = -g -Wall -Werror -D_BSD_SOURCE $(CURL_CFLAGS) $(JS_CFLAGS)
couchjs_LDADD = $(CURL_LIBS) $(JS_LIBS)
couchpriv_DATA = stat_descriptions.cfg
Oops, something went wrong.

0 comments on commit 4a6ac64

Please sign in to comment.