diff options
author | Aaron <aaron@10gen.com> | 2010-02-17 11:59:35 -0800 |
---|---|---|
committer | Aaron <aaron@10gen.com> | 2010-02-17 11:59:35 -0800 |
commit | 0ffefe9bc0d01585671e4ddbd4101663aa386fe7 (patch) | |
tree | 631bdffba3486ba42dcfa5d6f3b0308053dd4769 /scripting | |
parent | 154cce03f4d89533558933acd8ee21a167d6d2b5 (diff) | |
download | mongo-0ffefe9bc0d01585671e4ddbd4101663aa386fe7.tar.gz |
SERVER-612 informal dbref for sm
Diffstat (limited to 'scripting')
-rw-r--r-- | scripting/engine_spidermonkey.cpp | 5 | ||||
-rw-r--r-- | scripting/sm_db.cpp | 28 |
2 files changed, 16 insertions, 17 deletions
diff --git a/scripting/engine_spidermonkey.cpp b/scripting/engine_spidermonkey.cpp index 7b7527723bf..294431c6e35 100644 --- a/scripting/engine_spidermonkey.cpp +++ b/scripting/engine_spidermonkey.cpp @@ -453,8 +453,7 @@ namespace mongo { if ( ref == obj->firstElement().fieldName() ){ JSObject * o = JS_NewObject( _context , &dbref_class , NULL, NULL); assert( o ); - setProperty( o , "$ref" , toval( obj->firstElement() ) ); - setProperty( o , "$id" , toval( (*obj)["$id"] ) ); + assert( JS_SetPrivate( _context , o , (void*)(new BSONHolder( obj->getOwned() ) ) ) ); return o; } JSObject * o = JS_NewObject( _context , readOnly ? &bson_ro_class : &bson_class , NULL, NULL); @@ -768,6 +767,8 @@ namespace mongo { JSBool mark_modified( JSContext *cx, JSObject *obj, jsval idval, jsval *vp){ Convertor c(cx); BSONHolder * holder = GETHOLDER( cx , obj ); + if ( !holder ) // needed when we're messing with DBRef.prototype + return JS_TRUE; if ( holder->_inResolve ) return JS_TRUE; holder->_modified = true; diff --git a/scripting/sm_db.cpp b/scripting/sm_db.cpp index d3db026a635..ca4526a3c40 100644 --- a/scripting/sm_db.cpp +++ b/scripting/sm_db.cpp @@ -563,29 +563,24 @@ namespace mongo { JSBool dbref_constructor( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval ){ Convertor c( cx ); - + if ( argc == 2 ){ - assert( JS_SetProperty( cx , obj , "$ref" , &(argv[0]) ) ); - assert( JS_SetProperty( cx , obj , "$id" , &(argv[1]) ) ); + JSObject * o = JS_NewObject( cx , NULL , NULL, NULL ); + assert( o ); + assert( JS_SetProperty( cx, o , "$ref" , &argv[ 0 ] ) ); + assert( JS_SetProperty( cx, o , "$id" , &argv[ 1 ] ) ); + BSONObj bo = c.toObject( o ); + assert( JS_SetPrivate( cx , obj , (void*)(new BSONHolder( bo.getOwned() ) ) ) ); return JS_TRUE; } else { JS_ReportError( cx , "DBRef needs 2 arguments" ); + assert( JS_SetPrivate( cx , obj , (void*)(new BSONHolder( BSONObj().getOwned() ) ) ) ); return JS_FALSE; } } - JSClass dbref_class = { - "DBRef" , JSCLASS_HAS_PRIVATE , - JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, - JS_EnumerateStub, JS_ResolveStub , JS_ConvertStub, JS_FinalizeStub, - JSCLASS_NO_OPTIONAL_MEMBERS - }; - - JSFunctionSpec dbref_functions[] = { - { 0 } - }; - + JSClass dbref_class = bson_class; // name will be fixed later // BinData @@ -817,7 +812,6 @@ namespace mongo { assert( JS_InitClass( cx , global , 0 , &internal_cursor_class , internal_cursor_constructor , 0 , 0 , internal_cursor_functions , 0 , 0 ) ); assert( JS_InitClass( cx , global , 0 , &dbquery_class , dbquery_constructor , 0 , 0 , 0 , 0 , 0 ) ); assert( JS_InitClass( cx , global , 0 , &dbpointer_class , dbpointer_constructor , 0 , 0 , dbpointer_functions , 0 , 0 ) ); - assert( JS_InitClass( cx , global , 0 , &dbref_class , dbref_constructor , 0 , 0 , dbref_functions , 0 , 0 ) ); assert( JS_InitClass( cx , global , 0 , &bindata_class , bindata_constructor , 0 , 0 , bindata_functions , 0 , 0 ) ); assert( JS_InitClass( cx , global , 0 , ×tamp_class , 0 , 0 , 0 , 0 , 0 , 0 ) ); @@ -830,6 +824,10 @@ namespace mongo { assert( JS_InitClass( cx , global , 0 , &bson_ro_class , bson_cons , 0 , 0 , bson_functions , 0 , 0 ) ); assert( JS_InitClass( cx , global , 0 , &bson_class , bson_cons , 0 , 0 , bson_functions , 0 , 0 ) ); + static const char *dbrefName = "DBRef"; + dbref_class.name = dbrefName; + assert( JS_InitClass( cx , global , 0 , &dbref_class , dbref_constructor , 2 , 0 , bson_functions , 0 , 0 ) ); + scope->exec( jsconcatcode ); } |