Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

sm18 checkpoint

  • Loading branch information...
commit 168dcf76327692b7383940ae20932e13101069d4 1 parent 9ff7fa1
@erh erh authored
View
16 jstests/regex.js
@@ -2,23 +2,23 @@ t = db.jstests_regex;
t.drop();
t.save( { a: "bcd" } );
-assert.eq( 1, t.count( { a: /b/ } ) );
-assert.eq( 1, t.count( { a: /bc/ } ) );
-assert.eq( 1, t.count( { a: /bcd/ } ) );
-assert.eq( 0, t.count( { a: /bcde/ } ) );
+assert.eq( 1, t.count( { a: /b/ } ) , "A" );
+assert.eq( 1, t.count( { a: /bc/ } ) , "B" );
+assert.eq( 1, t.count( { a: /bcd/ } ) , "C" );
+assert.eq( 0, t.count( { a: /bcde/ } ) , "D" );
t.drop();
t.save( { a: { b: "cde" } } );
-assert.eq( 1, t.count( { 'a.b': /de/ } ) );
+assert.eq( 1, t.count( { 'a.b': /de/ } ) , "E" );
t.drop();
t.save( { a: { b: [ "cde" ] } } );
-assert.eq( 1, t.count( { 'a.b': /de/ } ) );
+assert.eq( 1, t.count( { 'a.b': /de/ } ) , "F" );
t.drop();
t.save( { a: [ { b: "cde" } ] } );
-assert.eq( 1, t.count( { 'a.b': /de/ } ) );
+assert.eq( 1, t.count( { 'a.b': /de/ } ) , "G" );
t.drop();
t.save( { a: [ { b: [ "cde" ] } ] } );
-assert.eq( 1, t.count( { 'a.b': /de/ } ) );
+assert.eq( 1, t.count( { 'a.b': /de/ } ) , "H" );
View
20 scripting/engine_spidermonkey.cpp
@@ -156,7 +156,7 @@ namespace mongo {
BSONObjBuilder b;
- if ( ! appendSpecialDBObject( this , b , "value" , o ) ){
+ if ( ! appendSpecialDBObject( this , b , "value" , OBJECT_TO_JSVAL( o ) , o ) ){
jsval theid = getProperty( o , "_id" );
if ( ! JSVAL_IS_VOID( theid ) ){
@@ -200,6 +200,13 @@ namespace mongo {
uassert( "not a function" , JS_TypeOfValue( _context , v ) == JSTYPE_FUNCTION );
return getFunctionCode( JS_ValueToFunction( _context , v ) );
}
+
+ void appendRegex( BSONObjBuilder& b , const string& name , string s ){
+ assert( s[0] == '/' );
+ s = s.substr(1);
+ string::size_type end = s.rfind( '/' );
+ b.appendRegex( name.c_str() , s.substr( 0 , end ).c_str() , s.substr( end + 1 ).c_str() );
+ }
void append( BSONObjBuilder& b , string name , jsval val , BSONType oldType = EOO ){
//cout << "name: " << name << "\t" << typeString( val ) << " oldType: " << oldType << endl;
@@ -224,7 +231,7 @@ namespace mongo {
if ( ! o || o == JSVAL_NULL ){
b.appendNull( name.c_str() );
}
- else if ( ! appendSpecialDBObject( this , b , name , o ) ){
+ else if ( ! appendSpecialDBObject( this , b , name , val , o ) ){
BSONObj sub = toObject( o );
if ( JS_IsArrayObject( _context , o ) ){
b.appendArray( name.c_str() , sub );
@@ -239,9 +246,7 @@ namespace mongo {
case JSTYPE_FUNCTION: {
string s = toString(val);
if ( s[0] == '/' ){
- s = s.substr(1);
- string::size_type end = s.rfind( '/' );
- b.appendRegex( name.c_str() , s.substr( 0 , end ).c_str() , s.substr( end + 1 ).c_str() );
+ appendRegex( b , name , s );
}
else {
b.appendCode( name.c_str() , getFunctionCode( val ).c_str() );
@@ -731,8 +736,13 @@ namespace mongo {
public:
SMEngine(){
+#ifdef SM18
+ JS_SetCStringsAreUTF8();
+#endif
+
_runtime = JS_NewRuntime(8L * 1024L * 1024L);
uassert( "JS_NewRuntime failed" , _runtime );
+
if ( ! utf8Ok() ){
cerr << "*** warning: spider monkey build without utf8 support. consider rebuilding with utf8 support" << endl;
}
View
13 scripting/engine_spidermonkey.h
@@ -4,12 +4,15 @@
#include "engine.h"
+// START inc hacking
+
#if defined( MOZJS )
#define MOZILLA_1_8_BRANCH
#include "mozjs/jsapi.h"
#include "mozjs/jsdate.h"
+#include "mozjs/jsregexp.h"
#warning if you are using an ubuntu version of spider monkey, we recommend installing spider monkey from source
@@ -25,14 +28,18 @@
#include "jsapi.h"
#include "jsdate.h"
+#include "jsregexp.h"
#else
#include "js/jsapi.h"
#include "js/jsdate.h"
+#include "js/jsregexp.h"
#endif
+// END inc hacking
+
// -- SM 1.6 hacks ---
#ifndef JSCLASS_GLOBAL_FLAGS
@@ -49,6 +56,10 @@ JSBool JS_CStringsAreUTF8(){
#endif
// -- END SM 1.6 hacks ---
+#ifdef JSVAL_IS_TRACEABLE
+#define SM18
+#endif
+
namespace mongo {
class SMScope;
@@ -75,7 +86,7 @@ namespace mongo {
// mongo
void initMongoJS( SMScope * scope , JSContext * cx , JSObject * global , bool local );
- bool appendSpecialDBObject( Convertor * c , BSONObjBuilder& b , const string& name , JSObject * o );
+ bool appendSpecialDBObject( Convertor * c , BSONObjBuilder& b , const string& name , jsval val , JSObject * o );
#define JSVAL_IS_OID(v) ( JSVAL_IS_OBJECT( v ) && JS_InstanceOf( cx , JSVAL_TO_OBJECT( v ) , &object_id_class , 0 ) )
View
14 scripting/sm_db.cpp
@@ -652,8 +652,8 @@ namespace mongo {
scope->exec( jsconcatcode );
}
- bool appendSpecialDBObject( Convertor * c , BSONObjBuilder& b , const string& name , JSObject * o ){
-
+ bool appendSpecialDBObject( Convertor * c , BSONObjBuilder& b , const string& name , jsval val , JSObject * o ){
+
if ( JS_InstanceOf( c->_context , o , &object_id_class , 0 ) ){
OID oid;
oid.init( c->getString( o , "str" ) );
@@ -709,11 +709,17 @@ namespace mongo {
if ( JS_InstanceOf( c->_context , o , &dbquery_class , 0 ) ||
JS_InstanceOf( c->_context , o , &mongo_class , 0 ) ||
JS_InstanceOf( c->_context , o , &db_collection_class , 0 ) ){
- b.append( name.c_str() , c->toString( OBJECT_TO_JSVAL(o) ) );
+ b.append( name.c_str() , c->toString( val ) );
return true;
}
-
+#ifdef SM18
+ if ( JS_InstanceOf( c->_context , o , &js_RegExpClass , 0 ) ){
+ c->appendRegex( b , name , c->toString( val ) );
+ return true;
+ }
+#endif
+
return false;
}
Please sign in to comment.
Something went wrong with that request. Please try again.