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 --- src/couchdb/couch_js.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'src') 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