diff options
author | Paul J. Davis <paul.joseph.davis@gmail.com> | 2011-09-06 15:27:10 -0500 |
---|---|---|
committer | Paul J. Davis <paul.joseph.davis@gmail.com> | 2011-09-22 17:02:47 -0500 |
commit | 34ba230324bb329ce5ed54d703dcb4d84a65ab86 (patch) | |
tree | ea777cf0b2f6682642aaf64c5b3a1a55e4c3a523 /couchjs/c_src/utf8.c | |
parent | 8a96880cd02ea9286dea597d213ddf0d4487cbc3 (diff) |
Updated CouchJS to support SpiderMonkey 1.8.5
This is tested against the 1.7.0, 1.8.0rc1, and 1.8.5 tarballs from
Mozilla's FTP directory. It's mostly the same code from trunk minus a
few tweaks to get it past a couple type errors using c++ instead of cc.
Diffstat (limited to 'couchjs/c_src/utf8.c')
-rw-r--r-- | couchjs/c_src/utf8.c | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/couchjs/c_src/utf8.c b/couchjs/c_src/utf8.c index 57928ba9..ace6badb 100644 --- a/couchjs/c_src/utf8.c +++ b/couchjs/c_src/utf8.c @@ -11,13 +11,7 @@ // the License. #include "config.h" -#ifdef HAVE_JS_JSAPI_H -#include <js/jsapi.h> -#elif HAVE_MOZJS_JSAPI_H -#include <mozjs/jsapi.h> -#else -#include <jsapi.h> -#endif +#include "sm.h" static int enc_char(uint8 *utf8Buffer, uint32 ucs4Char) @@ -128,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; @@ -136,12 +130,16 @@ enc_string(JSContext* cx, jsval arg, size_t* buflen) str = JS_ValueToString(cx, arg); if(!str) goto error; +#ifdef SM185 + 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; - bytes = JS_malloc(cx, (byteslen) + 1); + bytes = (char*) JS_malloc(cx, (byteslen) + 1); bytes[byteslen] = 0; if(!enc_charbuf(src, srclen, bytes, &byteslen)) goto error; @@ -273,7 +271,7 @@ dec_string(JSContext* cx, const char* bytes, size_t byteslen) if(!dec_charbuf(bytes, byteslen, NULL, &charslen)) goto error; - chars = JS_malloc(cx, (charslen + 1) * sizeof(jschar)); + chars = (jschar*) JS_malloc(cx, (charslen + 1) * sizeof(jschar)); if(!chars) return NULL; chars[charslen] = 0; |