diff options
author | Eliot Horowitz <eliot@10gen.com> | 2009-05-27 16:23:52 -0400 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2009-05-27 16:23:52 -0400 |
commit | e8a92a31f47eed060d2e056a54b334a4e7423aa9 (patch) | |
tree | ab23e36a4bc62f4b8b12b740cfb81fac3957b8b5 | |
parent | d556557091810b3b88d2dfbd026e1d4f0c3a8772 (diff) | |
parent | 3b2ecb5ff075f935c4cb3c6e731f0276ea747c55 (diff) | |
download | mongo-e8a92a31f47eed060d2e056a54b334a4e7423aa9.tar.gz |
Merge branch 'master' of git@github.com:mongodb/mongo
-rw-r--r-- | dbtests/jstests.cpp | 51 | ||||
-rw-r--r-- | scripting/engine_spidermonkey.cpp | 7 |
2 files changed, 56 insertions, 2 deletions
diff --git a/dbtests/jstests.cpp b/dbtests/jstests.cpp index d2338a0c053..b6e2b3a3e8d 100644 --- a/dbtests/jstests.cpp +++ b/dbtests/jstests.cpp @@ -21,6 +21,12 @@ #include "dbtests.h" +#include "../db/instance.h" + +namespace mongo { + bool dbEval(const char *ns, BSONObj& cmd, BSONObjBuilder& result, string& errmsg); +} // namespace mongo + namespace JSTests { class Fundamental { @@ -424,14 +430,58 @@ namespace JSTests { } }; + + void dummy_function_to_force_dbeval_cpp_linking() { + BSONObj cmd; + BSONObjBuilder result; + string errmsg; + dbEval( "", cmd, result, errmsg); + } + + DBDirectClient client; + class Utf8Check { public: + Utf8Check() { reset(); } + ~Utf8Check() { reset(); } void run() { if( !globalScriptEngine->utf8Ok() ) { log() << "utf8 not supported" << endl; return; } + string utf8ObjSpec = "{'_id':'\\u0001\\u007f\\u07ff\\uffff'}"; + BSONObj utf8Obj = fromjson( utf8ObjSpec ); + client.insert( ns(), utf8Obj ); + client.eval( "unittest", "v = db.jstests.utf8check.findOne(); db.jstests.utf8check.remove( {} ); db.jstests.utf8check.insert( v );" ); + check( utf8Obj, client.findOne( ns(), BSONObj() ) ); + } + private: + void check( const BSONObj &one, const BSONObj &two ) { + if ( one.woCompare( two ) != 0 ) { + static string fail = string( "Assertion failure expected " ) + string( one ) + ", got " + string( two ); + FAIL( fail.c_str() ); + } + } + void reset() { + client.dropCollection( ns() ); + } + static const char *ns() { return "unittest.jstests.utf8check"; } + }; + + class LongUtf8String { + public: + LongUtf8String() { reset(); } + ~LongUtf8String() { reset(); } + void run() { + if( !globalScriptEngine->utf8Ok() ) + return; + client.eval( "unittest", "db.jstests.longutf8string.save( {_id:'\\uffff\uffff\uffff\uffff'} )" ); } + private: + void reset() { + client.dropCollection( ns() ); + } + static const char *ns() { return "unittest.jstests.longutf8string"; } }; class All : public Suite { @@ -450,6 +500,7 @@ namespace JSTests { add< TypeConservation >(); add< WeirdObjects >(); add< Utf8Check >(); + add< LongUtf8String >(); } }; diff --git a/scripting/engine_spidermonkey.cpp b/scripting/engine_spidermonkey.cpp index 37516f46cd3..2fb4beecdb8 100644 --- a/scripting/engine_spidermonkey.cpp +++ b/scripting/engine_spidermonkey.cpp @@ -86,10 +86,13 @@ namespace mongo { if( srclen == 0 ) return ""; - size_t len = srclen * 4; + size_t len = srclen * 6; // we only need *3, but see note on len below char * dst = (char*)malloc( len ); - len /= 2; // weird JS_EncodeCharacters api expects len in 16bit units but modifies it to represent size in 8bit units. + len /= 2; + // doc re weird JS_EncodeCharacters api claims len expected in 16bit + // units, but experiments suggest 8bit units expected. We allocate + // enough memory that either will work. assert( JS_EncodeCharacters( _context , s , srclen , dst , &len) ); |