From 71081311b2b11ed923869ce5bd11ce7b0fd1da2c Mon Sep 17 00:00:00 2001 From: Paul Joseph Davis Date: Thu, 8 Sep 2011 05:00:10 +0000 Subject: Fix CouchJS compatibility with older SpiderMonkey. This is a backport of the work to make CouchJS build against all of the major versions of SpiderMonkey. Thanks to Randall Leeds and Chris Coulson for the original patches. Backport based on r1137464 and r1164346 Fixes COUCHDB-1078 Fixes COUCHDB-1260 git-svn-id: https://svn.apache.org/repos/asf/couchdb/branches/1.1.x@1166525 13f79535-47bb-0310-9956-ffa450edef68 --- src/couchdb/priv/couch_js/utf8.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/couchdb/priv/couch_js/utf8.c') diff --git a/src/couchdb/priv/couch_js/utf8.c b/src/couchdb/priv/couch_js/utf8.c index 699a6fee..d6064267 100644 --- a/src/couchdb/priv/couch_js/utf8.c +++ b/src/couchdb/priv/couch_js/utf8.c @@ -11,6 +11,7 @@ // the License. #include +#include "config.h" static int enc_char(uint8 *utf8Buffer, uint32 ucs4Char) @@ -121,7 +122,7 @@ char* enc_string(JSContext* cx, jsval arg, size_t* buflen) { JSString* str = NULL; - jschar* src = NULL; + const jschar* src = NULL; char* bytes = NULL; size_t srclen = 0; size_t byteslen = 0; @@ -129,8 +130,12 @@ enc_string(JSContext* cx, jsval arg, size_t* buflen) str = JS_ValueToString(cx, arg); if(!str) goto error; +#ifdef HAVE_JS_GET_STRING_CHARS_AND_LENGTH + src = JS_GetStringCharsAndLength(cx, str, &srclen); +#else src = JS_GetStringChars(str); srclen = JS_GetStringLength(str); +#endif if(!enc_charbuf(src, srclen, NULL, &byteslen)) goto error; @@ -283,4 +288,4 @@ error: success: return str; -} \ No newline at end of file +} -- cgit v1.2.3