sm encoding checkpoint

This commit is contained in:
Aaron
2009-05-27 14:31:23 -04:00
parent 8d50601341
commit f2920fa2a8
3 changed files with 22 additions and 96 deletions

View File

@@ -3,8 +3,6 @@
#include "stdafx.h"
#include "engine_spidermonkey.h"
#include "../util/encoding.h"
#include "../client/dbclient.h"
namespace mongo {
@@ -75,22 +73,13 @@ namespace mongo {
return new BSONFieldIterator( this );
}
class Convertor : boost::noncopyable {
public:
Convertor( JSContext * cx ){
_context = cx;
}
static void smToMoStr( string &in ) {
if ( !JS_CStringsAreUTF8() )
in = latin1ToUtf8( in );
}
static void moToSmStr( string &in ) {
if ( !JS_CStringsAreUTF8() )
in = utf8ToLatin1( in );
}
string toString( JSString * so ){
jschar * s = JS_GetStringChars( so );
size_t srclen = JS_GetStringLength( so );
@@ -106,7 +95,9 @@ namespace mongo {
string ss( dst , len );
free( dst );
smToMoStr( ss );
if ( !JS_CStringsAreUTF8() )
for( string::const_iterator i = ss.begin(); i != ss.end(); ++i )
uassert( "non ascii character detected", (unsigned char)(*i) <= 127 );
return ss;
}
@@ -262,9 +253,7 @@ namespace mongo {
return true;
}
JSFunction * compileFunction( string code ){
moToSmStr( code );
JSFunction * compileFunction( const char * code ){
if ( ! hasFunctionIdentifier( code ) ){
string s = code;
if ( isSimpleStatement( s ) ){
@@ -303,9 +292,7 @@ namespace mongo {
}
jsval toval( const char * c ){
string str( c );
moToSmStr( str );
JSString * s = JS_NewStringCopyZ( _context , str.c_str() );
JSString * s = JS_NewStringCopyZ( _context , c );
assert( s );
return STRING_TO_JSVAL( s );
}
@@ -321,7 +308,7 @@ namespace mongo {
JSObject * o = toJSObject( obj , readOnly );
return OBJECT_TO_JSVAL( o );
}
jsval toval( const BSONElement& e ){
switch( e.type() ){
@@ -382,9 +369,8 @@ namespace mongo {
}
flags++;
}
string regex( e.regex() );
moToSmStr( regex );
JSObject * r = JS_NewRegExpObject( _context , (char*)regex.c_str() , regex.length() , flagNumber );
JSObject * r = JS_NewRegExpObject( _context , (char*)e.regex() , strlen( e.regex() ) , flagNumber );
assert( r );
return OBJECT_TO_JSVAL( r );
}
@@ -420,9 +406,7 @@ namespace mongo {
JSObject * getJSObject( JSObject * o , const char * name ){
jsval v;
string nameStr( name );
moToSmStr( nameStr );
assert( JS_GetProperty( _context , o , nameStr.c_str() , &v ) );
assert( JS_GetProperty( _context , o , name , &v ) );
return JSVAL_TO_OBJECT( v );
}
@@ -726,8 +710,6 @@ namespace mongo {
assert( JS_DefineFunction( _context , _convertor->getGlobalPrototype( "Object" ) ,
"keySet" , object_keyset , 0 , JSPROP_READONLY ) );
log() << "utf8? " << JS_CStringsAreUTF8() << endl;
_this = 0;
}