From afb9467fbe19d0741559253d3042627c299abbcf Mon Sep 17 00:00:00 2001 From: Jan Lehnardt Date: Tue, 4 Aug 2009 12:28:58 +0000 Subject: add compile-time conditionals to support the upcoming Spidermonkey 1.8, swap searching for libjs and libmozjs, patch by Alessandro Decina, closes COUCHDB-288 git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@800750 13f79535-47bb-0310-9956-ffa450edef68 --- configure.ac | 4 ++-- share/www/script/test/show_documents.js | 2 +- src/couchdb/couch_js.c | 28 +++++++++++++++++++++++++--- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/configure.ac b/configure.ac index f42b4b77..72e8aef3 100644 --- a/configure.ac +++ b/configure.ac @@ -85,8 +85,8 @@ CPPFLAGS="$FLAGS $CPPFLAGS" # manually linking libm is requred for FreeBSD 7.0 LDFLAGS="$FLAGS -lm $LDFLAGS" -AC_CHECK_LIB([js], [JS_NewContext], [], [ - AC_CHECK_LIB([mozjs], [JS_NewContext], [], [ +AC_CHECK_LIB([mozjs], [JS_NewContext], [], [ + AC_CHECK_LIB([js], [JS_NewContext], [], [ AC_MSG_ERROR([Could not find the js library. Is the Mozilla SpiderMonkey library installed?])])]) diff --git a/share/www/script/test/show_documents.js b/share/www/script/test/show_documents.js index 8a1edd2d..a1138596 100644 --- a/share/www/script/test/show_documents.js +++ b/share/www/script/test/show_documents.js @@ -112,7 +112,7 @@ couchTests.show_documents = function(debug) { // Becase Safari can't stand to see that dastardly // E4X outside of a string. Outside of tests you // can just use E4X literals. - this.eval('xml.node.@foo = doc.word'); + eval('xml.node.@foo = doc.word'); return { body: xml }; diff --git a/src/couchdb/couch_js.c b/src/couchdb/couch_js.c index b828355a..f05fc4b4 100644 --- a/src/couchdb/couch_js.c +++ b/src/couchdb/couch_js.c @@ -213,7 +213,8 @@ EvalInContext(JSContext *context, JSObject *obj, uintN argc, jsval *argv, JS_ReportOutOfMemory(context); return JS_FALSE; } - + JS_SetContextThread(sub_context); + JS_BeginRequest(sub_context); src = JS_GetStringChars(str); srclen = JS_GetStringLength(str); @@ -229,13 +230,15 @@ EvalInContext(JSContext *context, JSObject *obj, uintN argc, jsval *argv, *rval = OBJECT_TO_JSVAL(sandbox); ok = JS_TRUE; } else { - ok = JS_EvaluateUCScript(sub_context, sandbox, src, srclen, NULL, -1, + ok = JS_EvaluateUCScript(sub_context, sandbox, src, srclen, NULL, 0, rval); ok = JS_TRUE; } out: + JS_EndRequest(sub_context); JS_DestroyContext(sub_context); + JS_ClearContextThread(sub_context); return ok; } @@ -395,6 +398,7 @@ ExecuteScript(JSContext *context, JSObject *obj, const char *filename) { static uint32 gBranchCount = 0; +#if JS_VERSION <= 170 static JSBool BranchCallback(JSContext *context, JSScript *script) { if ((++gBranchCount & 0x3fff) == 1) { @@ -402,6 +406,16 @@ BranchCallback(JSContext *context, JSScript *script) { } return JS_TRUE; } +#else +static JSBool +OperationCallback(JSContext *context) +{ + if ((++gBranchCount & 0x3fff) == 1) { + JS_MaybeGC(context); + } + return JS_TRUE; +} +#endif static void PrintError(JSContext *context, const char *message, JSErrorReport *report) { @@ -1211,9 +1225,16 @@ main(int argc, const char * argv[]) { context = JS_NewContext(runtime, gStackChunkSize); if (!context) return 1; + JS_SetContextThread(context); + JS_BeginRequest(context); + /* FIXME: https://bugzilla.mozilla.org/show_bug.cgi?id=477187 */ JS_SetErrorReporter(context, PrintError); +#if JS_VERSION <= 170 JS_SetBranchCallback(context, BranchCallback); JS_ToggleOptions(context, JSOPTION_NATIVE_BRANCH_CALLBACK); +#else + JS_SetOperationCallback(context, OperationCallback); +#endif JS_ToggleOptions(context, JSOPTION_XML); global = JS_NewObject(context, NULL, NULL, NULL); @@ -1243,8 +1264,9 @@ main(int argc, const char * argv[]) { } ExecuteScript(context, global, argv[1]); - + JS_EndRequest(context); JS_DestroyContext(context); + JS_ClearContextThread(context); JS_DestroyRuntime(runtime); JS_ShutDown(); -- cgit v1.2.3